| 48 | } |
| 49 | |
| 50 | func TestTable_AddField(t *testing.T) { |
| 51 | var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{}) |
| 52 | |
| 53 | defer func() { |
| 54 | _ = testingStore.Close() |
| 55 | }() |
| 56 | |
| 57 | err := table.AddFields("expiresAt") |
| 58 | if err != nil { |
| 59 | t.Fatal(err) |
| 60 | } |
| 61 | |
| 62 | var before = time.Now() |
| 63 | for _, item := range []*testCachedItem{ |
| 64 | { |
| 65 | Hash: "a1", |
| 66 | URL: "https://example.com/a1", |
| 67 | ExpiresAt: 1710832067, |
| 68 | }, |
| 69 | { |
| 70 | Hash: "a5", |
| 71 | URL: "https://example.com/a5", |
| 72 | ExpiresAt: time.Now().Unix() + 7200, |
| 73 | }, |
| 74 | { |
| 75 | Hash: "a4", |
| 76 | URL: "https://example.com/a4", |
| 77 | ExpiresAt: time.Now().Unix() + 86400, |
| 78 | }, |
| 79 | { |
| 80 | Hash: "a3", |
| 81 | URL: "https://example.com/a3", |
| 82 | ExpiresAt: time.Now().Unix() + 1800, |
| 83 | }, |
| 84 | { |
| 85 | Hash: "a2", |
| 86 | URL: "https://example.com/a2", |
| 87 | ExpiresAt: time.Now().Unix() + 365*86400, |
| 88 | }, |
| 89 | } { |
| 90 | err = table.Set(item.Hash, item) |
| 91 | if err != nil { |
| 92 | t.Fatal(err) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | t.Log("set cost:", time.Since(before).Seconds()*1000, "ms") |
| 97 | |
| 98 | testInspectDB(t) |
| 99 | } |
| 100 | |
| 101 | func TestTable_AddField_Many(t *testing.T) { |
| 102 | if !testutils.IsSingleTesting() { |