-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit hacks the existing repo clone tests into something usable by the new isolated command. It went ok and was less effort than trying to introduce the same kind of test format as repo view and gist create.
- Loading branch information
Showing
9 changed files
with
461 additions
and
291 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import ( | |
"encoding/json" | ||
"io/ioutil" | ||
"os/exec" | ||
"reflect" | ||
"regexp" | ||
"strings" | ||
"testing" | ||
|
@@ -437,190 +436,6 @@ func TestRepoFork_in_parent_survey_no(t *testing.T) { | |
} | ||
} | ||
|
||
func TestParseExtraArgs(t *testing.T) { | ||
type Wanted struct { | ||
args []string | ||
dir string | ||
} | ||
tests := []struct { | ||
name string | ||
args []string | ||
want Wanted | ||
}{ | ||
{ | ||
name: "args and target", | ||
args: []string{"target_directory", "-o", "upstream", "--depth", "1"}, | ||
want: Wanted{ | ||
args: []string{"-o", "upstream", "--depth", "1"}, | ||
dir: "target_directory", | ||
}, | ||
}, | ||
{ | ||
name: "only args", | ||
args: []string{"-o", "upstream", "--depth", "1"}, | ||
want: Wanted{ | ||
args: []string{"-o", "upstream", "--depth", "1"}, | ||
dir: "", | ||
}, | ||
}, | ||
{ | ||
name: "only target", | ||
args: []string{"target_directory"}, | ||
want: Wanted{ | ||
args: []string{}, | ||
dir: "target_directory", | ||
}, | ||
}, | ||
{ | ||
name: "no args", | ||
args: []string{}, | ||
want: Wanted{ | ||
args: []string{}, | ||
dir: "", | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
args, dir := parseCloneArgs(tt.args) | ||
got := Wanted{ | ||
args: args, | ||
dir: dir, | ||
} | ||
|
||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("got %#v want %#v", got, tt.want) | ||
} | ||
}) | ||
} | ||
|
||
} | ||
|
||
func TestRepoClone(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
args string | ||
want string | ||
}{ | ||
{ | ||
name: "shorthand", | ||
args: "repo clone OWNER/REPO", | ||
want: "git clone https://github.com/OWNER/REPO.git", | ||
}, | ||
{ | ||
name: "shorthand with directory", | ||
args: "repo clone OWNER/REPO target_directory", | ||
want: "git clone https://github.com/OWNER/REPO.git target_directory", | ||
}, | ||
{ | ||
name: "clone arguments", | ||
args: "repo clone OWNER/REPO -- -o upstream --depth 1", | ||
want: "git clone -o upstream --depth 1 https://github.com/OWNER/REPO.git", | ||
}, | ||
{ | ||
name: "clone arguments with directory", | ||
args: "repo clone OWNER/REPO target_directory -- -o upstream --depth 1", | ||
want: "git clone -o upstream --depth 1 https://github.com/OWNER/REPO.git target_directory", | ||
}, | ||
{ | ||
name: "HTTPS URL", | ||
args: "repo clone https://github.com/OWNER/REPO", | ||
want: "git clone https://github.com/OWNER/REPO", | ||
}, | ||
{ | ||
name: "SSH URL", | ||
args: "repo clone [email protected]:OWNER/REPO.git", | ||
want: "git clone [email protected]:OWNER/REPO.git", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
http := initFakeHTTP() | ||
http.Register( | ||
httpmock.GraphQL(`query RepositoryFindParent\b`), | ||
httpmock.StringResponse(` | ||
{ "data": { "repository": { | ||
"parent": null | ||
} } } | ||
`)) | ||
|
||
cs, restore := test.InitCmdStubber() | ||
defer restore() | ||
|
||
cs.Stub("") // git clone | ||
|
||
output, err := RunCommand(tt.args) | ||
if err != nil { | ||
t.Fatalf("error running command `repo clone`: %v", err) | ||
} | ||
|
||
eq(t, output.String(), "") | ||
eq(t, output.Stderr(), "") | ||
eq(t, cs.Count, 1) | ||
eq(t, strings.Join(cs.Calls[0].Args, " "), tt.want) | ||
}) | ||
} | ||
} | ||
|
||
func TestRepoClone_hasParent(t *testing.T) { | ||
http := initFakeHTTP() | ||
http.Register( | ||
httpmock.GraphQL(`query RepositoryFindParent\b`), | ||
httpmock.StringResponse(` | ||
{ "data": { "repository": { | ||
"parent": { | ||
"owner": {"login": "hubot"}, | ||
"name": "ORIG" | ||
} | ||
} } } | ||
`)) | ||
|
||
cs, restore := test.InitCmdStubber() | ||
defer restore() | ||
|
||
cs.Stub("") // git clone | ||
cs.Stub("") // git remote add | ||
|
||
_, err := RunCommand("repo clone OWNER/REPO") | ||
if err != nil { | ||
t.Fatalf("error running command `repo clone`: %v", err) | ||
} | ||
|
||
eq(t, cs.Count, 2) | ||
eq(t, strings.Join(cs.Calls[1].Args, " "), "git -C REPO remote add -f upstream https://github.com/hubot/ORIG.git") | ||
} | ||
|
||
func TestRepo_withoutUsername(t *testing.T) { | ||
http := initFakeHTTP() | ||
http.Register( | ||
httpmock.GraphQL(`query UserCurrent\b`), | ||
httpmock.StringResponse(` | ||
{ "data": { "viewer": { | ||
"login": "OWNER" | ||
}}}`)) | ||
http.Register( | ||
httpmock.GraphQL(`query RepositoryFindParent\b`), | ||
httpmock.StringResponse(` | ||
{ "data": { "repository": { | ||
"parent": null | ||
} } }`)) | ||
|
||
cs, restore := test.InitCmdStubber() | ||
defer restore() | ||
|
||
cs.Stub("") // git clone | ||
|
||
output, err := RunCommand("repo clone REPO") | ||
if err != nil { | ||
t.Fatalf("error running command `repo clone`: %v", err) | ||
} | ||
|
||
eq(t, output.String(), "") | ||
eq(t, output.Stderr(), "") | ||
eq(t, cs.Count, 1) | ||
eq(t, strings.Join(cs.Calls[0].Args, " "), "git clone https://github.com/OWNER/REPO.git") | ||
} | ||
|
||
func TestRepoCreate(t *testing.T) { | ||
ctx := context.NewBlank() | ||
ctx.SetBranch("master") | ||
|
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
Oops, something went wrong.