Skip to content

Declare Gitea client test e2e #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 40 additions & 24 deletions gitea/client_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build e2e

/*
Copyright 2023 The Flux CD contributors.

Expand All @@ -17,49 +19,63 @@ limitations under the License.
package gitea

import (
"net/url"
"os"
"regexp"
"testing"

"github.com/fluxcd/go-git-providers/gitprovider"
)

func Test_DomainVariations(t *testing.T) {

giteaBaseUrl = "http://try.gitea.io"
if giteaBaseUrlVar := os.Getenv("GITEA_BASE_URL"); giteaBaseUrlVar != "" {
giteaBaseUrl = giteaBaseUrlVar
}

u, err := url.Parse(giteaBaseUrl)
if err != nil {
t.Fatalf("failed parsing base URL %q: %s", giteaBaseUrl, err)
}

tests := []struct {
name string
opts gitprovider.ClientOption
want string
expectedErrs []error
name string
opts gitprovider.ClientOption
want string
expectedErrPattern string
}{
{
name: "try.gitea.io domain",
opts: gitprovider.WithDomain("try.gitea.io"),
want: "try.gitea.io",
name: "custom domain without protocol uses HTTPS by default",
opts: gitprovider.WithDomain(u.Host),
expectedErrPattern: "http: server gave HTTP response to HTTPS client",
},
{
name: "custom domain without protocol",
opts: gitprovider.WithDomain("try.gitea.io"),
want: "try.gitea.io",
},
{
name: "custom domain with https protocol",
opts: gitprovider.WithDomain("https://try.gitea.io"),
want: "https://try.gitea.io",
},
{
name: "custom domain with http protocol",
opts: gitprovider.WithDomain("http://try.gitea.io"),
want: "http://try.gitea.io",
name: "custom domain with scheme",
opts: gitprovider.WithDomain(giteaBaseUrl),
want: giteaBaseUrl,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c1, err := NewClient("token", tt.opts)
if err != nil {
t.Fatal(err)
if tt.expectedErrPattern == "" {
t.Fatalf("unexpected error: %s", err)
}
m, mErr := regexp.MatchString(tt.expectedErrPattern, err.Error())
if mErr != nil {
t.Fatalf("unexpected error from matching error: %s", mErr)
}
if !m {
t.Fatalf("unexpected error %q; expected %q", err, tt.expectedErrPattern)
}
return // all assertions passed
} else if tt.expectedErrPattern != "" {
t.Fatalf("expected error %q but got none", tt.expectedErrPattern)
}
assertEqual(t, tt.want, c1.SupportedDomain())

c2, _ := NewClient("token", tt.opts)
assertEqual(t, tt.want, c2.SupportedDomain())
assertEqual(t, tt.want, c1.SupportedDomain())
})
}
}
Expand Down