(t *testing.T)
| 187 | } |
| 188 | |
| 189 | func TestDevelopRun(t *testing.T) { |
| 190 | featureEnabledPayload := `{"data":{"LinkedBranch":{"fields":[{"name":"id"},{"name":"ref"}]}}}` |
| 191 | featureDisabledPayload := `{"data":{"LinkedBranch":null}}` |
| 192 | unsafeTargetDir := t.TempDir() |
| 193 | unsafeTarget := filepath.Join(unsafeTargetDir, "worktree-link") |
| 194 | require.NoError(t, os.Symlink(unsafeTargetDir, unsafeTarget)) |
| 195 | nonEmptyTarget := t.TempDir() |
| 196 | require.NoError(t, os.WriteFile(filepath.Join(nonEmptyTarget, "file"), []byte("x"), 0o644)) |
| 197 | |
| 198 | tests := []struct { |
| 199 | name string |
| 200 | opts *DevelopOptions |
| 201 | cmdStubs func(*run.CommandStubber) |
| 202 | runStubs func(*run.CommandStubber) |
| 203 | remotes map[string]string |
| 204 | httpStubs func(*httpmock.Registry, *testing.T) |
| 205 | expectedOut string |
| 206 | expectedErrOut string |
| 207 | wantErr string |
| 208 | wantErrContains string |
| 209 | tty bool |
| 210 | }{ |
| 211 | { |
| 212 | name: "returns an error when the feature is not supported by the API", |
| 213 | opts: &DevelopOptions{ |
| 214 | IssueNumber: 42, |
| 215 | List: true, |
| 216 | }, |
| 217 | httpStubs: func(reg *httpmock.Registry, t *testing.T) { |
| 218 | reg.Register( |
| 219 | httpmock.GraphQL(`query IssueByNumber\b`), |
| 220 | httpmock.StringResponse(`{"data":{"repository":{"hasIssuesEnabled":true,"issue":{"id":"SOMEID","number":42}}}}`), |
| 221 | ) |
| 222 | reg.Register( |
| 223 | httpmock.GraphQL(`query LinkedBranchFeature\b`), |
| 224 | httpmock.StringResponse(featureDisabledPayload), |
| 225 | ) |
| 226 | }, |
| 227 | wantErr: "the `gh issue develop` command is not currently available", |
| 228 | }, |
| 229 | { |
| 230 | name: "list branches for an issue", |
| 231 | opts: &DevelopOptions{ |
| 232 | IssueNumber: 42, |
| 233 | List: true, |
| 234 | }, |
| 235 | httpStubs: func(reg *httpmock.Registry, t *testing.T) { |
| 236 | reg.Register( |
| 237 | httpmock.GraphQL(`query IssueByNumber\b`), |
| 238 | httpmock.StringResponse(`{"data":{"repository":{"hasIssuesEnabled":true,"issue":{"id":"SOMEID","number":42}}}}`), |
| 239 | ) |
| 240 | reg.Register( |
| 241 | httpmock.GraphQL(`query LinkedBranchFeature\b`), |
| 242 | httpmock.StringResponse(featureEnabledPayload), |
| 243 | ) |
| 244 | reg.Register( |
| 245 | httpmock.GraphQL(`query ListLinkedBranches\b`), |
| 246 | httpmock.GraphQLQuery(` |
nothing calls this directly
no test coverage detected