-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype_test.go
More file actions
51 lines (41 loc) · 1.16 KB
/
type_test.go
File metadata and controls
51 lines (41 loc) · 1.16 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package gomigration
import (
"bytes"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
// helper to capture output
func captureOutput(f func()) string {
old := os.Stdout // keep backup
r, w, _ := os.Pipe()
os.Stdout = w
f() // call the function
_ = w.Close()
os.Stdout = old
var buf bytes.Buffer
_, _ = buf.ReadFrom(r)
return buf.String()
}
func TestRegisteredMigrationList_Print(t *testing.T) {
// Setup time for testing
now := time.Now()
// Create sample data
migrations := RegisteredMigrationList{
{Name: "create_orders", IsExecuted: true, ExecutedAt: &now},
{Name: "add_customer_id", IsExecuted: false, ExecutedAt: nil},
}
// Capture output of the Print() method
output := captureOutput(func() {
migrations.Print()
})
// Assertions
assert.Contains(t, output, "Migration Name")
assert.Contains(t, output, "Is Executed")
assert.Contains(t, output, "Executed At")
assert.Contains(t, output, "create_orders")
assert.Contains(t, output, now.Format(time.RFC3339)) // Check formatted time
assert.Contains(t, output, "add_customer_id")
assert.Contains(t, output, "N/A") // Check for non-executed migration's "Executed At" field
}