| 342 | } |
| 343 | |
| 344 | func TestUnmarshalJSON(t *testing.T) { |
| 345 | s := store.Store[string, string]{} |
| 346 | s.Set("b", "old") // should be overwritten |
| 347 | s.Set("c", "test3") // ensures that the old values are not removed |
| 348 | |
| 349 | raw := []byte(`{"a":"test1", "b":"test2"}`) |
| 350 | if err := json.Unmarshal(raw, &s); err != nil { |
| 351 | t.Fatal(err) |
| 352 | } |
| 353 | |
| 354 | if v := s.Get("a"); v != "test1" { |
| 355 | t.Fatalf("Expected store.a to be %q, got %q", "test1", v) |
| 356 | } |
| 357 | |
| 358 | if v := s.Get("b"); v != "test2" { |
| 359 | t.Fatalf("Expected store.b to be %q, got %q", "test2", v) |
| 360 | } |
| 361 | |
| 362 | if v := s.Get("c"); v != "test3" { |
| 363 | t.Fatalf("Expected store.c to be %q, got %q", "test3", v) |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | func TestMarshalJSON(t *testing.T) { |
| 368 | s := &store.Store[string, string]{} |