-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils_test.go
58 lines (43 loc) · 1.4 KB
/
utils_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
50
51
52
53
54
55
56
57
58
package main
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
type mockClient struct {
mock.Mock
}
func (m *mockClient) Load(path string) (Dict, error) {
args := m.Called(path)
return map[string]string{args.String(0): args.String(1)}, args.Error(2) //nolint:wrapcheck
}
func TestLoadValues(t *testing.T) {
logger, log := testLogger()
m := new(mockClient)
m.On("Load", "foo").Return("foo", "bar", nil)
m.On("Load", "bar").Return("bar", "baz", nil)
d, err := loadValues(context.TODO(), m, logger, []string{"foo", "bar"})
require.NoError(t, err)
assert.Equal(t, Dict{
"foo": "bar",
"bar": "baz",
}, d)
assert.Equal(t, []byte(`{"time":"test-time","level":"DEBUG","msg":"Loading values","path":"foo"}
{"time":"test-time","level":"DEBUG","msg":"Loading values","path":"bar"}
`), log.Bytes())
m.AssertExpectations(t)
}
func TestLoadValues_Error(t *testing.T) {
logger, log := testLogger()
m := new(mockClient)
m.On("Load", "none").Return("", "", errors.New("test error")) //nolint:goerr113
d, err := loadValues(context.TODO(), m, logger, []string{"none"})
require.ErrorContains(t, err, "Could not load values: test error")
assert.Equal(t, Dict{}, d)
assert.Equal(t, []byte(`{"time":"test-time","level":"DEBUG","msg":"Loading values","path":"none"}
`), log.Bytes())
m.AssertExpectations(t)
}