2024-04-11 23:04:30 +02:00
|
|
|
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
2022-07-29 06:29:21 +02:00
|
|
|
// All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
2022-02-10 18:48:58 +01:00
|
|
|
package repository
|
|
|
|
|
|
|
|
import (
|
2024-08-05 10:19:00 +02:00
|
|
|
"context"
|
2022-02-10 18:48:58 +01:00
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2024-08-05 10:19:00 +02:00
|
|
|
"github.com/ClusterCockpit/cc-backend/pkg/schema"
|
2022-03-15 08:29:29 +01:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
2022-02-10 18:48:58 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFind(t *testing.T) {
|
|
|
|
r := setup(t)
|
|
|
|
|
2023-04-21 12:59:27 +02:00
|
|
|
jobId, cluster, startTime := int64(398998), "fritz", int64(1675957496)
|
2022-02-16 09:01:32 +01:00
|
|
|
job, err := r.Find(&jobId, &cluster, &startTime)
|
2022-02-10 18:48:58 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// fmt.Printf("%+v", job)
|
|
|
|
|
2023-04-21 12:59:27 +02:00
|
|
|
if job.ID != 5 {
|
2022-02-11 11:04:26 +01:00
|
|
|
t.Errorf("wrong summary for diagnostic 3\ngot: %d \nwant: 1366", job.JobID)
|
2022-02-10 18:48:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFindById(t *testing.T) {
|
|
|
|
r := setup(t)
|
|
|
|
|
2024-07-03 17:24:26 +02:00
|
|
|
job, err := r.FindById(getContext(t), 5)
|
2022-02-10 18:48:58 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// fmt.Printf("%+v", job)
|
|
|
|
|
2023-04-21 12:59:27 +02:00
|
|
|
if job.JobID != 398998 {
|
2022-02-11 11:04:26 +01:00
|
|
|
t.Errorf("wrong summary for diagnostic 3\ngot: %d \nwant: 1404396", job.JobID)
|
2022-02-10 18:48:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetTags(t *testing.T) {
|
|
|
|
r := setup(t)
|
|
|
|
|
2024-08-05 10:19:00 +02:00
|
|
|
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(ctx)
|
2022-02-10 18:48:58 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("TAGS %+v \n", tags)
|
|
|
|
// fmt.Printf("COUNTS %+v \n", counts)
|
|
|
|
|
2023-06-05 16:10:47 +02:00
|
|
|
if counts["bandwidth"] != 0 {
|
|
|
|
t.Errorf("wrong tag count \ngot: %d \nwant: 0", counts["bandwidth"])
|
2022-02-11 11:04:26 +01:00
|
|
|
}
|
2022-02-10 18:48:58 +01:00
|
|
|
}
|