2022-02-10 18:48:58 +01:00
|
|
|
package repository
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
|
2022-02-11 11:04:26 +01:00
|
|
|
"github.com/ClusterCockpit/cc-backend/test"
|
2022-02-10 18:48:58 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var db *sqlx.DB
|
|
|
|
|
|
|
|
func init() {
|
2022-02-11 11:04:26 +01:00
|
|
|
db = test.InitDB()
|
2022-02-10 18:48:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func setup(t *testing.T) *JobRepository {
|
2022-02-19 10:28:29 +01:00
|
|
|
r := &JobRepository{
|
2022-02-10 18:48:58 +01:00
|
|
|
DB: db,
|
|
|
|
}
|
2022-02-19 10:28:29 +01:00
|
|
|
if err := r.Init(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return r
|
2022-02-10 18:48:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFind(t *testing.T) {
|
|
|
|
r := setup(t)
|
|
|
|
|
2022-02-16 09:01:32 +01:00
|
|
|
jobId, cluster, startTime := int64(1404396), "emmy", int64(1609299584)
|
|
|
|
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)
|
|
|
|
|
2022-02-11 11:04:26 +01:00
|
|
|
if job.ID != 1366 {
|
|
|
|
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)
|
|
|
|
|
2022-02-11 11:04:26 +01:00
|
|
|
job, err := r.FindById(1366)
|
2022-02-10 18:48:58 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// fmt.Printf("%+v", job)
|
|
|
|
|
2022-02-11 11:04:26 +01:00
|
|
|
if job.JobID != 1404396 {
|
|
|
|
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)
|
|
|
|
|
2022-02-17 09:04:57 +01:00
|
|
|
tags, counts, err := r.CountTags(nil)
|
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)
|
|
|
|
|
2022-02-11 11:04:26 +01:00
|
|
|
if counts["bandwidth"] != 6 {
|
|
|
|
t.Errorf("wrong summary for diagnostic 3\ngot: %d \nwant: 6", counts["load-imbalance"])
|
|
|
|
}
|
2022-02-10 18:48:58 +01:00
|
|
|
}
|