cc-backend/internal/repository/job_test.go

72 lines
1.4 KiB
Go
Raw Normal View History

// Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
// All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package repository
import (
"fmt"
"testing"
2023-02-15 13:07:19 +01:00
"github.com/ClusterCockpit/cc-backend/pkg/log"
2022-03-15 08:29:29 +01:00
_ "github.com/mattn/go-sqlite3"
)
func setup(t *testing.T) *JobRepository {
log.Init("info", true)
2023-05-05 06:02:17 +02:00
dbfilepath := "testdata/test.db"
err := MigrateDB("sqlite3", dbfilepath)
if err != nil {
t.Fatal(err)
}
Connect("sqlite3", dbfilepath)
return GetJobRepository()
}
func TestFind(t *testing.T) {
r := setup(t)
jobId, cluster, startTime := int64(398998), "fritz", int64(1675957496)
2022-02-16 09:01:32 +01:00
job, err := r.Find(&jobId, &cluster, &startTime)
if err != nil {
t.Fatal(err)
}
// fmt.Printf("%+v", job)
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)
}
}
func TestFindById(t *testing.T) {
r := setup(t)
job, err := r.FindById(5)
if err != nil {
t.Fatal(err)
}
// fmt.Printf("%+v", job)
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)
}
}
func TestGetTags(t *testing.T) {
r := setup(t)
2022-02-17 09:04:57 +01:00
tags, counts, err := r.CountTags(nil)
if err != nil {
t.Fatal(err)
}
fmt.Printf("TAGS %+v \n", tags)
// fmt.Printf("COUNTS %+v \n", counts)
if counts["bandwidth"] != 3 {
t.Errorf("wrong tag count \ngot: %d \nwant: 3", counts["bandwidth"])
2022-02-11 11:04:26 +01:00
}
}