Skip to content

Commit

Permalink
Merge pull request #236 from fluxcd/remove-ext-dep-gitea
Browse files Browse the repository at this point in the history
Declare Gitea client test e2e
  • Loading branch information
makkes authored Jun 20, 2023
2 parents 48f0280 + 519940d commit 2200758
Showing 1 changed file with 40 additions and 24 deletions.
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

0 comments on commit 2200758

Please sign in to comment.