-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig_test.go
84 lines (71 loc) · 2.33 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package timestream
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestNewConfig(t *testing.T) {
t.Parallel()
config := NewConfig()
t.Run("The Region is empty", func(t *testing.T) {
t.Parallel()
require.Equal(t, "", config.Region)
})
t.Run("The DatabaseName is empty", func(t *testing.T) {
t.Parallel()
require.Equal(t, "", config.DatabaseName)
})
t.Run("The TableName is empty", func(t *testing.T) {
t.Parallel()
require.Equal(t, "", config.TableName)
})
}
func TestGetConsolidatedConfig(t *testing.T) {
os.Clearenv()
t.Run("Defaults applied correctly", func(t *testing.T) {
t.Parallel()
config, err := GetConsolidatedConfig([]byte("{}"), map[string]string{})
require.NoError(t, err)
require.Equal(t, "", config.Region)
require.Equal(t, "", config.DatabaseName)
require.Equal(t, "", config.TableName)
})
testJSON := []byte(
`{"region": "us-east-1", "databaseName": "testDbJson", "tableName": "testTableJson", "pushInterval": "30s"}`,
)
t.Run("JSON is applied correctly", func(t *testing.T) {
t.Parallel()
config, err := GetConsolidatedConfig(testJSON, map[string]string{})
require.NoError(t, err)
require.Equal(t, "us-east-1", config.Region)
require.Equal(t, "testDbJson", config.DatabaseName)
require.Equal(t, "testTableJson", config.TableName)
})
t.Run("Env variables applied correctly", func(t *testing.T) {
config, err := GetConsolidatedConfig([]byte("{}"), map[string]string{
"K6_TIMESTREAM_REGION": "eu-west-1",
"K6_TIMESTREAM_DATABASE_NAME": "testDbEnv",
"K6_TIMESTREAM_TABLE_NAME": "testTableEnv",
"K6_TIMESTREAM_PUSH_INTERVAL": "1h",
})
require.NoError(t, err)
require.Equal(t, "eu-west-1", config.Region)
require.Equal(t, "testDbEnv", config.DatabaseName)
require.Equal(t, "testTableEnv", config.TableName)
})
t.Run(
"Env variables applied correctly over json variables",
func(t *testing.T) {
config, err := GetConsolidatedConfig(testJSON, map[string]string{
"K6_TIMESTREAM_REGION": "eu-west-1",
"K6_TIMESTREAM_DATABASE_NAME": "testDbEnv",
"K6_TIMESTREAM_TABLE_NAME": "testTableEnv",
"K6_TIMESTREAM_PUSH_INTERVAL": "1h",
})
require.NoError(t, err)
require.Equal(t, "eu-west-1", config.Region)
require.Equal(t, "testDbEnv", config.DatabaseName)
require.Equal(t, "testTableEnv", config.TableName)
},
)
}