(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestCachedScanner_ScanUsers(t *testing.T) { |
| 14 | t.Parallel() |
| 15 | |
| 16 | ctx := context.Background() |
| 17 | |
| 18 | tests := map[string]struct { |
| 19 | scanner *mockScanner |
| 20 | ttl time.Duration |
| 21 | waitTime time.Duration |
| 22 | expectedCalls int |
| 23 | expectErr bool |
| 24 | }{ |
| 25 | "cache hit within TTL": { |
| 26 | scanner: &mockScanner{ |
| 27 | active: []string{"user-1"}, |
| 28 | deleting: []string{"user-2"}, |
| 29 | deleted: []string{"user-3"}, |
| 30 | }, |
| 31 | ttl: 1 * time.Hour, |
| 32 | waitTime: 0, |
| 33 | expectedCalls: 1, |
| 34 | expectErr: false, |
| 35 | }, |
| 36 | "cache miss after TTL": { |
| 37 | scanner: &mockScanner{ |
| 38 | active: []string{"user-1"}, |
| 39 | deleting: []string{"user-2"}, |
| 40 | deleted: []string{"user-3"}, |
| 41 | }, |
| 42 | ttl: 100 * time.Millisecond, |
| 43 | waitTime: 500 * time.Millisecond, |
| 44 | expectedCalls: 2, |
| 45 | expectErr: false, |
| 46 | }, |
| 47 | "scanner error": { |
| 48 | scanner: &mockScanner{ |
| 49 | err: assert.AnError, |
| 50 | }, |
| 51 | ttl: 1 * time.Hour, |
| 52 | waitTime: 0, |
| 53 | expectedCalls: 1, |
| 54 | expectErr: true, |
| 55 | }, |
| 56 | "empty results": { |
| 57 | scanner: &mockScanner{ |
| 58 | active: []string{}, |
| 59 | deleting: []string{}, |
| 60 | deleted: []string{}, |
| 61 | }, |
| 62 | ttl: 1 * time.Hour, |
| 63 | waitTime: 0, |
| 64 | expectedCalls: 1, |
| 65 | expectErr: false, |
| 66 | }, |
| 67 | } |
| 68 | |
| 69 | for testName, testData := range tests { |
| 70 | t.Run(testName, func(t *testing.T) { |
nothing calls this directly
no test coverage detected