-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdag_test.go
63 lines (47 loc) · 1.5 KB
/
dag_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
package hclconfig
import (
"path/filepath"
"testing"
"github.com/jumppad-labs/hclconfig/test_fixtures/structs"
"github.com/stretchr/testify/require"
)
func setupGraphConfig(t *testing.T) *Config {
absoluteFolderPath, err := filepath.Abs("./test_fixtures/simple/container.hcl")
if err != nil {
t.Fatal(err)
}
p := NewParser(DefaultOptions())
p.RegisterType("container", &structs.Container{})
p.RegisterType("network", &structs.Network{})
p.RegisterType("template", &structs.Template{})
c, err := p.ParseFile(absoluteFolderPath)
require.NoError(t, err)
return c
}
func TestDoYaLikeDAGAddsDependencies(t *testing.T) {
c := setupGraphConfig(t)
g, err := doYaLikeDAGs(c)
require.NoError(t, err)
network, err := c.FindResource("resource.network.onprem")
require.NoError(t, err)
template, err := c.FindResource("resource.template.consul_config")
require.NoError(t, err)
// check the dependency tree of the base container
base, err := c.FindResource("resource.container.base")
require.NoError(t, err)
s, err := g.Descendents(base)
require.NoError(t, err)
// check the network is returned
list := s.List()
require.Contains(t, list, network)
// check the dependency tree of the consul container
consul, err := c.FindResource("resource.container.consul")
require.NoError(t, err)
s, err = g.Descendents(consul)
require.NoError(t, err)
// check the network is returned
list = s.List()
require.Contains(t, list, network)
require.Contains(t, list, base)
require.Contains(t, list, template)
}