Make api test pass and cleanup

This commit is contained in:
Jan Eitzinger 2022-09-06 14:40:14 +02:00
parent 8fbd1b2cb8
commit 937e72954d
5 changed files with 38 additions and 29 deletions

View File

@ -1,15 +0,0 @@
{
[
"name": "alex",
"metricDataRepository": {
"kind": "cc-metric-store",
"url": "http://localhost:8082",
"token": "eyJhbGciOiJF-E-pQBQ"
},
"filterRanges": {
"numNodes": { "from": 1, "to": 64 },
"duration": { "from": 0, "to": 86400 },
"startTime": { "from": "2022-01-01T00:00:00Z", "to": null }
}
]
}

View File

@ -14,5 +14,20 @@
"archive": { "archive": {
"kind": "file", "kind": "file",
"path": "./var/job-archive" "path": "./var/job-archive"
},
"clusters": [
{
"name": "test",
"metricDataRepository": {
"kind": "cc-metric-store",
"url": "http://localhost:8082",
"token": "eyJhbGciOiJF-E-pQBQ"
},
"filterRanges": {
"numNodes": { "from": 1, "to": 64 },
"duration": { "from": 0, "to": 86400 },
"startTime": { "from": "2022-01-01T00:00:00Z", "to": null }
} }
}
]
} }

View File

@ -76,7 +76,7 @@ type ProgramConfig struct {
StopJobsExceedingWalltime int `json:"stop-jobs-exceeding-walltime"` StopJobsExceedingWalltime int `json:"stop-jobs-exceeding-walltime"`
// Array of Clusters // Array of Clusters
Clusters []*Cluster `json:"Clusters"` Clusters []*Cluster `json:"clusters"`
} }
var Keys ProgramConfig = ProgramConfig{ var Keys ProgramConfig = ProgramConfig{
@ -85,7 +85,7 @@ var Keys ProgramConfig = ProgramConfig{
EmbedStaticFiles: true, EmbedStaticFiles: true,
DBDriver: "sqlite3", DBDriver: "sqlite3",
DB: "./var/job.db", DB: "./var/job.db",
Archive: []byte(`{\"kind\":\"file\",\"path\":\"./var/job-archive\"}`), Archive: json.RawMessage(`{\"kind\":\"file\",\"path\":\"./var/job-archive\"}`),
DisableArchive: false, DisableArchive: false,
LdapConfig: nil, LdapConfig: nil,
SessionMaxAge: "168h", SessionMaxAge: "168h",
@ -113,7 +113,7 @@ var Keys ProgramConfig = ProgramConfig{
func Init(flagConfigFile string) { func Init(flagConfigFile string) {
f, err := os.Open(flagConfigFile) f, err := os.Open(flagConfigFile)
if err != nil { if err != nil {
if !os.IsNotExist(err) || flagConfigFile != "./config.json" { if !os.IsNotExist(err) {
log.Fatal(err) log.Fatal(err)
} }
} else { } else {
@ -123,5 +123,9 @@ func Init(flagConfigFile string) {
log.Fatal(err) log.Fatal(err)
} }
f.Close() f.Close()
if Keys.Clusters == nil || len(Keys.Clusters) < 1 {
log.Fatal("At least one cluster required in config!")
}
} }
} }

View File

@ -20,7 +20,7 @@ import (
) )
type FsArchiveConfig struct { type FsArchiveConfig struct {
Path string `json:"filePath"` Path string `json:"path"`
} }
type FsArchive struct { type FsArchive struct {

View File

@ -28,11 +28,17 @@ import (
func setup(t *testing.T) *api.RestApi { func setup(t *testing.T) *api.RestApi {
const testconfig = `{ const testconfig = `{
"addr": "0.0.0.0:80", "addr": "0.0.0.0:8080",
"archive": { "archive": {
"kind": "file", "kind": "file",
"path": "./var/job-archive" "path": "./var/job-archive"
},
"clusters": [
{
"name": "testcluster",
"metricDataRepository": {"kind": "test"}
} }
]
}` }`
const testclusterJson = `{ const testclusterJson = `{
"name": "testcluster", "name": "testcluster",
@ -109,12 +115,11 @@ func setup(t *testing.T) *api.RestApi {
config.Init(cfgFilePath) config.Init(cfgFilePath)
archiveCfg := fmt.Sprintf("{\"kind\":\"file\",\"path\":\"%s\"}", jobarchive) archiveCfg := fmt.Sprintf("{\"kind\":\"file\",\"path\":\"%s\"}", jobarchive)
config.Keys.Archive = []byte(archiveCfg)
repository.Connect("sqlite3", dbfilepath) repository.Connect("sqlite3", dbfilepath)
db := repository.GetConnection() db := repository.GetConnection()
if err := archive.Init(config.Keys.Archive); err != nil { if err := archive.Init(json.RawMessage(archiveCfg)); err != nil {
t.Fatal(err) t.Fatal(err)
} }