37 lines
868 B
Go
37 lines
868 B
Go
package create
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/cli/cli/api"
|
|
"github.com/cli/cli/pkg/httpmock"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_RepoCreate(t *testing.T) {
|
|
reg := &httpmock.Registry{}
|
|
httpClient := api.NewHTTPClient(api.ReplaceTripper(reg))
|
|
|
|
reg.Register(
|
|
httpmock.GraphQL(`mutation RepositoryCreate\b`),
|
|
httpmock.GraphQLMutation(`{}`,
|
|
func(inputs map[string]interface{}) {
|
|
assert.Equal(t, inputs["description"], "roasted chestnuts")
|
|
assert.Equal(t, inputs["homepageUrl"], "http://example.com")
|
|
}),
|
|
)
|
|
|
|
input := repoCreateInput{
|
|
Description: "roasted chestnuts",
|
|
HomepageURL: "http://example.com",
|
|
}
|
|
|
|
_, err := repoCreate(httpClient, "github.com", input, "")
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if len(reg.Requests) != 1 {
|
|
t.Fatalf("expected 1 HTTP request, seen %d", len(reg.Requests))
|
|
}
|
|
}
|