summaryrefslogtreecommitdiff
path: root/service/env/service_test.go
blob: 28e0d15beb5e00662025107375347580a49b3b5c (plain)
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
package env

import (
	"github.com/stretchr/testify/assert"
	"testing"
)

func Test_NewService(t *testing.T) {
	s := NewService(map[string]string{"version": "test"})
	assert.Len(t, s.values, 1)
}

func Test_Init(t *testing.T) {
	s := &Service{}
	s.Init(&Config{})
	assert.Len(t, s.values, 1)

	values, err := s.GetEnv()
	assert.NoError(t, err)
	assert.Equal(t, "yes", values["rr"])
}

func Test_Extend(t *testing.T) {
	s := NewService(map[string]string{"rr": "version"})

	s.Init(&Config{Values: map[string]string{"key": "value"}})
	assert.Len(t, s.values, 2)

	values, err := s.GetEnv()
	assert.NoError(t, err)
	assert.Len(t, values, 2)
	assert.Equal(t, "version", values["rr"])
	assert.Equal(t, "value", values["key"])
}

func Test_Set(t *testing.T) {
	s := NewService(map[string]string{"rr": "version"})

	s.Init(&Config{Values: map[string]string{"key": "value"}})
	assert.Len(t, s.values, 2)

	s.SetEnv("key", "value-new")
	s.SetEnv("other", "new")

	values, err := s.GetEnv()
	assert.NoError(t, err)
	assert.Len(t, values, 3)
	assert.Equal(t, "version", values["rr"])
	assert.Equal(t, "value-new", values["key"])
	assert.Equal(t, "new", values["other"])
}