TestValidateIntRange tests the validateIntRange helper function with boundary values
(t *testing.T)
| 14 | |
| 15 | // TestValidateIntRange tests the validateIntRange helper function with boundary values |
| 16 | func TestValidateIntRange(t *testing.T) { |
| 17 | tests := []struct { |
| 18 | name string |
| 19 | value int |
| 20 | min int |
| 21 | max int |
| 22 | fieldName string |
| 23 | wantError bool |
| 24 | errorText string |
| 25 | }{ |
| 26 | { |
| 27 | name: "value at minimum", |
| 28 | value: 1, |
| 29 | min: 1, |
| 30 | max: 100, |
| 31 | fieldName: "test-field", |
| 32 | wantError: false, |
| 33 | }, |
| 34 | { |
| 35 | name: "value at maximum", |
| 36 | value: 100, |
| 37 | min: 1, |
| 38 | max: 100, |
| 39 | fieldName: "test-field", |
| 40 | wantError: false, |
| 41 | }, |
| 42 | { |
| 43 | name: "value in middle of range", |
| 44 | value: 50, |
| 45 | min: 1, |
| 46 | max: 100, |
| 47 | fieldName: "test-field", |
| 48 | wantError: false, |
| 49 | }, |
| 50 | { |
| 51 | name: "value below minimum", |
| 52 | value: 0, |
| 53 | min: 1, |
| 54 | max: 100, |
| 55 | fieldName: "test-field", |
| 56 | wantError: true, |
| 57 | errorText: "test-field must be between 1 and 100, got 0", |
| 58 | }, |
| 59 | { |
| 60 | name: "value above maximum", |
| 61 | value: 101, |
| 62 | min: 1, |
| 63 | max: 100, |
| 64 | fieldName: "test-field", |
| 65 | wantError: true, |
| 66 | errorText: "test-field must be between 1 and 100, got 101", |
| 67 | }, |
| 68 | { |
| 69 | name: "negative value below minimum", |
| 70 | value: -1, |
| 71 | min: 1, |
| 72 | max: 100, |
| 73 | fieldName: "test-field", |
nothing calls this directly
no test coverage detected