Skip to content

Commit

Permalink
Fix TestRun
Browse files Browse the repository at this point in the history
  • Loading branch information
178inaba committed Aug 24, 2017
1 parent 1ea7b35 commit 5a59f59
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions main_test.go
Expand Up @@ -23,19 +23,26 @@ import (

func TestRun(t *testing.T) {
tests := []struct {
is2Args bool
isAuthError, isCreateGistErr bool
createGistStatusCode int
removeError, runCmdError error
exitCode int
}{
{isAuthError: true, exitCode: 1},
{isCreateGistErr: true, createGistStatusCode: http.StatusUnauthorized, removeError: nil},
{isCreateGistErr: true, createGistStatusCode: http.StatusUnauthorized, removeError: errors.New("should be error"), exitCode: 1},
{isCreateGistErr: true, createGistStatusCode: http.StatusInternalServerError, removeError: nil, exitCode: 1},
{isCreateGistErr: true, createGistStatusCode: http.StatusUnauthorized, removeError: nil},
{is2Args: true, isAuthError: true, exitCode: 1},
{isCreateGistErr: true,
createGistStatusCode: http.StatusUnauthorized, removeError: nil},
{isCreateGistErr: true,
createGistStatusCode: http.StatusUnauthorized, removeError: errors.New("should be error"), exitCode: 1},
{isCreateGistErr: true,
createGistStatusCode: http.StatusInternalServerError, removeError: nil, exitCode: 1},
{isCreateGistErr: true,
createGistStatusCode: http.StatusUnauthorized, removeError: nil},
{runCmdError: errors.New("should be error")},
}

defer func(old []string) { os.Args = old }(os.Args)

tmpReadUsername := readUsername
tmpReadPassword := readPassword
tmpRunCmd := runCmd
Expand Down Expand Up @@ -66,10 +73,12 @@ func TestRun(t *testing.T) {
}
}))
defer ts.Close()

*apiRawurl = ts.URL + "/"
defer func(old []string) { os.Args = old }(os.Args)
os.Args = []string{"gistup", "README.md"}

os.Args = []string{"gistup"}
if test.is2Args {
os.Args = append(os.Args, "README.md")
}
flag.Parse()

runCmd = func(c *exec.Cmd) error { return test.runCmdError }
Expand Down

0 comments on commit 5a59f59

Please sign in to comment.