github.com/jduhamel/gcli@v0.2.4-0.20151019142748-0d5307cd7e21/tests/design_flow_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "strconv" 8 "strings" 9 "testing" 10 "time" 11 12 "github.com/tcnksm/gcli/skeleton" 13 ) 14 15 func TestDesignFlow(t *testing.T) { 16 // Test generating design file, validate it and generate 17 // cli project from it (Testing all work flow). 18 // let's create git interface. 19 20 artifactBin := "mygit" 21 22 owner := "awesome_user_" + strconv.Itoa(int(time.Now().Unix())) 23 cleanFunc, err := chdirSrcPath(owner) 24 if err != nil { 25 t.Fatal(err) 26 } 27 defer cleanFunc() 28 29 // Create design File 30 designFile := fmt.Sprintf("%s-design-test.toml", artifactBin) 31 designArgs := []string{ 32 "design", 33 "-owner", owner, 34 "-framework", "mitchellh_cli", 35 "-command=add:'Add file contents to the index'", 36 "-command=commit:'Record changes to the repository'", 37 "-command=push:'Update remote refs along with associated objects'", 38 "-command=pull-request:'Open a pull request on GitHub'", 39 "-output", designFile, 40 artifactBin, 41 } 42 43 if _, err := runGcli(designArgs); err != nil { 44 t.Fatal(err) 45 } 46 47 // Check design file is exist or not 48 if _, err := os.Stat(designFile); os.IsNotExist(err) { 49 t.Fatal(err) 50 } 51 52 // Validate design File 53 validateArgs := []string{ 54 "validate", 55 designFile, 56 } 57 58 if _, err := runGcli(validateArgs); err != nil { 59 t.Fatal(err) 60 } 61 62 // Apply to genearte cli project 63 applyArgs := []string{ 64 "apply", 65 "-current", 66 designFile, 67 } 68 69 output, err := runGcli(applyArgs) 70 if err != nil { 71 t.Fatal(err) 72 } 73 74 expect := "Successfully generated" 75 if !strings.Contains(output, expect) { 76 t.Fatalf("Expect %q to contain %q", output, expect) 77 } 78 79 // Check common files are generated 80 for _, tmpl := range skeleton.CommonTemplates { 81 // NOTE: OutputPathTmpl of common template is same as final output name 82 // and not changed by templating 83 if _, err := os.Stat(filepath.Join(artifactBin, tmpl.OutputPathTmpl)); os.IsNotExist(err) { 84 t.Fatalf("file is not exist: %s", tmpl.OutputPathTmpl) 85 } 86 } 87 88 if err := goTests(artifactBin); err != nil { 89 t.Fatalf("Failed to run go tests in %s: %s", artifactBin, err) 90 } 91 }