(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestAccumulate(t *testing.T) { |
| 20 | called := 0 |
| 21 | result, err := accumulate(10, func() (byte, error) { |
| 22 | called++ |
| 23 | //nolint:gosec // G115: called is bounded by test iteration count, no overflow possible. |
| 24 | return byte('A' + called), nil |
| 25 | }) |
| 26 | |
| 27 | assert.NilError(t, err) |
| 28 | assert.Equal(t, called, 10) |
| 29 | assert.Equal(t, result, "BCDEFGHIJK") |
| 30 | |
| 31 | t.Run("Error", func(t *testing.T) { |
| 32 | called := 0 |
| 33 | expected := errors.New("zap") |
| 34 | result, err := accumulate(10, func() (byte, error) { |
| 35 | called++ |
| 36 | if called < 5 { |
| 37 | //nolint:gosec // G115: called is bounded by test iteration count, no overflow possible. |
| 38 | return byte('A' + called), nil |
| 39 | } else { |
| 40 | return 'Z', expected |
| 41 | } |
| 42 | }) |
| 43 | |
| 44 | assert.Equal(t, err, expected) |
| 45 | assert.Equal(t, called, 5, "expected an early return") |
| 46 | assert.Equal(t, result, "") |
| 47 | }) |
| 48 | } |
| 49 | |
| 50 | func TestGenerateAlphaNumericPassword(t *testing.T) { |
| 51 | for _, length := range []int{0, 1, 2, 3, 5, 20, 200} { |
nothing calls this directly
no test coverage detected