This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
params_test.go
148 lines (122 loc) · 3.13 KB
/
params_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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"bytes"
"fmt"
"io/ioutil"
"testing"
)
// test that various replacements succeed
func TestReplacement(t *testing.T) {
template, err := ioutil.ReadFile("tests/add-and-gc-template.yml")
if err != nil {
t.Fatal(err)
}
target, err := ioutil.ReadFile("tests/add-and-gc.yml")
if err != nil {
t.Fatal(err)
}
params := Params{"NUM_NODES": "1",
"NUM_TIMES": "10",
"FILE_SIZE": "10",
"ON_NODE": "1",
}
processedTemplate, err := replaceParams(template, params)
if err != nil {
t.Log(err)
}
if bytes.Compare(processedTemplate, target) != 0 {
t.Fatal("Template with replaced params not equal to target test.")
}
}
// test that bad replacement fails
func TestBadReplacement(t *testing.T) {
template, err := ioutil.ReadFile("tests/add-and-gc-template.yml")
if err != nil {
t.Fatal(err)
}
target, err := ioutil.ReadFile("tests/add-and-gc.yml")
if err != nil {
t.Fatal(err)
}
params := Params{"NUM_NODES": "1",
"NUM_TIMES": "10",
"FILE_SIZE": "10",
"ON_NODE": "0",
}
processedTemplate, err := replaceParams(template, params)
if err != nil {
t.Log(err)
}
if bytes.Compare(processedTemplate, target) == 0 {
t.Fatal("This test should have failed (wrong replacement value).")
}
}
// test that replacement using config file succeeds
func TestConfigReplacement(t *testing.T) {
template, err := ioutil.ReadFile("tests/add-and-gc-template.yml")
if err != nil {
t.Fatal(err)
}
target, err := ioutil.ReadFile("tests/add-and-gc.yml")
if err != nil {
t.Fatal(err)
}
config, err := loadConfigFile("testutils/add-and-gc-config.yml")
if err != nil {
t.Fatal(err)
}
processedTemplate, err := replaceParams(template, config.Params)
if err != nil {
t.Log(err)
}
if bytes.Compare(processedTemplate, target) != 0 {
t.Fatal("Template with replaced params not equal to target test.")
}
}
// test that parameter addition works as expected
func TestParamsOverride(t *testing.T) {
template, err := ioutil.ReadFile("tests/add-and-gc-template.yml")
if err != nil {
t.Fatal(err)
}
target, err := ioutil.ReadFile("tests/add-and-gc.yml")
if err != nil {
t.Fatal(err)
}
params1 := Params{"NUM_NODES": "1",
"NUM_TIMES": "10",
"ON_NODE": "0",
}
params2 := Params{"NUM_NODES": "1",
"FILE_SIZE": "10",
"ON_NODE": "1",
}
config := TestConfig{Params: make(Params)}
config.addParams(params1)
config.addParams(params2)
processedTemplate, err := replaceParams(template, config.Params)
if err != nil {
t.Log(err)
}
if bytes.Compare(processedTemplate, target) != 0 {
t.Fatal("Template with replaced params not equal to target test.")
}
}
// test that missing parameters fail replacement
func TestUndeclaredParams(t *testing.T) {
template, err := ioutil.ReadFile("tests/add-and-gc-template.yml")
if err != nil {
t.Fatal(err)
}
params := Params{"NUM_NODES": "1",
"NUM_TIMES": "10",
"FILE_SIZE": "10",
}
_, err = replaceParams(template, params)
if err == nil {
t.Fatal("Param replacement should have failed (missing value).")
}
if err.Error() != fmt.Sprintf("Parameter ON_NODE not specified") {
t.Fatal(fmt.Sprintf("Failed with different error than intended: %s", err))
}
}