|
| 1 | +// +build go1.16 |
| 2 | + |
| 3 | +package migration |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "testing" |
| 8 | + "testing/fstest" |
| 9 | + |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | + "github.com/upfluence/log" |
| 13 | +) |
| 14 | + |
| 15 | +func TestFSSource(t *testing.T) { |
| 16 | + var ( |
| 17 | + ctx = context.Background() |
| 18 | + fs = fstest.MapFS{ |
| 19 | + "3_final.down.sql": &fstest.MapFile{Data: []byte("bar")}, |
| 20 | + "2_initial.up.postgres": &fstest.MapFile{Data: []byte("foo")}, |
| 21 | + "3_final.up.sql": &fstest.MapFile{Data: []byte("bar")}, |
| 22 | + } |
| 23 | + ) |
| 24 | + |
| 25 | + s, err := NewFSSource(fs, log.NewLogger(log.WithSink(sink{}))) |
| 26 | + require.NoError(t, err) |
| 27 | + |
| 28 | + m, err := s.First(ctx) |
| 29 | + require.NoError(t, err) |
| 30 | + |
| 31 | + assertMigration(t, m, fetchDriver("postgres"), 2, "foo", "") |
| 32 | + assertMigration(t, m, fetchDriver("sqlite3"), 2, "", "") |
| 33 | + |
| 34 | + _, id, _ := s.Next(ctx, 2) |
| 35 | + |
| 36 | + assert.Equal(t, uint(3), id) |
| 37 | + |
| 38 | + m, _ = s.Get(ctx, id) |
| 39 | + assertMigration(t, m, fetchDriver("postgres"), 3, "bar", "bar") |
| 40 | + |
| 41 | + ok, _, _ := s.Prev(ctx, 2) |
| 42 | + assert.False(t, ok) |
| 43 | + |
| 44 | + ok, _, err = s.Next(ctx, 3) |
| 45 | + assert.NoError(t, err) |
| 46 | + assert.False(t, ok) |
| 47 | +} |
0 commit comments