(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestNewModuleParameter(t *testing.T) { |
| 10 | tests := []struct { |
| 11 | name string |
| 12 | paramName string |
| 13 | defValue string |
| 14 | paramType ParamType |
| 15 | validator string |
| 16 | desc string |
| 17 | }{ |
| 18 | { |
| 19 | name: "string parameter with validator", |
| 20 | paramName: "test.param", |
| 21 | defValue: "default", |
| 22 | paramType: STRING, |
| 23 | validator: "^[a-z]+$", |
| 24 | desc: "A test parameter", |
| 25 | }, |
| 26 | { |
| 27 | name: "int parameter without validator", |
| 28 | paramName: "test.int", |
| 29 | defValue: "42", |
| 30 | paramType: INT, |
| 31 | validator: "", |
| 32 | desc: "An integer parameter", |
| 33 | }, |
| 34 | } |
| 35 | |
| 36 | for _, tt := range tests { |
| 37 | t.Run(tt.name, func(t *testing.T) { |
| 38 | p := NewModuleParameter(tt.paramName, tt.defValue, tt.paramType, tt.validator, tt.desc) |
| 39 | |
| 40 | if p.Name != tt.paramName { |
| 41 | t.Errorf("expected name %s, got %s", tt.paramName, p.Name) |
| 42 | } |
| 43 | if p.Value != tt.defValue { |
| 44 | t.Errorf("expected value %s, got %s", tt.defValue, p.Value) |
| 45 | } |
| 46 | if p.Type != tt.paramType { |
| 47 | t.Errorf("expected type %v, got %v", tt.paramType, p.Type) |
| 48 | } |
| 49 | if p.Description != tt.desc { |
| 50 | t.Errorf("expected description %s, got %s", tt.desc, p.Description) |
| 51 | } |
| 52 | |
| 53 | if tt.validator != "" && p.Validator == nil { |
| 54 | t.Error("expected validator to be set") |
| 55 | } |
| 56 | if tt.validator == "" && p.Validator != nil { |
| 57 | t.Error("expected validator to be nil") |
| 58 | } |
| 59 | }) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | func TestNewStringParameter(t *testing.T) { |
| 64 | p := NewStringParameter("test.string", "hello", "^[a-z]+$", "A string param") |
nothing calls this directly
no test coverage detected