github.com/secman-team/gh-api@v1.8.2/pkg/cmd/repo/create/http_test.go (about) 1 package create 2 3 import ( 4 "testing" 5 6 "github.com/secman-team/gh-api/api" 7 "github.com/secman-team/gh-api/pkg/httpmock" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func Test_RepoCreate(t *testing.T) { 12 reg := &httpmock.Registry{} 13 httpClient := api.NewHTTPClient(api.ReplaceTripper(reg)) 14 15 reg.Register( 16 httpmock.GraphQL(`mutation RepositoryCreate\b`), 17 httpmock.GraphQLMutation(`{}`, 18 func(inputs map[string]interface{}) { 19 assert.Equal(t, inputs["description"], "roasted chestnuts") 20 assert.Equal(t, inputs["homepageUrl"], "http://example.com") 21 }), 22 ) 23 24 input := repoCreateInput{ 25 Description: "roasted chestnuts", 26 HomepageURL: "http://example.com", 27 } 28 29 _, err := repoCreate(httpClient, "github.com", input, "") 30 if err != nil { 31 t.Fatalf("unexpected error: %v", err) 32 } 33 34 if len(reg.Requests) != 1 { 35 t.Fatalf("expected 1 HTTP request, seen %d", len(reg.Requests)) 36 } 37 }