Skip to content

Commit

Permalink
Add initial tests (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelicianoTech committed Aug 12, 2023
1 parent de12f84 commit cb42be3
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions arc/cmd/clone_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cmd

import (
"bytes"
"os"
"strings"
"testing"
)

func TestCloneBadInput(t *testing.T) {

expected := "Error: is not a valid hostname."

output := new(bytes.Buffer)
rootCmd.SetOut(output)
rootCmd.SetErr(output)

rootCmd.SetArgs([]string{"clone", "chicken"})

rootCmd.Execute()

if !strings.HasPrefix(output.String(), expected) {
t.Errorf("`arc clone` with bad input should start with `%s`, result: `%s`", expected, output)
}
}

func TestClonePass(t *testing.T) {

// This test will modify the local filesystem. Thus, only runs in an CI
// environment by default.
if os.Getenv("CI") != "true" {
t.Skip("skipping. Set envar CI=true to run.")
}

output := new(bytes.Buffer)
rootCmd.SetOut(output)
rootCmd.SetErr(output)

rootCmd.SetArgs([]string{"clone", "https://github.com/hubci/arc.git"})

rootCmd.Execute()

// check to see if repo was cloned
if _, err := os.Stat("/home/circleci/Repos/hubci/arc/.git"); os.IsNotExist(err) {
t.Error("`arc clone` failed to clone the arc repository.")
}
}

0 comments on commit cb42be3

Please sign in to comment.