-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_test.go
73 lines (67 loc) · 1.94 KB
/
merge_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
// file: main_test.go
package main
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMergeYAML_InvertedMergeOrder(t *testing.T) {
result, err := MergeYAML("tests/test2.yaml", "tests/test1.yaml")
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(`
modules:
my_module:
providerAliasRef: my_provider2
source: github.com/example/module
version: v1.0.0
my_module2:
providerAliasRef: my_provider2
source: github.com/example/module
version: v1.6.0
my_module3:
providerAliasRef: my_provider2
source: github.com/example/module
version: v1.6.0
providers:
my_provider:
auth:
ssh_key: ssh:key:2312312
providerType: github
`), strings.TrimSpace(string(result)))
}
func TestMergeYAML_TwoFiles(t *testing.T) {
result, err := MergeYAML("tests/test1.yaml", "tests/test2.yaml")
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(`
modules:
my_module:
providerAliasRef: my_provider2
source: github.com/example/module
version: v1.6.0
my_module2:
providerAliasRef: my_provider2
source: github.com/example/module
version: v1.6.0
my_module3:
providerAliasRef: my_provider2
source: github.com/example/module
version: v1.6.0
providers:
my_provider:
auth:
ssh_key: ssh:key:2312312
providerType: github
`), strings.TrimSpace(string(result)))
}
func TestMergeYAML_MissingFile(t *testing.T) {
result, err := MergeYAML("tests/test1.yaml", "tests/test3.yaml")
assert.Error(t, err)
assert.Contains(t, err.Error(), "no such file or directory")
assert.Equal(t, "", string(result))
}
func TestMergeYAML_InvalidYAML(t *testing.T) {
result, err := MergeYAML("tests/test1.yaml", "tests/invalid.yaml")
assert.Error(t, err)
assert.Contains(t, err.Error(), "failed to unmarshal data from file")
assert.Equal(t, "", string(result))
}