-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
49 lines (40 loc) · 1023 Bytes
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2024 Mikhail Knyazhev <[email protected]>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/
package config_test
import (
"os"
"testing"
"go.osspkg.com/casecheck"
"go.osspkg.com/config"
"go.osspkg.com/config/env"
)
func TestUnit_ConfigResolve(t *testing.T) {
type (
TestConfigItem struct {
Home string `yaml:"home"`
Path string `yaml:"path"`
}
TestConfig struct {
Envs TestConfigItem `yaml:"envs"`
}
)
filename := "/tmp/TestUnit_ConfigResolve.yaml"
data := `
envs:
home: "@env(HOME#fail)"
path: "@env(PATH#fail)"
`
err := os.WriteFile(filename, []byte(data), 0755)
casecheck.NoError(t, err)
res := config.New(env.New())
err = res.OpenFile(filename)
casecheck.NoError(t, err)
err = res.Build()
casecheck.NoError(t, err)
var tc TestConfig
casecheck.NoError(t, res.Decode(&tc))
casecheck.NotEqual(t, "fail", tc.Envs.Home)
casecheck.NotEqual(t, "fail", tc.Envs.Path)
}