(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestValidateSafeOutputsMax(t *testing.T) { |
| 14 | t.Run("nil config is valid", func(t *testing.T) { |
| 15 | err := validateSafeOutputsMax(nil) |
| 16 | assert.NoError(t, err, "nil config should be valid") |
| 17 | }) |
| 18 | |
| 19 | t.Run("config with no max fields is valid", func(t *testing.T) { |
| 20 | config := &SafeOutputsConfig{} |
| 21 | err := validateSafeOutputsMax(config) |
| 22 | assert.NoError(t, err, "config with no max fields should be valid") |
| 23 | }) |
| 24 | |
| 25 | t.Run("max of 1 is valid", func(t *testing.T) { |
| 26 | config := &SafeOutputsConfig{ |
| 27 | AddComments: &AddCommentsConfig{ |
| 28 | BaseSafeOutputConfig: BaseSafeOutputConfig{Max: strPtr("1")}, |
| 29 | }, |
| 30 | } |
| 31 | err := validateSafeOutputsMax(config) |
| 32 | assert.NoError(t, err, "max: 1 should be valid") |
| 33 | }) |
| 34 | |
| 35 | t.Run("max of 5 is valid", func(t *testing.T) { |
| 36 | config := &SafeOutputsConfig{ |
| 37 | CreateIssues: &CreateIssuesConfig{ |
| 38 | BaseSafeOutputConfig: BaseSafeOutputConfig{Max: strPtr("5")}, |
| 39 | }, |
| 40 | } |
| 41 | err := validateSafeOutputsMax(config) |
| 42 | assert.NoError(t, err, "max: 5 should be valid") |
| 43 | }) |
| 44 | |
| 45 | t.Run("max of -1 is valid (unlimited)", func(t *testing.T) { |
| 46 | config := &SafeOutputsConfig{ |
| 47 | AddComments: &AddCommentsConfig{ |
| 48 | BaseSafeOutputConfig: BaseSafeOutputConfig{Max: strPtr("-1")}, |
| 49 | }, |
| 50 | } |
| 51 | err := validateSafeOutputsMax(config) |
| 52 | assert.NoError(t, err, "max: -1 should be valid (means unlimited per spec)") |
| 53 | }) |
| 54 | |
| 55 | t.Run("max of 0 is invalid", func(t *testing.T) { |
| 56 | config := &SafeOutputsConfig{ |
| 57 | AddComments: &AddCommentsConfig{ |
| 58 | BaseSafeOutputConfig: BaseSafeOutputConfig{Max: strPtr("0")}, |
| 59 | }, |
| 60 | } |
| 61 | err := validateSafeOutputsMax(config) |
| 62 | require.Error(t, err, "max: 0 should be invalid") |
| 63 | assert.Contains(t, err.Error(), "max must be a positive integer or -1", "error should explain valid values") |
| 64 | assert.Contains(t, err.Error(), "add-comment", "error should mention the field name") |
| 65 | }) |
| 66 | |
| 67 | t.Run("max of -2 is invalid", func(t *testing.T) { |
| 68 | config := &SafeOutputsConfig{ |
| 69 | CreateIssues: &CreateIssuesConfig{ |
| 70 | BaseSafeOutputConfig: BaseSafeOutputConfig{Max: strPtr("-2")}, |
nothing calls this directly
no test coverage detected