63 lines
2.0 KiB
Go
63 lines
2.0 KiB
Go
package app
|
|
|
|
import "testing"
|
|
|
|
func TestSplitOwnerRepo(t *testing.T) {
|
|
owner, repo, err := splitOwnerRepo("Alice/Demo")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if owner != "alice" || repo != "demo" {
|
|
t.Fatalf("unexpected split: %s/%s", owner, repo)
|
|
}
|
|
if _, _, err := splitOwnerRepo("bad"); err == nil {
|
|
t.Fatal("expected invalid repo ref to fail")
|
|
}
|
|
}
|
|
|
|
func TestSplitRepoBranch(t *testing.T) {
|
|
owner, repo, branch, err := splitRepoBranch("Alice/Demo:feature/x")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if owner != "alice" || repo != "demo" || branch != "feature/x" {
|
|
t.Fatalf("unexpected split: %s/%s:%s", owner, repo, branch)
|
|
}
|
|
if _, _, _, err := splitRepoBranch("alice/demo"); err == nil {
|
|
t.Fatal("expected missing branch to fail")
|
|
}
|
|
}
|
|
|
|
func TestParseRepoCreateArgs(t *testing.T) {
|
|
name, visibility, description, jsonOut, err := parseRepoCreateArgs([]string{"demo", "--public", "--description", "hello", "--json"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if name != "demo" || visibility != "public" || description != "hello" || !jsonOut {
|
|
t.Fatalf("unexpected parse result: %q %q %q %v", name, visibility, description, jsonOut)
|
|
}
|
|
if _, _, _, _, err := parseRepoCreateArgs([]string{"demo"}); err == nil {
|
|
t.Fatal("expected missing visibility to fail")
|
|
}
|
|
}
|
|
|
|
func TestParseRepoPublishArgs(t *testing.T) {
|
|
name, visibility, description, remote, branch, err := parseRepoPublishArgs([]string{"demo", "--private", "--description=hello", "--remote", "upstream", "--branch", "trunk"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if name != "demo" || visibility != "private" || description != "hello" || remote != "upstream" || branch != "trunk" {
|
|
t.Fatalf("unexpected parse result: %q %q %q %q %q", name, visibility, description, remote, branch)
|
|
}
|
|
}
|
|
|
|
func TestRemoveBoolFlag(t *testing.T) {
|
|
args := []string{"repo", "--json", "extra"}
|
|
if !removeBoolFlag(&args, "--json") {
|
|
t.Fatal("expected flag to be removed")
|
|
}
|
|
if len(args) != 2 || args[0] != "repo" || args[1] != "extra" {
|
|
t.Fatalf("unexpected args: %#v", args)
|
|
}
|
|
}
|