-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_test.go
55 lines (47 loc) · 1.29 KB
/
run_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
package factory
import (
"testing"
"github.com/hashicorp/hcl/v2/hclparse"
"github.com/stretchr/testify/assert"
)
func TestDecodeRunBlock(t *testing.T) {
parser := hclparse.NewParser()
file, _ := parser.ParseHCL([]byte(`
run "Install Docker" {
command = "apt-get install docker"
}
run "Push Docker Image" {
file = "push.sh"
}
`), "test")
expected := []struct {
Name string
Command []string
File string
}{
{
Name: "Install Docker",
Command: []string{"apt-get install docker"},
File: "",
},
{
Name: "Push Docker Image",
Command: nil,
File: "push.sh",
},
}
stage, diags := file.Body.Content(stageBlockSchema)
if diags.HasErrors() {
t.Fatalf("Error decoding stage block: %s", diags)
}
f := NewFile()
for i, block := range stage.Blocks {
runBlock, d := decodeRunBlock(block, f, "stage")
if d.HasErrors() {
t.Fatalf("Error decoding run block: %s", d)
}
assert.Equal(t, expected[i].Name, runBlock.Name, "Expected %s got %s", expected[i].Name, runBlock.Name)
assert.Equal(t, expected[i].Command, runBlock.Commands, "expected commands to be %+v got %+v", expected[i].Command, runBlock.Commands)
assert.Equal(t, expected[i].File, runBlock.File, "Expected runBlock.File to be %s, got %s", expected[i].File, runBlock.File)
}
}