| 128 | } |
| 129 | |
| 130 | func TestGet(t *testing.T) { |
| 131 | s := store.New(map[string]int{"test1": 0, "test2": 1}) |
| 132 | |
| 133 | scenarios := []struct { |
| 134 | key string |
| 135 | expect int |
| 136 | }{ |
| 137 | {"test1", 0}, |
| 138 | {"test2", 1}, |
| 139 | {"missing", 0}, // should auto fallback to the zero value |
| 140 | } |
| 141 | |
| 142 | for _, scenario := range scenarios { |
| 143 | t.Run(scenario.key, func(t *testing.T) { |
| 144 | val := s.Get(scenario.key) |
| 145 | if val != scenario.expect { |
| 146 | t.Fatalf("Expected %v, got %v", scenario.expect, val) |
| 147 | } |
| 148 | }) |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | func TestGetOk(t *testing.T) { |
| 153 | s := store.New(map[string]int{"test1": 0, "test2": 1}) |