Repository navigation
Expand file tree
/
Copy pathconfig_test.go
More file actions
116 lines (100 loc) · 2.56 KB
/
Copy pathconfig_test.go
File metadata and controls
116 lines (100 loc) · 2.56 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package cfg
import (
"testing"
"gopkg.in/yaml.v2"
)
var yml = `
package: fake/testing
import:
- package: github.com/kylelemons/go-gypsy
subpackages:
- yaml
# Intentionally left spaces at end of next line.
- package: github.com/Masterminds/convert
repo: git@github.com:Masterminds/convert.git
vcs: git
ref: a9949121a2e2192ca92fa6dddfeaaa4a4412d955
subpackages:
- color
- nautical
- radial
os:
- linux
arch:
- i386
- arm
- package: github.com/Masterminds/structable
- package: github.com/Masterminds/cookoo/color
- package: github.com/Masterminds/cookoo/convert
devimport:
- package: github.com/kylelemons/go-gypsy
`
func TestManualConfigFromYaml(t *testing.T) {
cfg := &Config{}
err := yaml.Unmarshal([]byte(yml), &cfg)
if err != nil {
t.Errorf("Unable to Unmarshal config yaml")
}
if cfg.Name != "fake/testing" {
t.Errorf("Inaccurate name found %s", cfg.Name)
}
found := false
found2 := false
for _, i := range cfg.Imports {
if i.Name == "github.com/Masterminds/convert" {
found = true
ref := "a9949121a2e2192ca92fa6dddfeaaa4a4412d955"
if i.Reference != ref {
t.Errorf("Config reference for cookoo is inaccurate. Expected '%s' found '%s'", ref, i.Reference)
}
}
if i.Name == "github.com/Masterminds/cookoo" {
found2 = true
if i.Subpackages[0] != "color" {
t.Error("Dependency separating package and subpackage not working")
}
}
}
if !found {
t.Error("Unable to find github.com/Masterminds/convert")
}
if !found2 {
t.Error("Unable to find github.com/Masterminds/cookoo")
}
}
func TestClone(t *testing.T) {
cfg := &Config{}
err := yaml.Unmarshal([]byte(yml), &cfg)
if err != nil {
t.Errorf("Unable to Unmarshal config yaml")
}
cfg2 := cfg.Clone()
if cfg2.Name != "fake/testing" {
t.Error("Config cloning failed")
}
cfg.Name = "foo"
if cfg.Name == cfg2.Name {
t.Error("Cloning Config name failed")
}
}
func TestConfigFromYaml(t *testing.T) {
c, err := ConfigFromYaml([]byte(yml))
if err != nil {
t.Error("ConfigFromYaml failed to parse yaml")
}
if c.Name != "fake/testing" {
t.Error("ConfigFromYaml failed to properly parse yaml")
}
}
func TestHasDependency(t *testing.T) {
c, err := ConfigFromYaml([]byte(yml))
if err != nil {
t.Error("ConfigFromYaml failed to parse yaml for HasDependency")
}
if c.HasDependency("github.com/Masterminds/convert") != true {
t.Error("HasDependency failing to pickup depenency")
}
if c.HasDependency("foo/bar/bar") != false {
t.Error("HasDependency picking up dependency it shouldn't")
}
}