@@ -24,27 +24,41 @@ func (re *Recipe) Validate() error {
24
24
return err
25
25
}
26
26
27
- checkDuplicates := make (map [string ]bool )
27
+ varDuplicateCheck := make (map [string ]struct {} )
28
28
for _ , v := range re .Variables {
29
+ if _ , exists := varDuplicateCheck [v .Name ]; exists {
30
+ return fmt .Errorf ("variable %s has been declared multiple times" , v .Name )
31
+ }
29
32
if err := v .Validate (); err != nil {
30
33
return fmt .Errorf ("error on variable %s: %w" , v .Name , err )
31
34
}
32
- if _ , exists := checkDuplicates [v .Name ]; exists {
33
- return fmt .Errorf ("variable %s has been declared multiple times" , v .Name )
34
- }
35
- checkDuplicates [v .Name ] = true
35
+ varDuplicateCheck [v .Name ] = struct {}{}
36
36
}
37
37
38
- duplicateCheck := make (map [string ]struct {})
38
+ testDuplicateCheck := make (map [string ]struct {})
39
39
for _ , t := range re .Tests {
40
- if _ , exists := duplicateCheck [t .Name ]; exists {
40
+ if _ , exists := testDuplicateCheck [t .Name ]; exists {
41
41
return fmt .Errorf ("test case %s has been declared multiple times" , t .Name )
42
42
}
43
43
44
- duplicateCheck [t .Name ] = struct {}{}
45
44
if err := t .Validate (); err != nil {
46
45
return fmt .Errorf ("error when validating recipe test case %s: %w" , t .Name , err )
47
46
}
47
+ testDuplicateCheck [t .Name ] = struct {}{}
48
+
49
+ for vName := range t .Values {
50
+ found := false
51
+ for _ , v := range re .Variables {
52
+ if v .Name == vName {
53
+ found = true
54
+ break
55
+ }
56
+ }
57
+
58
+ if ! found {
59
+ return fmt .Errorf ("test case %s references an unknown variable %s" , t .Name , vName )
60
+ }
61
+ }
48
62
}
49
63
50
64
return nil
0 commit comments