-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #215 from warrn/warrn/214
Option '-s' causes CREATE to use sequential versioning
- Loading branch information
Showing
4 changed files
with
104 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package goose | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestSequential(t *testing.T) { | ||
t.Parallel() | ||
|
||
dir, err := ioutil.TempDir("", "tmptest") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
defer os.RemoveAll(dir) // clean up | ||
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 := ioutil.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()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters