stillbox/pkg/config/parse_test.go

81 lines
1.5 KiB
Go
Raw Normal View History

2024-11-24 08:40:14 -05:00
package config
import (
"testing"
"time"
"dynatron.me/x/stillbox/internal/common"
"dynatron.me/x/stillbox/internal/jsontypes"
"github.com/stretchr/testify/assert"
2024-11-24 09:10:31 -05:00
"github.com/stretchr/testify/require"
2024-11-24 08:40:14 -05:00
)
var expCfg = &Config{
DB: DB{
2024-11-24 09:10:31 -05:00
Connect: "postgres://stillbox:somepassword@stillbox:5432/stillbox?sslmode=disable",
2024-11-24 08:40:14 -05:00
LogQueries: true,
},
CORS: CORS{
AllowedOrigins: []string{
"http://localhost:*",
2024-11-24 09:10:31 -05:00
},
2024-11-24 08:40:14 -05:00
},
Auth: Auth{
JWTSecret: "somesecret",
2024-11-24 09:10:31 -05:00
Domain: "xenon",
2024-11-24 08:40:14 -05:00
AllowInsecure: map[string]bool{
"localhost": true,
2024-11-24 09:10:31 -05:00
"stillbox": true,
2024-11-24 08:40:14 -05:00
},
},
Alerting: Alerting{
2024-11-24 09:10:31 -05:00
Enable: true,
LookbackDays: 7,
HalfLife: jsontypes.Duration(30 * time.Minute),
Recent: jsontypes.Duration(2 * time.Hour),
2024-11-24 08:40:14 -05:00
AlertThreshold: 0.3,
2024-11-24 09:10:31 -05:00
Renotify: common.PtrTo(jsontypes.Duration(30 * time.Minute)),
2024-11-24 08:40:14 -05:00
},
Log: []Logger{
Logger{
Level: common.PtrTo("debug"),
},
Logger{
Level: common.PtrTo("error"),
2024-11-24 09:10:31 -05:00
File: common.PtrTo("error.log"),
2024-11-24 08:40:14 -05:00
},
},
Listen: ":3051",
Public: true,
RateLimit: RateLimit{
2024-11-24 09:10:31 -05:00
Enable: true,
2024-11-24 08:40:14 -05:00
Requests: 200,
2024-11-24 09:10:31 -05:00
Over: 2 * time.Minute,
2024-11-24 08:40:14 -05:00
},
Notify: Notify{
NotifyService{
Provider: "slackwebhook",
Config: map[string]interface{}{
"webhookURL": "https://hook",
},
},
},
Relay: []Relay{
Relay{
2024-11-24 09:10:31 -05:00
URL: "http://relay",
APIKey: "secret",
2024-11-24 08:40:14 -05:00
Required: true,
},
},
}
func TestConfigParse(t *testing.T) {
c := &Configuration{configPath: "testdata/testconfig.yaml"}
err := c.read()
require.NoError(t, err)
assert.Equal(t, expCfg, &c.Config)
}