-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation.go
51 lines (38 loc) · 1.42 KB
/
validation.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
package main
import (
"fmt"
"log"
"github.com/schrodinger/infra-tester/assertions"
)
func validateTest(test Test, assertionContext *assertions.AssertionContext) error {
for _, assertion := range test.PlanAssertions.Assertions {
if err := assertions.ValidateAssertion(assertion, "plan", assertionContext); err != nil {
return fmt.Errorf("assertion '%s' for plan step failed validation because - %s", assertion.Type, err)
}
}
for _, assertion := range test.ApplyAssertions.Assertions {
if err := assertions.ValidateAssertion(assertion, "apply", assertionContext); err != nil {
return fmt.Errorf("assertion '%s' for apply step failed validation because - %s", assertion.Type, err)
}
}
return nil
}
func validateTests(testPlan TestPlan, assertionContext *assertions.AssertionContext) error {
validatedTests := make(map[string]Test)
for _, test := range testPlan.Tests {
testName := test.Name
if test.Name == "" {
return fmt.Errorf("test name is not defined")
}
// check for duplicate test names
if _, ok := validatedTests[testName]; ok {
return fmt.Errorf("test name '%s' is already defined previously - tests with same name are not allowed", testName)
}
if err := validateTest(test, assertionContext); err != nil {
return fmt.Errorf("test '%s' failed validation: %s", testName, err)
}
validatedTests[testName] = test
}
log.Println("INFO: All tests and assertions are valid.")
return nil
}