-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.go
More file actions
52 lines (41 loc) · 1.05 KB
/
config_test.go
File metadata and controls
52 lines (41 loc) · 1.05 KB
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
50
51
52
/*
* Copyright (c) 2024-2025 Mikhail Knyazhev <markus621@yandex.com>. 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"`
Tmp string `yaml:"tempenv"`
}
TestConfig struct {
Envs TestConfigItem `yaml:"envs"`
}
)
data := `
envs:
home: "@env(HOME#fail)"
path: "@env(PATH#fail)"
`
casecheck.NoError(t, os.Setenv("tempenv", "123"))
res := config.New(env.New())
res.OpenBlob(data, ".yaml")
casecheck.NoError(t, res.Build())
var tc TestConfig
casecheck.NoError(t, res.Decode(&tc))
casecheck.NotEqual(t, "fail", tc.Envs.Home)
casecheck.NotEqual(t, "fail", tc.Envs.Path)
casecheck.NotEqual(t, "123", tc.Envs.Tmp)
res.Flush()
casecheck.Error(t, res.Build())
casecheck.Error(t, res.Decode(&tc))
}