func run(t testing.TB, commands []Command) { e := empiretest.NewEmpire(t) s := empiretest.NewServer(t, e) defer s.Close() token, err := e.AccessTokensCreate(&empire.AccessToken{ User: &empire.User{Name: "fake", GitHubToken: "token"}, }) if err != nil { t.Fatal(err) } for _, cmd := range commands { got := cli(t, token.Token, s.URL, cmd.Command) want := cmd.Output if want != "" { want = want + "\n" } if got != want { t.Fatalf("%q != %q", got, want) } } }
func TestLogin(t *testing.T) { e := empiretest.NewEmpire(t) s := empiretest.NewServer(t, e) defer s.Close() input := "fake\nbar\n" cmd := NewCmd(s.URL, "login") cmd.Stdin = strings.NewReader(input) out, err := cmd.CombinedOutput() if err != nil { t.Fatal(err) } if got, want := string(out), "Enter email: Logged in.\n"; got != want { t.Fatalf("%q", got) } }
// NewTestClient will return a new heroku.Client that's configured to interact // with a instance of the empire HTTP server. func NewTestClient(t testing.TB) (*heroku.Client, *httptest.Server) { e := empiretest.NewEmpire(t) s := empiretest.NewServer(t, e) token, err := e.AccessTokensCreate(&empire.AccessToken{ User: &empire.User{Name: "fake", GitHubToken: "token"}, }) if err != nil { t.Fatal(err) } c := &heroku.Client{ Username: "", Password: token.Token, } c.URL = s.URL return c, s }
func TestLoginUnauthorized(t *testing.T) { e := empiretest.NewEmpire(t) s := empiretest.NewServer(t, e) defer s.Close() input := "foo\nbar\n" cmd := NewCmd(s.URL, "login") cmd.Stdin = strings.NewReader(input) out, err := cmd.CombinedOutput() if err == nil { t.Fatal("Expected an error") } if got, want := string(out), "Enter email: error: Request not authenticated, API token is missing, invalid or expired Log in with `emp login`.\n"; got != want { t.Fatalf("%q", got) } }