forked from marcinwyszynski/ssmvars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment_test.go
53 lines (41 loc) · 1.17 KB
/
environment_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
package ssmvars
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
type mockReader struct {
mock.Mock
Reader
}
func (m *mockReader) ListVariables(ctx context.Context, namespace string) ([]*Variable, error) {
args := m.Called(ctx, namespace)
return args.Get(0).([]*Variable), args.Error(1)
}
func TestEnvironmentOK(t *testing.T) {
const namespace = "namespace"
reader := new(mockReader)
ctx := context.Background()
reader.On("ListVariables", ctx, namespace).Return([]*Variable{
{Name: "FIRST", Value: "first"},
{Name: "LAST", Value: "last"},
}, nil)
environment, err := Environment(ctx, reader, namespace)
assert.NoError(t, err)
assert.Len(t, environment, 2)
assert.Contains(t, environment, "FIRST=first")
assert.Contains(t, environment, "LAST=last")
}
func TestEnvironmentError(t *testing.T) {
const namespace = "namespace"
reader := new(mockReader)
ctx := context.Background()
reader.
On("ListVariables", ctx, namespace).
Return(([]*Variable)(nil), errors.New("bacon"))
environment, err := Environment(ctx, reader, namespace)
assert.EqualError(t, err, "bacon")
assert.Nil(t, environment)
}