mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-23 12:51:40 +02:00
Adapt testing
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/test"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
@@ -13,15 +14,7 @@ import (
|
||||
var db *sqlx.DB
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
|
||||
if db != nil {
|
||||
panic("prefer using sub-tests (`t.Run`) or implement `cleanup` before calling setup twice.")
|
||||
}
|
||||
db, err = sqlx.Open("sqlite3", "../var/test.db")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
db = test.InitDB()
|
||||
}
|
||||
|
||||
func setup(t *testing.T) *JobRepository {
|
||||
@@ -33,46 +26,45 @@ func setup(t *testing.T) *JobRepository {
|
||||
func TestFind(t *testing.T) {
|
||||
r := setup(t)
|
||||
|
||||
job, err := r.Find(1001789, "emmy", 1540853248)
|
||||
job, err := r.Find(1404396, "emmy", 1609299584)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// fmt.Printf("%+v", job)
|
||||
|
||||
if job.ID != 1245 {
|
||||
t.Errorf("wrong summary for diagnostic 3\ngot: %d \nwant: 1245", job.JobID)
|
||||
if job.ID != 1366 {
|
||||
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(1245)
|
||||
job, err := r.FindById(1366)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// fmt.Printf("%+v", job)
|
||||
|
||||
if job.JobID != 1001789 {
|
||||
t.Errorf("wrong summary for diagnostic 3\ngot: %d \nwant: 1001789", job.JobID)
|
||||
if job.JobID != 1404396 {
|
||||
t.Errorf("wrong summary for diagnostic 3\ngot: %d \nwant: 1404396", job.JobID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTags(t *testing.T) {
|
||||
r := setup(t)
|
||||
|
||||
tags, _, err := r.GetTags()
|
||||
tags, counts, err := r.GetTags()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("TAGS %+v \n", tags)
|
||||
// fmt.Printf("COUNTS %+v \n", counts)
|
||||
t.Errorf("wrong summary for diagnostic 3\ngot: %d \nwant: 23", 28)
|
||||
|
||||
// if counts["load-imbalance"] != 23 {
|
||||
// t.Errorf("wrong summary for diagnostic 3\ngot: %d \nwant: 23", counts["load-imbalance"])
|
||||
// }
|
||||
if counts["bandwidth"] != 6 {
|
||||
t.Errorf("wrong summary for diagnostic 3\ngot: %d \nwant: 6", counts["load-imbalance"])
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user