| 55 | } |
| 56 | |
| 57 | func Test_GistClone(t *testing.T) { |
| 58 | tests := []struct { |
| 59 | name string |
| 60 | args string |
| 61 | want string |
| 62 | }{ |
| 63 | { |
| 64 | name: "shorthand", |
| 65 | args: "GIST", |
| 66 | want: "git clone https://gist.github.com/GIST.git", |
| 67 | }, |
| 68 | { |
| 69 | name: "shorthand with directory", |
| 70 | args: "GIST target_directory", |
| 71 | want: "git clone https://gist.github.com/GIST.git target_directory", |
| 72 | }, |
| 73 | { |
| 74 | name: "clone arguments", |
| 75 | args: "GIST -- -o upstream --depth 1", |
| 76 | want: "git clone -o upstream --depth 1 https://gist.github.com/GIST.git", |
| 77 | }, |
| 78 | { |
| 79 | name: "clone arguments with directory", |
| 80 | args: "GIST target_directory -- -o upstream --depth 1", |
| 81 | want: "git clone -o upstream --depth 1 https://gist.github.com/GIST.git target_directory", |
| 82 | }, |
| 83 | { |
| 84 | name: "HTTPS URL", |
| 85 | args: "https://gist.github.com/OWNER/GIST", |
| 86 | want: "git clone https://gist.github.com/OWNER/GIST", |
| 87 | }, |
| 88 | { |
| 89 | name: "SSH URL", |
| 90 | args: "git@gist.github.com:GIST.git", |
| 91 | want: "git clone git@gist.github.com:GIST.git", |
| 92 | }, |
| 93 | } |
| 94 | for _, tt := range tests { |
| 95 | t.Run(tt.name, func(t *testing.T) { |
| 96 | reg := &httpmock.Registry{} |
| 97 | defer reg.Verify(t) |
| 98 | |
| 99 | httpClient := &http.Client{Transport: reg} |
| 100 | |
| 101 | cs, restore := run.Stub() |
| 102 | defer restore(t) |
| 103 | cs.Register(tt.want, 0, "") |
| 104 | |
| 105 | output, err := runCloneCommand(httpClient, tt.args) |
| 106 | if err != nil { |
| 107 | t.Fatalf("error running command `gist clone`: %v", err) |
| 108 | } |
| 109 | |
| 110 | assert.Equal(t, "", output.String()) |
| 111 | assert.Equal(t, "", output.Stderr()) |
| 112 | }) |
| 113 | } |
| 114 | } |