|
14 | 14 | package validators |
15 | 15 |
|
16 | 16 | import ( |
17 | | - "hpc-toolkit/pkg/config" |
18 | | - "hpc-toolkit/pkg/modulereader" |
19 | | - "testing" |
| 17 | + "hpc-toolkit/pkg/config" |
| 18 | + "hpc-toolkit/pkg/modulereader" |
| 19 | + "testing" |
20 | 20 |
|
21 | | - "github.com/zclconf/go-cty/cty" |
| 21 | + "github.com/zclconf/go-cty/cty" |
22 | 22 | ) |
23 | 23 |
|
24 | 24 | func TestRegexValidator(t *testing.T) { |
25 | | - // Fake blueprint for testing |
26 | | - bp := config.Blueprint{ |
27 | | - BlueprintName: "test-bp", |
28 | | - Groups: []config.Group{ |
29 | | - { |
30 | | - Name: "primary", |
31 | | - Modules: []config.Module{ |
32 | | - { |
33 | | - ID: "test-module", |
34 | | - Source: "test/module", |
35 | | - Settings: config.NewDict(map[string]cty.Value{ |
36 | | - "name": cty.StringVal("Invalid-Name"), |
37 | | - }), |
38 | | - }, |
39 | | - }, |
40 | | - }, |
41 | | - }, |
42 | | - } |
| 25 | + // Fake blueprint for testing |
| 26 | + bp := config.Blueprint{ |
| 27 | + BlueprintName: "test-bp", |
| 28 | + Groups: []config.Group{ |
| 29 | + { |
| 30 | + Name: "primary", |
| 31 | + Modules: []config.Module{ |
| 32 | + { |
| 33 | + ID: "test-module", |
| 34 | + Source: "test/module", |
| 35 | + Settings: config.NewDict(map[string]cty.Value{ |
| 36 | + "name": cty.StringVal("Invalid-Name"), |
| 37 | + }), |
| 38 | + }, |
| 39 | + }, |
| 40 | + }, |
| 41 | + }, |
| 42 | + } |
43 | 43 |
|
44 | | - // Validation rule from metadata.yaml |
45 | | - rule := modulereader.ValidationRule{ |
46 | | - Validator: "regex", |
47 | | - ErrorMessage: "'name' must be lowercase and start with a letter.", |
48 | | - Inputs: map[string]interface{}{ |
49 | | - "vars": []interface{}{"name"}, |
50 | | - "pattern": "^[a-z]([-a-z0-9]*[a-z0-9])?$", |
51 | | - }, |
52 | | - } |
| 44 | + // Validation rule from metadata.yaml |
| 45 | + rule := modulereader.ValidationRule{ |
| 46 | + Validator: "regex", |
| 47 | + ErrorMessage: "'name' must be lowercase and start with a letter.", |
| 48 | + Inputs: map[string]interface{}{ |
| 49 | + "vars": []interface{}{"name"}, |
| 50 | + "pattern": "^[a-z]([-a-z0-9]*[a-z0-9])?$", |
| 51 | + }, |
| 52 | + } |
53 | 53 |
|
54 | | - validator := RegexValidator{} |
55 | | - err := validator.Validate(bp, bp.Groups[0].Modules[0], rule, bp.Groups[0], 0) |
56 | | - if err == nil { |
57 | | - t.Errorf("Expected validation error, but got nil") |
58 | | - } |
| 54 | + validator := RegexValidator{} |
| 55 | + err := validator.Validate(bp, bp.Groups[0].Modules[0], rule, bp.Groups[0], 0) |
| 56 | + if err == nil { |
| 57 | + t.Errorf("Expected validation error, but got nil") |
| 58 | + } |
59 | 59 |
|
60 | | - expectedError := "deployment_groups[0].modules[0].settings.name: 'name' must be lowercase and start with a letter." |
61 | | - if err.Error() != expectedError { |
62 | | - t.Errorf("Expected error message '%s', but got '%s'", expectedError, err.Error()) |
63 | | - } |
| 60 | + expectedError := "deployment_groups[0].modules[0].settings.name: 'name' must be lowercase and start with a letter." |
| 61 | + if err.Error() != expectedError { |
| 62 | + t.Errorf("Expected error message '%s', but got '%s'", expectedError, err.Error()) |
| 63 | + } |
64 | 64 | } |
0 commit comments