2022-09-12 13:34:21 +02:00
|
|
|
// 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 (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ClusterCockpit/cc-backend/internal/auth"
|
|
|
|
"github.com/ClusterCockpit/cc-backend/internal/config"
|
2023-04-21 12:59:27 +02:00
|
|
|
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
2022-09-12 13:34:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func setupUserTest(t *testing.T) *UserCfgRepo {
|
|
|
|
const testconfig = `{
|
|
|
|
"addr": "0.0.0.0:8080",
|
|
|
|
"archive": {
|
|
|
|
"kind": "file",
|
|
|
|
"path": "./var/job-archive"
|
|
|
|
},
|
|
|
|
"clusters": [
|
|
|
|
{
|
|
|
|
"name": "testcluster",
|
2022-09-20 13:07:46 +02:00
|
|
|
"metricDataRepository": {"kind": "test", "url": "bla:8081"},
|
|
|
|
"filterRanges": {
|
|
|
|
"numNodes": { "from": 1, "to": 64 },
|
|
|
|
"duration": { "from": 0, "to": 86400 },
|
|
|
|
"startTime": { "from": "2022-01-01T00:00:00Z", "to": null }
|
|
|
|
} } ]
|
2022-09-12 13:34:21 +02:00
|
|
|
}`
|
2023-04-21 12:59:27 +02:00
|
|
|
|
|
|
|
log.Init("info", true)
|
2023-05-05 06:02:17 +02:00
|
|
|
dbfilepath := "testdata/test.db"
|
2023-04-21 12:59:27 +02:00
|
|
|
err := MigrateDB("sqlite3", dbfilepath)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
Connect("sqlite3", dbfilepath)
|
|
|
|
|
2022-09-12 13:34:21 +02:00
|
|
|
tmpdir := t.TempDir()
|
|
|
|
cfgFilePath := filepath.Join(tmpdir, "config.json")
|
|
|
|
if err := os.WriteFile(cfgFilePath, []byte(testconfig), 0666); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Init(cfgFilePath)
|
|
|
|
return GetUserCfgRepo()
|
|
|
|
}
|
2023-04-21 12:59:27 +02:00
|
|
|
|
2022-09-12 13:34:21 +02:00
|
|
|
func TestGetUIConfig(t *testing.T) {
|
|
|
|
r := setupUserTest(t)
|
2023-04-21 12:59:27 +02:00
|
|
|
u := auth.User{Username: "demo"}
|
2022-09-12 13:34:21 +02:00
|
|
|
|
|
|
|
cfg, err := r.GetUIConfig(&u)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("No config")
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp := cfg["plot_list_selectedMetrics"]
|
2023-04-21 12:59:27 +02:00
|
|
|
metrics := tmp.([]string)
|
|
|
|
str := metrics[2]
|
|
|
|
if str != "mem_used" {
|
2022-09-12 13:34:21 +02:00
|
|
|
t.Errorf("wrong config\ngot: %s \nwant: mem_bw", str)
|
|
|
|
}
|
|
|
|
}
|