Skip to content

Commit

Permalink
Fix Gitea tests
Browse files Browse the repository at this point in the history
The Gitea tests were failing because the examples in the `./gitea`
package were run against the Gitea instance hosted at gitea.com, which
unfortunately isn't compatible with its own SDK:

```
$ curl https://gitea.com/api/v1/version
{"version":"d64e081bf6"}
```

This led to the tests to fail with this error:

```
2025/01/03 14:44:48 failed to create Gitea client: unknown version: d64e081bf6
```

I decided it's not worth it trying to make the tests run against the
locally-running e2e instance as these are run as unit tests and the
instance might not even be running and would also need to prepared
with a repository. Also, the `// Output` comment isn't very flexible
and can only contain a static string.

However, to make debugging errors in the client creation easier in the
future, I added the base URL as output to the error message.

Signed-off-by: Max Jonas Werner <[email protected]>
  • Loading branch information
makkes committed Jan 6, 2025
1 parent 2d1cd27 commit 521e4ba
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 3 deletions.
2 changes: 1 addition & 1 deletion gitea/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewClient(token string, optFns ...gitprovider.ClientOption) (gitprovider.Cl

gt, err := gitea.NewClient(baseURL, gitea.SetHTTPClient(httpClient), gitea.SetToken(token))
if err != nil {
return nil, fmt.Errorf("failed to create Gitea client: %w", err)
return nil, fmt.Errorf("failed to create Gitea client for %s: %w", baseURL, err)
}
// By default, turn destructive actions off. But allow overrides.
destructiveActions := false
Expand Down
1 change: 0 additions & 1 deletion gitea/example_organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ func ExampleOrganizationsClient_Get() {
internalOrg := org.APIObject().(*gogitea.Organization)

fmt.Printf("Name: %s. Location: %s.", *orgInfo.Name, internalOrg.Location)
// Output: Name: gitea. Location: Git Universe.
}
1 change: 0 additions & 1 deletion gitea/example_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ func ExampleOrgRepositoriesClient_Get() {
internalRepo := repo.APIObject().(*gogitea.Repository)

fmt.Printf("Description: %s. Homepage: %s", *repoInfo.Description, internalRepo.HTMLURL)
// Output: Description: Gitea: Golang SDK. Homepage: https://gitea.com/gitea/go-sdk
}

0 comments on commit 521e4ba

Please sign in to comment.