-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
181 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,15 @@ import ( | |
"github.com/gemfury/cli/internal/ctx" | ||
"github.com/gemfury/cli/internal/testutil" | ||
"github.com/gemfury/cli/pkg/terminal" | ||
|
||
"net/http" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// ==== YANK ==== | ||
|
||
func TestYankCommandSuccess(t *testing.T) { | ||
func TestYankCommandOnePackage(t *testing.T) { | ||
auth := terminal.TestAuther("user", "abc123", nil) | ||
term := terminal.NewForTest() | ||
|
||
|
@@ -24,6 +26,7 @@ func TestYankCommandSuccess(t *testing.T) { | |
flags := ctx.GlobalFlags(cc) | ||
flags.Endpoint = server.URL | ||
|
||
// Removing using version flag | ||
err := runCommandNoErr(cc, []string{"yank", "foo", "-v", "0.0.1"}) | ||
if err != nil { | ||
t.Fatal(err) | ||
|
@@ -33,6 +36,80 @@ func TestYankCommandSuccess(t *testing.T) { | |
if outStr := string(term.OutBytes()); !strings.HasSuffix(outStr, exp) { | ||
t.Errorf("Expected output to include %q, got %q", exp, outStr) | ||
} | ||
|
||
// Removing using PACKAGE@VERSION | ||
err = runCommandNoErr(cc, []string{"yank", "[email protected]"}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
exp = "Removed package \"foo\" version \"0.0.1\"\n" | ||
if outStr := string(term.OutBytes()); !strings.HasSuffix(outStr, exp) { | ||
t.Errorf("Expected output to include %q, got %q", exp, outStr) | ||
} | ||
|
||
// Fail if no version specified | ||
err = runCommandNoErr(cc, []string{"yank", "foo"}) | ||
if err == nil || !strings.Contains(err.Error(), "Invalid package/version") { | ||
t.Errorf("Expected invalid error, got %q", err) | ||
} | ||
} | ||
|
||
func TestYankCommandMultiPackage(t *testing.T) { | ||
auth := terminal.TestAuther("user", "abc123", nil) | ||
term := terminal.NewForTest() | ||
|
||
// Fire up test server | ||
server := testutil.APIServerCustom(t, func(mux *http.ServeMux) { | ||
mux.HandleFunc("/packages/foo/versions/0.0.1", func(w http.ResponseWriter, r *http.Request) { | ||
if method := r.Method; method != "DELETE" { | ||
t.Errorf("Invalid request: %s %s", method, r.URL.Path) | ||
} | ||
w.Write([]byte("{}")) | ||
}) | ||
mux.HandleFunc("/packages/foo/versions/0.0.2", func(w http.ResponseWriter, r *http.Request) { | ||
if method := r.Method; method != "DELETE" { | ||
t.Errorf("Invalid request: %s %s", method, r.URL.Path) | ||
} | ||
http.NotFound(w, r) | ||
}) | ||
}) | ||
|
||
defer server.Close() | ||
|
||
cc := cli.TestContext(term, auth) | ||
flags := ctx.GlobalFlags(cc) | ||
flags.Endpoint = server.URL | ||
|
||
// Expected successful output | ||
exp := "Removed package \"foo\" version \"0.0.1\"\n" | ||
|
||
// Failure for multiple packages without version | ||
err := runCommandNoErr(cc, []string{"yank", "foo", "bar"}) | ||
if err == nil || !strings.Contains(err.Error(), "Invalid package/version") { | ||
t.Errorf("Expected invalid error, got %q", err) | ||
} | ||
|
||
// Failure for multiple packages with version flag | ||
err = runCommandNoErr(cc, []string{"yank", "foo", "bar", "-v", "0.0.1"}) | ||
if err == nil || !strings.Contains(err.Error(), "Use PACKAGE@VERSION") { | ||
t.Errorf("Expected invalid error, got %q", err) | ||
} | ||
|
||
// Partial failure for multiple packages | ||
err = runCommandNoErr(cc, []string{"yank", "[email protected]", "[email protected]"}) | ||
if err == nil || !strings.Contains(err.Error(), "Doesn't look like this exists") { | ||
t.Errorf("Expected invalid error, got %q", err) | ||
} | ||
if outStr := string(term.OutBytes()); !strings.Contains(outStr, exp) { | ||
t.Errorf("Expected output to include %q, got %q", exp, outStr) | ||
} | ||
|
||
// Success all around (reusing the same test package URL) | ||
err = runCommandNoErr(cc, []string{"yank", "[email protected]", "[email protected]"}) | ||
if outStr := string(term.OutBytes()); !strings.HasSuffix(outStr, exp) { | ||
t.Errorf("Expected output to include %q, got %q", exp, outStr) | ||
} | ||
} | ||
|
||
func TestYankCommandUnauthorized(t *testing.T) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters