-
Notifications
You must be signed in to change notification settings - Fork 13
/
context_test.go
91 lines (72 loc) · 2.02 KB
/
context_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
package main
import (
"bytes"
"runtime"
"testing"
)
func TestConvertToEntryGroups(t *testing.T) {
yamlContents := []byte(`
describe: Tests
constants:
TEST_VAR: test
before:
- command: echo "Set up everything before all"
before_each:
- command: echo "Set up everything before each"
after_each:
- command: echo "Tear down everything after each"
after:
- command: echo "Tear down everything after all"
specs:
- name: First Test should do whatever
entries:
- name: Stdout_not_has | must pass
command: echo "hello world"
stdout_not_has: ["bye" ]
- name: Stdout_has | must pass
command: echo "hello world"
stdout_has: ["hello", "world"]
- name: Second Test should do whatever
entries:
- name: Stdout_has | must pass
command: echo "bye world"
stdout_has: ["bye", "world"]`)
if runtime.GOOS == "windows" {
yamlContents = bytes.Replace(yamlContents, []byte("echo"), []byte("cmd /C echo"), -1)
}
var groups []EntryGroup
if err := TextContextLoader(yamlContents).Load(&groups); err != nil {
t.Fatal(err)
}
if len(groups) != 5 {
t.Fatal("Context must be converted to 5 EntryGroups")
}
}
func TestVersionsCompatibility(t *testing.T) {
yamlContents := []byte(`
- name: Tests
entries:
- name: Stdout_has | must pass
command: echo "hello world"
stdout_has: ["hello", "world" ]
- name: Stdout_has | must not pass
command: echo "hello world"
stdout_has: ["hello"]
stdout_not_has: ["apple"]
- name: Stdout_not_has | must pass
command: echo "hello world"
stdout_not_has: ["orange", "apple"]
- name: Stdout_not_has | must not pass
command: echo "hello world"
stdout_not_has: ["apple"]`)
if runtime.GOOS == "windows" {
yamlContents = bytes.Replace(yamlContents, []byte("echo"), []byte("cmd /C echo"), -1)
}
var groups []EntryGroup
if err := TextContextLoader(yamlContents).Load(&groups); err != nil {
t.Fatal(err)
}
if len(groups) != 1 {
t.Fatal("Context must be converted to 1 EntryGroup")
}
}