-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenvexpand_test.go
88 lines (66 loc) · 2.12 KB
/
envexpand_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
85
86
87
88
package envexpand
import (
"bytes"
"os"
"testing"
)
func TestExpands(t *testing.T) {
os.Setenv("ENVEXPAND_DOMAIN", "google.com")
defer os.Unsetenv("ENVEXPAND_DOMAIN")
input := []byte("http://${ENVEXPAND_DOMAIN}")
expected := []byte("http://google.com")
output := Expand(input)
if !bytes.Equal(output, expected) {
t.Errorf("output does not match expected", input, output, expected)
}
}
func TestExpandsString(t *testing.T) {
os.Setenv("ENVEXPAND_DOMAIN", "google.com")
defer os.Unsetenv("ENVEXPAND_DOMAIN")
input := "http://${ENVEXPAND_DOMAIN}"
expected := "http://google.com"
output := ExpandString(input)
if output != expected {
t.Errorf("output does not match expected", input, output, expected)
}
}
func TestDoesNotExpandIfNotFound(t *testing.T) {
input := []byte("http://${ENVEXPAND_DOMAIN}")
expected := []byte("http://${ENVEXPAND_DOMAIN}")
output := Expand(input)
if !bytes.Equal(output, expected) {
t.Errorf("output does not match expected", input, output, expected)
}
}
func TestDoesNotExpandIfNotFoundString(t *testing.T) {
input := "http://${ENVEXPAND_DOMAIN}"
expected := "http://${ENVEXPAND_DOMAIN}"
output := ExpandString(input)
if output != expected {
t.Errorf("output does not match expected", input, output, expected)
}
}
func TestExpandsMultiple(t *testing.T) {
os.Setenv("ENVEXPAND_DOMAIN", "google.com")
defer os.Unsetenv("ENVEXPAND_DOMAIN")
os.Setenv("ENVEXPAND_PORT", "8080")
defer os.Unsetenv("ENVEXPAND_PORT")
input := []byte("http://${ENVEXPAND_DOMAIN}:${ENVEXPAND_PORT}")
expected := []byte("http://google.com:8080")
output := Expand(input)
if !bytes.Equal(output, expected) {
t.Errorf("output does not match expected", input, output, expected)
}
}
func TestExpandsMultipleString(t *testing.T) {
os.Setenv("ENVEXPAND_DOMAIN", "google.com")
defer os.Unsetenv("ENVEXPAND_DOMAIN")
os.Setenv("ENVEXPAND_PORT", "8080")
defer os.Unsetenv("ENVEXPAND_PORT")
input := "http://${ENVEXPAND_DOMAIN}:${ENVEXPAND_PORT}"
expected := "http://google.com:8080"
output := ExpandString(input)
if output != expected {
t.Errorf("output does not match expected", input, output, expected)
}
}