| 150 | } |
| 151 | |
| 152 | func TestGetOk(t *testing.T) { |
| 153 | s := store.New(map[string]int{"test1": 0, "test2": 1}) |
| 154 | |
| 155 | scenarios := []struct { |
| 156 | key string |
| 157 | expectValue int |
| 158 | expectOk bool |
| 159 | }{ |
| 160 | {"test1", 0, true}, |
| 161 | {"test2", 1, true}, |
| 162 | {"missing", 0, false}, // should auto fallback to the zero value |
| 163 | } |
| 164 | |
| 165 | for _, scenario := range scenarios { |
| 166 | t.Run(scenario.key, func(t *testing.T) { |
| 167 | val, ok := s.GetOk(scenario.key) |
| 168 | |
| 169 | if ok != scenario.expectOk { |
| 170 | t.Fatalf("Expected ok %v, got %v", scenario.expectOk, ok) |
| 171 | } |
| 172 | |
| 173 | if val != scenario.expectValue { |
| 174 | t.Fatalf("Expected %v, got %v", scenario.expectValue, val) |
| 175 | } |
| 176 | }) |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | func TestGetAll(t *testing.T) { |
| 181 | data := map[string]int{ |