-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathutils_test.go
64 lines (50 loc) · 1.46 KB
/
utils_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
package testing
import (
"testing"
"github.com/daidokoro/qaz/utils"
"github.com/stretchr/testify/assert"
)
func TestConfigTemplate(t *testing.T) {
expected := []byte(`
# AWS Region
region: eu-west-1
# Project Name
project: test-project
# Global Stack Variables
global:
# Stacks
stacks:
`)
b := utils.ConfigTemplate("test-project", "eu-west-1")
assert.Equal(t, expected, b)
}
func TestAllinSlice(t *testing.T) {
slice := []string{"a", "a", "a"}
assert.Equal(t, true, utils.All(slice, "a"))
assert.Equal(t, false, utils.All(slice, "b"))
}
func TestStringIn(t *testing.T) {
slice := []string{"a", "b", "c"}
assert.Equal(t, true, utils.StringIn("a", slice))
assert.Equal(t, false, utils.StringIn("q", slice))
}
func TestGet(t *testing.T) {
expected := "Description: This is an example VPC deployed via Qaz!\n\nResources:\n VPC:\n Type: AWS::EC2::VPC\n Properties:\n CidrBlock: {{ .vpc.cidr }}\n"
v, err := utils.Get("https://raw.githubusercontent.com/cfn-deployable/simplevpc/master/vpc.yaml")
assert.NoError(t, err)
assert.Equal(t, expected, v)
}
func TestGetSource(t *testing.T) {
x, y, err := utils.GetSource("Stackname::http://someurl")
assert.NoError(t, err)
assert.Equal(t, x, "Stackname")
assert.Equal(t, y, "http://someurl")
}
func TestIsJSON(t *testing.T) {
j := `{"name": "some json"}`
assert.Equal(t, true, utils.IsJSON(j))
}
func TestIsHCL(t *testing.T) {
h := `service { name = "some hcl" }`
assert.Equal(t, true, utils.IsHCL(h))
}