diff --git a/.circleci/config.yml b/.circleci/config.yml index 5c834bf84..b4d5ae22b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -212,7 +212,7 @@ jobs: - run: name: Running Functional tests for team command: | - go test -v (go list ./functional/team/... | grep -v vendor/) + go test -v -count=1 -p 1 (go list ./functional/team/... | grep -v vendor/) windows_functional_test_single: executor: windows-executor @@ -233,7 +233,7 @@ jobs: - run: name: Running Functional tests for single command: | - go test -v (go list ./functional/single/... | grep -v vendor/) + go test -v -count=1 -p 1 (go list ./functional/single/... | grep -v vendor/) build: diff --git a/Makefile b/Makefile index 8624dc95c..6d2646cc5 100644 --- a/Makefile +++ b/Makefile @@ -111,11 +111,11 @@ unit-test: functional-test-single: mkdir -p $(BIN) - $(GOTEST) -v `go list ./functional/single/... | grep -v vendor/` + $(GOTEST) -v -count=1 -p 1 `go list ./functional/single/... | grep -v vendor/` functional-test-team: mkdir -p $(BIN) - $(GOTEST) -v `go list ./functional/team/... | grep -v vendor/` + $(GOTEST) -v -count=1 -p 1 `go list ./functional/team/... | grep -v vendor/` rebase-nightly: git config --global user.email "$(GIT_EMAIL)" diff --git a/functional/runner.go b/functional/runner.go index 89ef6f524..a5b9dd166 100644 --- a/functional/runner.go +++ b/functional/runner.go @@ -44,7 +44,7 @@ func (scenario *Scenario) RunSteps() (string, error) { } func (scenario *Scenario) RunStdin() (string, error) { - fmt.Println("Running: " + scenario.Entry) + fmt.Println("Running STDIN: " + scenario.Entry) os := runtime.GOOS if os == "windows" { b2, err := scenario.runStdinForWindows() @@ -66,6 +66,16 @@ func RitInit() { fmt.Println("Setup Done..") } +func RitClearConfigs() { + os := runtime.GOOS + if os == "windows" { + setUpClearSetupWindows() + } else { + setUpClearSetupUnix() + } + fmt.Println("Setup Done..") +} + func LoadScenarios(file string) []Scenario { jsonFile, err := os.Open(file) if err != nil { @@ -90,3 +100,4 @@ func scannerTerminal(out io.Reader) *bufio.Scanner { scanner.Split(bufio.ScanLines) return scanner } + diff --git a/functional/runner_unix.go b/functional/runner_unix.go index cd2320006..c1882421b 100644 --- a/functional/runner_unix.go +++ b/functional/runner_unix.go @@ -5,7 +5,10 @@ import ( "fmt" "io" "log" + "os" "os/exec" + "os/user" + "path/filepath" "strings" "time" @@ -30,6 +33,8 @@ func (scenario *Scenario) runStdinForUnix() (bytes.Buffer, error) { if errorEcho != nil { log.Printf("Error while running: %q", errorEcho) } + var stderr bytes.Buffer + commandRit.Stderr = &stderr errorRit := commandRit.Start() if errorRit != nil { @@ -46,6 +51,7 @@ func (scenario *Scenario) runStdinForUnix() (bytes.Buffer, error) { errorRit = commandRit.Wait() if errorRit != nil { log.Printf("Error while running: %q", errorRit) + b2 = stderr } fmt.Println(&b2) @@ -76,6 +82,29 @@ func setUpRitUnix() { } } +func setUpClearSetupUnix() { + fmt.Println("Running Clear for Unix..") + myPath := "/.rit/" + usr, _ := user.Current() + dir := usr.HomeDir + myPath + + d, err := os.Open(dir) + if err != nil { + log.Printf("Error Open dir: %q", err) + } + defer d.Close() + names, err := d.Readdirnames(-1) + if err != nil { + log.Printf("Error Readdirnames: %q", err) + } + for _, name := range names { + err := os.RemoveAll(filepath.Join(dir, name)) + if err != nil { + log.Printf("Error cleaning repo rit: %q", err) + } + } +} + func (scenario *Scenario) runStepsForUnix() (error, string) { args := strings.Fields(scenario.Steps[0].Value) cmd, stdin, out, err := execRit(args) diff --git a/functional/runner_win.go b/functional/runner_win.go index 63137f3b6..b0b7061ae 100644 --- a/functional/runner_win.go +++ b/functional/runner_win.go @@ -5,7 +5,10 @@ import ( "fmt" "io" "log" + "os" "os/exec" + "os/user" + "path/filepath" "strings" ) @@ -17,6 +20,9 @@ func (scenario *Scenario) runStdinForWindows() (bytes.Buffer, error) { _, pipeWriter := io.Pipe() cmd.Stdout = pipeWriter + var stderr bytes.Buffer + cmd.Stderr = &stderr + var b2 bytes.Buffer cmd.Stdout = &b2 @@ -28,6 +34,7 @@ func (scenario *Scenario) runStdinForWindows() (bytes.Buffer, error) { err = cmd.Wait() if err != nil { log.Printf("Error while running: %q", err) + b2 = stderr } pipeWriter.Close() @@ -48,3 +55,26 @@ func setUpRitWin() { } fmt.Printf("%s\n", stdoutStderr) } + +func setUpClearSetupWindows() { + fmt.Println("Running Clear for Windows..") + myPath := "\\.rit\\" + usr, _ := user.Current() + dir := usr.HomeDir + myPath + + d, err := os.Open(dir) + if err != nil { + log.Printf("Error Open dir: %q", err) + } + defer d.Close() + names, err := d.Readdirnames(-1) + if err != nil { + log.Printf("Error Readdirnames: %q", err) + } + for _, name := range names { + err := os.RemoveAll(filepath.Join(dir, name)) + if err != nil { + log.Printf("Error cleaning repo rit: %q", err) + } + } +} diff --git a/functional/single/core_feature.json b/functional/single/core/core_feature.json similarity index 100% rename from functional/single/core_feature.json rename to functional/single/core/core_feature.json diff --git a/functional/single/core_integration_test.go b/functional/single/core/core_integration_test.go similarity index 86% rename from functional/single/core_integration_test.go rename to functional/single/core/core_integration_test.go index 478081b04..728a59fb9 100644 --- a/functional/single/core_integration_test.go +++ b/functional/single/core/core_integration_test.go @@ -1,6 +1,8 @@ -package single +package core import ( + "testing" + . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" @@ -8,7 +10,16 @@ import ( "github.com/ZupIT/ritchie-cli/functional" ) +func TestRitSingleCore(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Rit Suite Core") +} + var _ = Describe("RitCore", func() { + BeforeSuite(func() { + functional.RitInit() + }) + scenariosCore := functional.LoadScenarios("core_feature.json") DescribeTable("When running core command", diff --git a/functional/single/init/init_feature.json b/functional/single/init/init_feature.json new file mode 100644 index 000000000..8a5bdf084 --- /dev/null +++ b/functional/single/init/init_feature.json @@ -0,0 +1,152 @@ +[ + { + "entry":"Show context", + "steps":[ + { + "key":"", + "value":"show context", + "action":"main" + } + ], + "result":"To start using rit, you need to initialize rit first." + }, + { + "entry":"Set context", + "steps":[ + { + "key":"", + "value":"set context", + "action":"main" + } + ], + "result":"To start using rit, you need to initialize rit first." + }, + { + "entry":"Delete context", + "steps":[ + { + "key":"", + "value":"delete context", + "action":"main" + } + + ], + "result":"To start using rit, you need to initialize rit first." + }, + { + "entry":"Add new repo", + "steps":[ + { + "key":"", + "value":"add repo", + "action":"main" + } + ], + "result":"To start using rit, you need to initialize rit first." + }, + { + "entry":"Clean repo", + "steps":[ + { + "key":"", + "value":"clean repo", + "action":"main" + } + ], + "result":"To start using rit, you need to initialize rit first." + }, + { + "entry":"List repo", + "steps":[ + { + "key":"", + "value":"list repo", + "action":"main" + } + ], + "result":"To start using rit, you need to initialize rit first." + }, + { + "entry":"Delete repo", + "steps":[ + { + "key":"", + "value":"delete repo", + "action":"main" + } + ], + "result":"To start using rit, you need to initialize rit first." + }, + { + "entry":"Set credentials", + "steps":[ + { + "key":"", + "value":"set credential", + "action":"main" + } + ], + "result":"To start using rit, you need to initialize rit first." + }, + { + "entry":"Update repo", + "steps":[ + { + "key":"", + "value":"update repo", + "action":"main" + } + ], + "result":"To start using rit, you need to initialize rit first." + }, + { + "entry":"Do INIT", + "steps":[ + { + "key":"", + "value":"init", + "action":"main" + }, + { + "key":"Define a passphrase for your machine:", + "value":"12345", + "action":"sendkey" + } + ], + "result":"" + }, + { + "entry":"Set Login STDIN", + "steps":[ + { + "key":"", + "value":"{\"passphrase\":\"12345\"}", + "action":"echo" + }, + { + "key":"", + "value":"init --stdin", + "action":"main" + } + + ], + "result":"" + }, + { + "entry":"Set Login STDIN without passphrase", + "steps":[ + { + "key":"", + "value":"{\"name\":\"12345\"}", + "action":"echo" + }, + { + "key":"", + "value":"init --stdin", + "action":"main" + } + + ], + "result":"Error: passphrase is required" + } +] \ No newline at end of file diff --git a/functional/single/init/init_integration_test.go b/functional/single/init/init_integration_test.go new file mode 100644 index 000000000..4ef57a7d3 --- /dev/null +++ b/functional/single/init/init_integration_test.go @@ -0,0 +1,86 @@ +package init + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/extensions/table" + . "github.com/onsi/gomega" + "github.com/onsi/gomega/gexec" + + "github.com/ZupIT/ritchie-cli/functional" +) + +func TestRitSingleInit(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Rit Suite Init") +} + +var _ = Describe("RitInit", func() { + BeforeEach(func() { + functional.RitClearConfigs() + }) + + scenariosCore := functional.LoadScenarios("init_feature.json") + + DescribeTable("When running command without init", + func(scenario functional.Scenario) { + out, err := scenario.RunSteps() + Expect(err).To(Succeed()) + Expect(out).To(ContainSubstring(scenario.Result)) + }, + + Entry("Show context", scenariosCore[0]), + Entry("Set context", scenariosCore[1]), + Entry("Delete context", scenariosCore[2]), + Entry("Add new repo", scenariosCore[3]), + Entry("Clean repo", scenariosCore[4]), + Entry("List repo", scenariosCore[5]), + Entry("Delete repo", scenariosCore[6]), + Entry("Set Credential", scenariosCore[7]), + Entry("Update repo", scenariosCore[8]), + + Entry("Do init", scenariosCore[9]), + ) + +}) + +var _ = Describe("RitInit", func() { + BeforeEach(func() { + functional.RitClearConfigs() + }) + + scenariosCore := functional.LoadScenarios("init_feature.json") + + DescribeTable("When STDIN for init", + func(scenario functional.Scenario) { + out, err := scenario.RunStdin() + Expect(err).To(Succeed()) + Expect(out).To(ContainSubstring(scenario.Result)) + }, + + Entry("Set Init STDIN", scenariosCore[10]), + + ) + +}) + +var _ = Describe("RitInit STDIN Invalid", func() { + BeforeEach(func() { + functional.RitClearConfigs() + }) + + scenariosCore := functional.LoadScenarios("init_feature.json") + + DescribeTable("When STDIN for init is invalid", + func(scenario functional.Scenario) { + out, err := scenario.RunStdin() + Expect(err).Should(gexec.Exit(1)) + Expect(out).To(ContainSubstring(scenario.Result)) + }, + + Entry("Set Init STDIN without passphrase", scenariosCore[11]), + + ) + +}) diff --git a/functional/single/runner_integration_test.go b/functional/single/runner_integration_test.go deleted file mode 100644 index 473aa36ea..000000000 --- a/functional/single/runner_integration_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package single - -import ( - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "github.com/ZupIT/ritchie-cli/functional" -) - -func TestRitSingle(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Rit Suite") -} - -var _ = Describe("RitScaffold", func() { - BeforeSuite(func() { - functional.RitInit() - }) -}) diff --git a/functional/single/scaffold_feature.json b/functional/single/scaffold/scaffold_feature.json similarity index 100% rename from functional/single/scaffold_feature.json rename to functional/single/scaffold/scaffold_feature.json diff --git a/functional/single/scaffold_integration_test.go b/functional/single/scaffold/scaffold_integration_test.go similarity index 74% rename from functional/single/scaffold_integration_test.go rename to functional/single/scaffold/scaffold_integration_test.go index a38ee4921..e84537c22 100644 --- a/functional/single/scaffold_integration_test.go +++ b/functional/single/scaffold/scaffold_integration_test.go @@ -1,7 +1,9 @@ -package single +package scaffold import ( + "testing" + . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" @@ -9,7 +11,16 @@ import ( "github.com/ZupIT/ritchie-cli/functional" ) +func TestRitSingleScaffold(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Rit Suite Scaffold") +} + var _ = Describe("RitScaffold", func() { + BeforeSuite(func() { + functional.RitInit() + }) + scenariosScaffold := functional.LoadScenarios("scaffold_feature.json") DescribeTable("When running core command", diff --git a/functional/single/stdin_feature.json b/functional/single/stdin/stdin_feature.json similarity index 100% rename from functional/single/stdin_feature.json rename to functional/single/stdin/stdin_feature.json diff --git a/functional/single/stdin_integration_test.go b/functional/single/stdin/stdin_integration_test.go similarity index 81% rename from functional/single/stdin_integration_test.go rename to functional/single/stdin/stdin_integration_test.go index 7cb5cc336..4bf7c90b7 100644 --- a/functional/single/stdin_integration_test.go +++ b/functional/single/stdin/stdin_integration_test.go @@ -1,6 +1,8 @@ -package single +package stdin import ( + "testing" + . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" @@ -8,7 +10,16 @@ import ( "github.com/ZupIT/ritchie-cli/functional" ) +func TestRitSingleStdin(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Rit Suite Stdin") +} + var _ = Describe("RitStdin", func() { + BeforeSuite(func() { + functional.RitInit() + }) + scenariosStdin := functional.LoadScenarios("stdin_feature.json") DescribeTable("When running core command",