github.com/goonzoid/gcli@v0.2.3-0.20150926213610-155587606ea1/tests/design_flow_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strconv"
     7  	"strings"
     8  	"testing"
     9  	"time"
    10  )
    11  
    12  func TestDesignFlow(t *testing.T) {
    13  	// Test generating design file, validate it and generate
    14  	// cli project from it (Testing all work flow).
    15  	// let's create git interface.
    16  
    17  	artifactBin := "mygit"
    18  
    19  	owner := "awesome_user_" + strconv.Itoa(int(time.Now().Unix()))
    20  	cleanFunc, err := chdirSrcPath(owner)
    21  	if err != nil {
    22  		t.Fatal(err)
    23  	}
    24  	defer cleanFunc()
    25  
    26  	// Create design File
    27  	designFile := fmt.Sprintf("%s-design-test.toml", artifactBin)
    28  	designArgs := []string{
    29  		"design",
    30  		"-owner", owner,
    31  		"-framework", "mitchellh_cli",
    32  		"-command=add:'Add file contents to the index'",
    33  		"-command=commit:'Record changes to the repository'",
    34  		"-command=push:'Update remote refs along with associated objects'",
    35  		"-output", designFile,
    36  		artifactBin,
    37  	}
    38  
    39  	if _, err := runGcli(designArgs); err != nil {
    40  		t.Fatal(err)
    41  	}
    42  
    43  	// Check design file is exist or not
    44  	if _, err := os.Stat(designFile); os.IsNotExist(err) {
    45  		t.Fatal(err)
    46  	}
    47  
    48  	// Validate design File
    49  	validateArgs := []string{
    50  		"validate",
    51  		designFile,
    52  	}
    53  
    54  	if _, err := runGcli(validateArgs); err != nil {
    55  		t.Fatal(err)
    56  	}
    57  
    58  	// Apply to genearte cli project
    59  	applyArgs := []string{
    60  		"apply",
    61  		designFile,
    62  	}
    63  
    64  	output, err := runGcli(applyArgs)
    65  	if err != nil {
    66  		t.Fatal(err)
    67  	}
    68  
    69  	expect := "Successfully generated"
    70  	if !strings.Contains(output, expect) {
    71  		t.Fatalf("Expect %q to contain %q", output, expect)
    72  	}
    73  
    74  	if err := goTests(artifactBin); err != nil {
    75  		t.Fatalf("Failed to run go tests in %s: %s", artifactBin, err)
    76  	}
    77  }