forked from pressly/goose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_test.go
49 lines (42 loc) · 1.1 KB
/
create_test.go
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
package goose
import (
"fmt"
"os"
"os/exec"
"strings"
"testing"
"time"
)
func TestSequential(t *testing.T) {
t.Parallel()
dir := t.TempDir()
defer os.Remove("./bin/create-goose") // clean up
commands := []string{
"go build -o ./bin/create-goose ./cmd/goose",
fmt.Sprintf("./bin/create-goose -s -dir=%s create create_table", dir),
fmt.Sprintf("./bin/create-goose -s -dir=%s create add_users", dir),
fmt.Sprintf("./bin/create-goose -s -dir=%s create add_indices", dir),
fmt.Sprintf("./bin/create-goose -s -dir=%s create update_users", dir),
}
for _, cmd := range commands {
args := strings.Split(cmd, " ")
time.Sleep(1 * time.Second)
cmd := exec.Command(args[0], args[1:]...)
cmd.Env = os.Environ()
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("%s:\n%v\n\n%s", err, cmd, out)
}
}
files, err := os.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
// check that the files are in order
for i, f := range files {
expected := fmt.Sprintf("%05v", i+1)
if !strings.HasPrefix(f.Name(), expected) {
t.Errorf("failed to find %s prefix in %s", expected, f.Name())
}
}
}