Loading .devcontainer/devcontainer.json +3 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,9 @@ // Features add additional features to your environment. See https://containers.dev/features "features": { "ghcr.io/devcontainers/features/docker-in-docker:2": {}, "ghcr.io/devcontainers/features/docker-in-docker:2": { "moby": false }, "ghcr.io/devcontainers-extra/features/mise:1": {}, "ghcr.io/devcontainers/features/go:1": { "version": "1.25" Loading gitlab_test.go +9 −1 Original line number Diff line number Diff line Loading @@ -57,6 +57,14 @@ var ( // configured to talk to that test server. Tests should register handlers on // mux which provide mock responses for the API method being tested. func setup(t *testing.T) (*http.ServeMux, *Client) { // Setup on subpath, but pass in an empty subpath. return setupOnSubpath(t, "") } // setupOnSubpath sets up a test HTTP server along with a gitlab.Client that is // configured to talk to that test server, but it sets up the client to use a baseURL // configured on a subpath instead of the root of the domain. func setupOnSubpath(t *testing.T, path string) (*http.ServeMux, *Client) { // mux is the HTTP request multiplexer used with the test server. mux := http.NewServeMux() Loading @@ -66,7 +74,7 @@ func setup(t *testing.T) (*http.ServeMux, *Client) { // client is the GitLab client being tested. client, err := NewClient("", WithBaseURL(server.URL), WithBaseURL(server.URL+path), // Disable backoff to speed up tests that expect errors. WithCustomBackoff(func(_, _ time.Duration, _ int, _ *http.Response) time.Duration { return 0 Loading graphql.go +2 −1 Original line number Diff line number Diff line Loading @@ -84,8 +84,9 @@ func (g *GraphQL) Do(query GraphQLQuery, response any, options ...RequestOptionF if err != nil { return nil, fmt.Errorf("failed to create GraphQL request: %w", err) } // Overwrite the path of the existing request, as otherwise client-go appends /api/v4 instead. request.URL.Path = GraphQLAPIEndpoint request.URL.Path = strings.Replace(request.URL.Path, "/"+apiVersionPath, GraphQLAPIEndpoint, 1) resp, err := g.client.Do(request, response) if err != nil { // return error, details can be read from Response Loading graphql_test.go +34 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,40 @@ func TestGraphQL_Do_Success(t *testing.T) { assert.Equal(t, "any-id", response.Data.Project.ID) } func TestGraphQL_Do_Success_With_Subpath(t *testing.T) { t.Parallel() // GIVEN mux, client := setupOnSubpath(t, "/subpath") mux.HandleFunc("/subpath/api/graphql", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, http.MethodPost) testJSONBody(t, r, `{ "query": "query { project(fullPath: \"gitlab-org/gitlab\") { id } }" }`) fmt.Fprint(w, ` { "data": { "project": { "id": "any-id" } } } `) }) // WHEN var response struct { Data struct { Project struct { ID string `json:"id"` } `json:"project"` } `json:"data"` } _, err := client.GraphQL.Do(GraphQLQuery{Query: `query { project(fullPath: "gitlab-org/gitlab") { id } }`}, &response) // THEN require.NoError(t, err) assert.Equal(t, "any-id", response.Data.Project.ID) } func TestGraphQL_Do_Success_With_Variables(t *testing.T) { t.Parallel() Loading Loading
.devcontainer/devcontainer.json +3 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,9 @@ // Features add additional features to your environment. See https://containers.dev/features "features": { "ghcr.io/devcontainers/features/docker-in-docker:2": {}, "ghcr.io/devcontainers/features/docker-in-docker:2": { "moby": false }, "ghcr.io/devcontainers-extra/features/mise:1": {}, "ghcr.io/devcontainers/features/go:1": { "version": "1.25" Loading
gitlab_test.go +9 −1 Original line number Diff line number Diff line Loading @@ -57,6 +57,14 @@ var ( // configured to talk to that test server. Tests should register handlers on // mux which provide mock responses for the API method being tested. func setup(t *testing.T) (*http.ServeMux, *Client) { // Setup on subpath, but pass in an empty subpath. return setupOnSubpath(t, "") } // setupOnSubpath sets up a test HTTP server along with a gitlab.Client that is // configured to talk to that test server, but it sets up the client to use a baseURL // configured on a subpath instead of the root of the domain. func setupOnSubpath(t *testing.T, path string) (*http.ServeMux, *Client) { // mux is the HTTP request multiplexer used with the test server. mux := http.NewServeMux() Loading @@ -66,7 +74,7 @@ func setup(t *testing.T) (*http.ServeMux, *Client) { // client is the GitLab client being tested. client, err := NewClient("", WithBaseURL(server.URL), WithBaseURL(server.URL+path), // Disable backoff to speed up tests that expect errors. WithCustomBackoff(func(_, _ time.Duration, _ int, _ *http.Response) time.Duration { return 0 Loading
graphql.go +2 −1 Original line number Diff line number Diff line Loading @@ -84,8 +84,9 @@ func (g *GraphQL) Do(query GraphQLQuery, response any, options ...RequestOptionF if err != nil { return nil, fmt.Errorf("failed to create GraphQL request: %w", err) } // Overwrite the path of the existing request, as otherwise client-go appends /api/v4 instead. request.URL.Path = GraphQLAPIEndpoint request.URL.Path = strings.Replace(request.URL.Path, "/"+apiVersionPath, GraphQLAPIEndpoint, 1) resp, err := g.client.Do(request, response) if err != nil { // return error, details can be read from Response Loading
graphql_test.go +34 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,40 @@ func TestGraphQL_Do_Success(t *testing.T) { assert.Equal(t, "any-id", response.Data.Project.ID) } func TestGraphQL_Do_Success_With_Subpath(t *testing.T) { t.Parallel() // GIVEN mux, client := setupOnSubpath(t, "/subpath") mux.HandleFunc("/subpath/api/graphql", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, http.MethodPost) testJSONBody(t, r, `{ "query": "query { project(fullPath: \"gitlab-org/gitlab\") { id } }" }`) fmt.Fprint(w, ` { "data": { "project": { "id": "any-id" } } } `) }) // WHEN var response struct { Data struct { Project struct { ID string `json:"id"` } `json:"project"` } `json:"data"` } _, err := client.GraphQL.Do(GraphQLQuery{Query: `query { project(fullPath: "gitlab-org/gitlab") { id } }`}, &response) // THEN require.NoError(t, err) assert.Equal(t, "any-id", response.Data.Project.ID) } func TestGraphQL_Do_Success_With_Variables(t *testing.T) { t.Parallel() Loading