aboutsummaryrefslogtreecommitdiffstats
path: root/internal/models/migration_test.go
blob: 5df6dc844b44755c08bfe5164d92de922c6164c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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())
}