mirror of
				https://github.com/ClusterCockpit/cc-backend
				synced 2025-10-31 07:55:06 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			74 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
 | |
| // All rights reserved. This file is part of cc-backend.
 | |
| // Use of this source code is governed by a MIT-style
 | |
| // license that can be found in the LICENSE file.
 | |
| package repository
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"fmt"
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/ClusterCockpit/cc-lib/schema"
 | |
| 	_ "github.com/mattn/go-sqlite3"
 | |
| )
 | |
| 
 | |
| func TestFind(t *testing.T) {
 | |
| 	r := setup(t)
 | |
| 
 | |
| 	jobID, cluster, startTime := int64(398800), "fritz", int64(1675954712)
 | |
| 	job, err := r.Find(&jobID, &cluster, &startTime)
 | |
| 	if err != nil {
 | |
| 		t.Fatal(err)
 | |
| 	}
 | |
| 
 | |
| 	// fmt.Printf("%+v", job)
 | |
| 
 | |
| 	if *job.ID != 345 {
 | |
| 		t.Errorf("wrong summary for diagnostic \ngot: %d \nwant: 345", job.JobID)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestFindById(t *testing.T) {
 | |
| 	r := setup(t)
 | |
| 
 | |
| 	job, err := r.FindById(getContext(t), 338)
 | |
| 	if err != nil {
 | |
| 		t.Fatal(err)
 | |
| 	}
 | |
| 
 | |
| 	// fmt.Printf("%+v", job)
 | |
| 
 | |
| 	if job.JobID != 398793 {
 | |
| 		t.Errorf("wrong summary for diagnostic \ngot: %d \nwant: 1404396", job.JobID)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestGetTags(t *testing.T) {
 | |
| 	r := setup(t)
 | |
| 
 | |
| 	const contextUserKey ContextKey = "user"
 | |
| 	contextUserValue := &schema.User{
 | |
| 		Username:   "testuser",
 | |
| 		Projects:   make([]string, 0),
 | |
| 		Roles:      []string{"user"},
 | |
| 		AuthType:   0,
 | |
| 		AuthSource: 2,
 | |
| 	}
 | |
| 
 | |
| 	ctx := context.WithValue(getContext(t), contextUserKey, contextUserValue)
 | |
| 
 | |
| 	// Test Tag has Scope "global"
 | |
| 	tags, counts, err := r.CountTags(GetUserFromContext(ctx))
 | |
| 	if err != nil {
 | |
| 		t.Fatal(err)
 | |
| 	}
 | |
| 
 | |
| 	fmt.Printf("TAGS %+v \n", tags)
 | |
| 	// fmt.Printf("COUNTS %+v \n", counts)
 | |
| 
 | |
| 	if counts["bandwidth"] != 0 {
 | |
| 		t.Errorf("wrong tag count \ngot: %d \nwant: 0", counts["bandwidth"])
 | |
| 	}
 | |
| }
 |