(t *testing.T)
| 27 | ) |
| 28 | |
| 29 | func TestGet(t *testing.T) { |
| 30 | ctx := context.Background() |
| 31 | |
| 32 | tests := []struct { |
| 33 | name string |
| 34 | setupCache func(*PolicyCache) |
| 35 | key string |
| 36 | expectedValue string |
| 37 | expectedFound bool |
| 38 | }{ |
| 39 | { |
| 40 | name: "key does not exist", |
| 41 | setupCache: func(c *PolicyCache) {}, |
| 42 | key: "nonexistent", |
| 43 | expectedValue: "", |
| 44 | expectedFound: false, |
| 45 | }, |
| 46 | { |
| 47 | name: "key exists with valid value", |
| 48 | setupCache: func(c *PolicyCache) { |
| 49 | c.Set("existing", "value", nil) |
| 50 | }, |
| 51 | key: "existing", |
| 52 | expectedValue: "value", |
| 53 | expectedFound: true, |
| 54 | }, |
| 55 | { |
| 56 | name: "key exists but with wrong type", |
| 57 | setupCache: func(c *PolicyCache) { |
| 58 | c.Data.Store("wrongtype", "string value") |
| 59 | }, |
| 60 | key: "wrongtype", |
| 61 | expectedValue: "", |
| 62 | expectedFound: false, |
| 63 | }, |
| 64 | { |
| 65 | name: "empty key with value", |
| 66 | setupCache: func(c *PolicyCache) { |
| 67 | c.Set("", "emptykeyvalue", nil) |
| 68 | }, |
| 69 | key: "", |
| 70 | expectedValue: "emptykeyvalue", |
| 71 | expectedFound: true, |
| 72 | }, |
| 73 | { |
| 74 | name: "key with error", |
| 75 | setupCache: func(c *PolicyCache) { |
| 76 | c.Set("errorkey", "errorvalue", errors.New("test error")) |
| 77 | }, |
| 78 | key: "errorkey", |
| 79 | expectedValue: "errorvalue", |
| 80 | expectedFound: true, |
| 81 | }, |
| 82 | { |
| 83 | name: "key with empty value", |
| 84 | setupCache: func(c *PolicyCache) { |
| 85 | c.Set("emptyvalue", "", nil) |
| 86 | }, |
nothing calls this directly
no test coverage detected