Skip to content

Commit

Permalink
Merge pull request #64 from lucapette/fix-63
Browse files Browse the repository at this point in the history
Fixes #63
  • Loading branch information
lucapette authored Sep 21, 2017
2 parents 96d8de4 + 276e5a1 commit 6d308be
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
35 changes: 33 additions & 2 deletions integration/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"testing"

Expand Down Expand Up @@ -153,7 +154,7 @@ func TestCLI(t *testing.T) {
"unknown format",
[]string{"-f=sqll", "-t=USERS", "int:42,42", "enum:foo,foo"},
"unknown-format.golden",
false,
true,
},
}

Expand All @@ -173,13 +174,43 @@ func TestCLI(t *testing.T) {
}
expected := golden.load()

if !reflect.DeepEqual(actual, expected) {
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("diff: %v", diff(expected, actual))
}
})
}
}

func TestGeneratorDescription(t *testing.T) {
tests := []struct {
name string
args []string
}{
{"simple generator", []string{"-g", "name.first"}},
{"custom generator", []string{"-g", "int"}},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := exec.Command(binaryPath, tt.args...)
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("test run returned an error: %v\n%s", err, output)
}

actual := string(output)
matched, err := regexp.MatchString("Description:", actual)
if err != nil {
t.Fatalf("could not match actual: %v", err)
}

if !matched {
t.Fatalf("expected %s to match description, but did not", actual)
}
})
}
}

func TestFileGenerator(t *testing.T) {
tests := []struct {
name string
Expand Down
14 changes: 12 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,17 @@ func main() {
if generator := generators.FindByName(*generatorFlag); generator != nil {
fmt.Printf("Description: %s\n\nExample:\n\n", generator.Desc)
for i := 0; i < 5; i++ {
fmt.Println(generator.Func())
fn := generator.Func
if generator.IsCustom() {
custom, err := generator.CustomFunc("")
if err != nil {
fmt.Printf("could not generate example: %v", err)
os.Exit(1)
}

fn = custom
}
fmt.Println(fn())
}
}
os.Exit(0)
Expand Down Expand Up @@ -162,7 +172,7 @@ func main() {
if err != nil {
fmt.Printf("%v\n\n", err)
flag.Usage()
os.Exit(0)
os.Exit(1)
}

for i := 0; i < *limitFlag; i++ {
Expand Down

0 comments on commit 6d308be

Please sign in to comment.