mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-15 03:11:02 +01:00
820e2feec9
Add test for mgm config parser
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
const (
|
|
exampleConfig = `{
|
|
"RelayConfig": {
|
|
"Address": "rels://relay.stage.npeer.io"
|
|
},
|
|
"HttpConfig": {
|
|
"AuthAudience": "https://stageapp/",
|
|
"AuthIssuer": "https://something.eu.auth0.com/",
|
|
"OIDCConfigEndpoint": "https://something.eu.auth0.com/.well-known/openid-configuration"
|
|
}
|
|
}`
|
|
)
|
|
|
|
func Test_loadMgmtConfig(t *testing.T) {
|
|
tmpFile, err := createConfig()
|
|
if err != nil {
|
|
t.Fatalf("failed to create config: %s", err)
|
|
}
|
|
|
|
cfg, err := loadMgmtConfig(context.Background(), tmpFile)
|
|
if err != nil {
|
|
t.Fatalf("failed to load management config: %s", err)
|
|
}
|
|
if cfg.RelayConfig == nil {
|
|
t.Fatalf("config is nil")
|
|
}
|
|
if cfg.RelayConfig.Address == "" {
|
|
t.Fatalf("relay address is empty")
|
|
}
|
|
}
|
|
|
|
func createConfig() (string, error) {
|
|
tmpfile, err := os.CreateTemp("", "config.json")
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
_, err = tmpfile.Write([]byte(exampleConfig))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if err := tmpfile.Close(); err != nil {
|
|
return "", err
|
|
}
|
|
return tmpfile.Name(), nil
|
|
}
|