mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-25 21:09:05 +01:00
Adapt testing
This commit is contained in:
parent
f2ae0daec2
commit
abcfc48802
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
@ -14,4 +14,5 @@ jobs:
|
||||
run: |
|
||||
go build ./...
|
||||
go vet ./...
|
||||
go test -v ./...
|
||||
go test .
|
||||
env BASEPATH="../" go test ./repository
|
||||
|
@ -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"])
|
||||
}
|
||||
}
|
||||
|
25
test/db.go
Normal file
25
test/db.go
Normal file
@ -0,0 +1,25 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
func InitDB() *sqlx.DB {
|
||||
|
||||
bp := "./"
|
||||
ebp := os.Getenv("BASEPATH")
|
||||
|
||||
if ebp != "" {
|
||||
bp = ebp + "test/"
|
||||
}
|
||||
|
||||
db, err := sqlx.Open("sqlite3", bp+"test.db")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
return db
|
||||
}
|
BIN
test/test.db
Normal file
BIN
test/test.db
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user