Get that test mostly working

This commit is contained in:
Chris Westra 2022-09-08 17:17:06 -04:00
parent 5734df806b
commit 2e98e8a4a7
2 changed files with 43 additions and 10 deletions

View file

@ -21,6 +21,9 @@ func CreateBranchIssueReference(client *Client, repo *Repository, params map[str
}) {
linkedBranch {
id
ref {
name
}
}
}
}
@ -38,17 +41,25 @@ func CreateBranchIssueReference(client *Client, repo *Repository, params map[str
result := struct {
createLinkedBranch struct {
BranchIssueReference BranchIssueReference
LinkedBranch struct {
ID int
Ref struct {
Name string
}
}
}
}{}
fmt.Printf("query variables %#v", inputParams)
err := client.GraphQL(repo.RepoHost(), query, inputParams, &result)
if err != nil {
return nil, err
}
ref := &result.createLinkedBranch.BranchIssueReference
return ref, nil
fmt.Printf("result %#v", &result)
ref := BranchIssueReference{
ID: result.createLinkedBranch.LinkedBranch.ID,
BranchName: result.createLinkedBranch.LinkedBranch.Ref.Name,
}
return &ref, nil
}

View file

@ -8,7 +8,9 @@ import (
"github.com/cli/cli/v2/internal/ghrepo"
"github.com/cli/cli/v2/internal/run"
"github.com/cli/cli/v2/pkg/httpmock"
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/cli/cli/v2/pkg/prompt"
"github.com/cli/cli/v2/test"
"github.com/stretchr/testify/assert"
)
@ -34,25 +36,32 @@ func Test_developRun(t *testing.T) {
},
httpStubs: func(reg *httpmock.Registry, t *testing.T) {
reg.StubRepoResponse("OWNER", "REPO")
reg.Register(
httpmock.GraphQL(`query RepositoryInfo\b`),
httpmock.StringResponse(`
{ "data": { "repository": {
"id": "REPOID",
"hasIssuesEnabled": true
} } }`),
)
reg.Register(
httpmock.GraphQL(`query IssueByNumber\b`),
httpmock.StringResponse(`{"data":{"repository":{
"hasIssuesEnabled": true,
"issue":{"id":1, "number":123, "title":"my issue"},
}}}`))
httpmock.StringResponse(`{"data":{"repository":{ "hasIssuesEnabled": true, "issue":{"id": "yar", "number":123, "title":"my issue"} }}}`))
reg.Register(
httpmock.GraphQL(`query BranchIssueReferenceFindBaseOid\b`),
httpmock.StringResponse(`{"data":{"repository":{"ref":{"target":{"oid":"123"}}}}}`))
reg.Register(
httpmock.GraphQL(`mutation CreateLinkedBranch\b`),
httpmock.GraphQLMutation(`
{ "data": { "createLinkedBranch": { "linkedBranch": 1 } } }`,
httpmock.GraphQLMutation(`{ "data": { "createLinkedBranch": { "linkedBranch": {"id": 2, "ref": {"name": "my-branch"} } } } }`,
func(inputs map[string]interface{}) {
}),
)
},
expectedOut: "Created my-branch\n",
},
}
for _, tt := range tests {
@ -65,6 +74,13 @@ func Test_developRun(t *testing.T) {
opts := DevelopOptions{}
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(tt.tty)
ios.SetStdinTTY(tt.tty)
ios.SetStderrTTY(tt.tty)
opts.IO = ios
opts.BaseRepo = func() (ghrepo.Interface, error) {
return ghrepo.New("OWNER", "REPO"), nil
}
@ -81,10 +97,16 @@ func Test_developRun(t *testing.T) {
defer cleanSetup()
err := developRun(&opts)
output := &test.CmdOut{
OutBuf: stdout,
ErrBuf: stderr,
}
if tt.wantErr != "" {
assert.EqualError(t, err, tt.wantErr)
} else {
assert.NoError(t, err)
assert.Equal(t, tt.expectedOut, output.String())
assert.Equal(t, tt.expectedErrOut, output.Stderr())
}
})
}