|
| 1 | +package migrations_tests |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/filecoin-project/boost/db" |
| 8 | + "github.com/filecoin-project/boost/db/migrations" |
| 9 | + "github.com/pressly/goose/v3" |
| 10 | + "github.com/stretchr/testify/require" |
| 11 | +) |
| 12 | + |
| 13 | +func TestDealFastRetrieval(t *testing.T) { |
| 14 | + req := require.New(t) |
| 15 | + ctx := context.Background() |
| 16 | + |
| 17 | + sqldb := db.CreateTestTmpDB(t) |
| 18 | + req.NoError(db.CreateAllBoostTables(ctx, sqldb, sqldb)) |
| 19 | + |
| 20 | + // Run migrations up to the one that adds the FastRetrieval field to Deals |
| 21 | + goose.SetBaseFS(migrations.EmbedMigrations) |
| 22 | + req.NoError(goose.SetDialect("sqlite3")) |
| 23 | + req.NoError(goose.UpTo(sqldb, ".", 20221124191002)) |
| 24 | + |
| 25 | + // Generate 2 deals |
| 26 | + dealsDB := db.NewDealsDB(sqldb) |
| 27 | + deals, err := db.GenerateNDeals(1) |
| 28 | + req.NoError(err) |
| 29 | + |
| 30 | + // Insert the deals in DB |
| 31 | + err = dealsDB.Insert(ctx, &deals[0]) |
| 32 | + require.NoError(t, err) |
| 33 | + |
| 34 | + // Get deal state |
| 35 | + dealState, err := dealsDB.ByID(ctx, deals[0].DealUuid) |
| 36 | + require.NoError(t, err) |
| 37 | + require.False(t, dealState.FastRetrieval) |
| 38 | + |
| 39 | + //Run migration |
| 40 | + req.NoError(goose.UpByOne(sqldb, ".")) |
| 41 | + |
| 42 | + // Check the deal state again |
| 43 | + dealState, err = dealsDB.ByID(ctx, deals[0].DealUuid) |
| 44 | + require.NoError(t, err) |
| 45 | + require.True(t, dealState.FastRetrieval) |
| 46 | +} |
0 commit comments