From bc346a69c43961e1478ed3acfd80c24d566394bf Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Mon, 1 Jan 2024 20:23:56 -0500 Subject: Add migration tests --- internal/models/migration_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 internal/models/migration_test.go (limited to 'internal/models/migration_test.go') diff --git a/internal/models/migration_test.go b/internal/models/migration_test.go new file mode 100644 index 0000000..5df6dc8 --- /dev/null +++ b/internal/models/migration_test.go @@ -0,0 +1,37 @@ +package models + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +type FakeClock struct{} + +func (c *FakeClock) Now() time.Time { + return time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC) +} + +func TestNewMigration(t *testing.T) { + m := NewMigration(&FakeClock{}, " test MESSAGE ") + + assert.Equal(t, "20200101000000", m.Version) + assert.Equal(t, " test MESSAGE ", m.Message) + assert.Equal(t, false, m.Applied) + assert.Equal(t, "20200101000000_test_message", m.Dirname()) + assert.Equal(t, "20200101000000 - test_message - [ ]", m.String()) +} + +func TestAppliedNewMigration(t *testing.T) { + m := NewMigration(&FakeClock{}, "test message") + m.Applied = true + + assert.Equal(t, "20200101000000 - test_message - [x]", m.String()) +} + +func TestEmptyMessageMigration(t *testing.T) { + m := NewMigration(&FakeClock{}, "") + + assert.Equal(t, "20200101000000 - [ ]", m.String()) +} -- cgit v1.2.3