-
Notifications
You must be signed in to change notification settings - Fork 1
/
stack_self_environment_test.go
114 lines (97 loc) · 2.68 KB
/
stack_self_environment_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
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
package engine
import (
"testing"
"github.com/ekara-platform/engine/util"
"github.com/ekara-platform/engine/model"
"github.com/stretchr/testify/assert"
)
func TestEnvironmentSelfStackNoComponent(t *testing.T) {
descContent := `
name: ekaraDemoVar
qualifier: dev
ekara:
parent:
repository: parent
# Following content just to force the download of comp1
orchestrator:
component: comp1
providers:
p1:
component: comp1
nodes:
node1:
instances: 1
provider:
name: p1
stacks:
myStack:
`
checkSelfStack(t, descContent)
}
func TestEnvironmentSelfStackLowDash(t *testing.T) {
descContent := `
name: ekaraDemoVar
qualifier: dev
ekara:
parent:
repository: parent
# Following content just to force the download of comp1
orchestrator:
component: comp1
providers:
p1:
component: comp1
nodes:
node1:
instances: 1
provider:
name: p1
stacks:
myStack:
component: "_"
`
checkSelfStack(t, descContent)
}
func checkSelfStack(t *testing.T, descContent string) {
parentContent := `
ekara:
components:
comp1:
repository: comp1
`
mainPath := "descriptor"
tester := util.CreateComponentTester(t, model.CreateEmptyParameters())
defer tester.Clean()
repParent := tester.CreateDir("parent")
tester.CreateDirEmptyDesc("comp1")
repDesc := tester.CreateDir(mainPath)
repParent.WriteCommit("ekara.yaml", parentContent)
repDesc.WriteCommit("ekara.yaml", descContent)
// write the compose/playbook content into the descriptor component
repDesc.WriteCommit("docker_compose.yml", "docker compose content")
tester.Init(repDesc.AsRepository("master"))
env := tester.Env()
assert.NotNil(t, env)
// comp1 should be downloaded because it's used as orchestrator and provider
tester.AssertComponentsExactly(model.MainComponentId, model.MainComponentId+model.ParentComponentSuffix, "comp1")
// Chect that the environment has one self contained stack
if assert.Len(t, env.Stacks, 1) {
stack, ok := env.Stacks["myStack"]
if assert.True(t, ok) {
//Check that the self contained stack has been well built
assert.Equal(t, "myStack", stack.Name)
stackC, err := stack.Component(tester.Model())
assert.Nil(t, err)
assert.NotNil(t, stackC)
assert.Equal(t, model.MainComponentId, stackC.ComponentId())
// Check that the stack is usable and returns the environent as component
usableStack, err := tester.ComponentManager().Use(stack, tester.TemplateContext())
defer usableStack.Release()
assert.Nil(t, err)
assert.NotNil(t, usableStack)
assert.False(t, usableStack.Templated())
// Check that the stacks contains the compose/playbook file
tester.AssertFileContent(usableStack, "docker_compose.yml", "docker compose content")
}
}
}