-
Notifications
You must be signed in to change notification settings - Fork 21
/
data_test.go
70 lines (56 loc) · 1.72 KB
/
data_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
package main
import (
"fmt"
"sort"
"testing"
)
func AssertEqual(t *testing.T, value []string, expect []string) {
if len(value) != len(expect) {
t.Error("Slices are not the same length", len(value), len(expect))
}
sort.Strings(value)
sort.Strings(expect)
for i, _ := range value {
if value[i] != expect[i] {
t.Error(fmt.Sprintf("Values at offset %v do not match", i), value[i], expect[i])
}
}
}
func TestBuildEnvVarsUpcaseFalse(t *testing.T) {
var params map[string]string
params = make(map[string]string)
params["baz"] = "qux"
params["FOO"] = "bar"
expectation := []string{"baz=qux", "FOO=bar"}
envvars := BuildEnvVars(params, false, false, false)
AssertEqual(t, envvars, expectation)
}
func TestBuildEnvVarsUpcaseTrue(t *testing.T) {
var params map[string]string
params = make(map[string]string)
params["baz"] = "qux"
params["FOO"] = "bar"
expectation := []string{"BAZ=qux", "FOO=bar"}
envVars := BuildEnvVars(params, false, false, true)
AssertEqual(t, envVars, expectation)
}
func TestBuildEnvVarsUpperSanitize(t *testing.T) {
var params map[string]string
params = make(map[string]string)
params["FOO"] = "bar"
params["baz-corgie"] = "qux"
params["wE_irD-kEY!"] = "zaphod"
expectation := []string{"BAZ_CORGIE=qux", "FOO=bar", "WE_IRD_KEY_=zaphod"}
envVars := BuildEnvVars(params, true, false, true)
AssertEqual(t, envVars, expectation)
}
func TestBuildEnvVarsUpperStrip(t *testing.T) {
var params map[string]string
params = make(map[string]string)
params["FOO"] = "bar"
params["baz-corgie"] = "qux"
params["wE_irD-kEY!"] = "zaphod"
expectation := []string{"BAZCORGIE=qux", "FOO=bar", "WE_IRDKEY=zaphod"}
envVars := BuildEnvVars(params, false, true, true)
AssertEqual(t, envVars, expectation)
}