(t *testing.T)
| 59 | } |
| 60 | |
| 61 | func TestInitSystemKV_existing(t *testing.T) { |
| 62 | // Setup |
| 63 | db := database.InitTestMemoryDB(t) |
| 64 | |
| 65 | database.MustExec(t, "inserting a system config", db, "INSERT INTO system (key, value) VALUES (?, ?)", "testKey", "testVal") |
| 66 | |
| 67 | var originalCount int |
| 68 | database.MustScan(t, "counting system configs", db.QueryRow("SELECT count(*) FROM system"), &originalCount) |
| 69 | |
| 70 | // Execute |
| 71 | tx, err := db.Begin() |
| 72 | if err != nil { |
| 73 | t.Fatal(errors.Wrap(err, "beginning a transaction")) |
| 74 | } |
| 75 | |
| 76 | if err := initSystemKV(tx, "testKey", "newTestVal"); err != nil { |
| 77 | tx.Rollback() |
| 78 | t.Fatal(errors.Wrap(err, "executing")) |
| 79 | } |
| 80 | |
| 81 | tx.Commit() |
| 82 | |
| 83 | // Test |
| 84 | var count int |
| 85 | database.MustScan(t, "counting system configs", db.QueryRow("SELECT count(*) FROM system"), &count) |
| 86 | assert.Equal(t, count, originalCount, "system count mismatch") |
| 87 | |
| 88 | var val string |
| 89 | database.MustScan(t, "getting system value", |
| 90 | db.QueryRow("SELECT value FROM system WHERE key = ?", "testKey"), &val) |
| 91 | assert.Equal(t, val, "testVal", "system value should not have been updated") |
| 92 | } |
| 93 | |
| 94 | func TestInit_APIEndpoint(t *testing.T) { |
| 95 | // Create a temporary directory for test |
nothing calls this directly
no test coverage detected