Skip to content

Commit

Permalink
test: Updated tests 👷
Browse files Browse the repository at this point in the history
  • Loading branch information
guisea committed Jul 31, 2024
1 parent 8954943 commit 72a1ffe
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
24 changes: 24 additions & 0 deletions pkg/provider/gitea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,30 @@ func TestGiteaCreateReleaseStripPrefix(t *testing.T) {
assertions.NoError(err)
}

func TestGiteaInvalidTag(t *testing.T) {
setup()
defer teardown()

assertions := require.New(t)
repo := &GiteaRepository{}

err := repo.Init(map[string]string{
"gitea_host": server.URL,
"slug": fmt.Sprintf("%s/%s", giteaUser, giteaRepo),
"token": "token",
})

assertions.NoError(err)

err = repo.CreateRelease(&provider.CreateReleaseConfig{
NewVersion: "1.0.1",
Prerelease: false,
Branch: "",
SHA: testSHA,
})
assertions.Errorf(err, "invalid tag name")
}

func TestGiteaEnvironmentVars(t *testing.T) {
setup()
defer teardown()
Expand Down
26 changes: 20 additions & 6 deletions pkg/provider/test_server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//coverage:ignore
package provider

import (
Expand Down Expand Up @@ -35,12 +36,6 @@ func CreateTestServer() *httptest.Server {

//gocyclo:ignore
func GiteaHandler(w http.ResponseWriter, r *http.Request) {
// Rate Limit headers
if r.Header.Get("Authorization") == "" {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}

if r.Method == http.MethodGet && r.URL.Path == "/api/v1/version" {
// Client performs a request to check version
// Get json string from file
Expand Down Expand Up @@ -88,3 +83,22 @@ func GiteaHandler(w http.ResponseWriter, r *http.Request) {

http.Error(w, "invalid route", http.StatusNotImplemented)
}

func GiteaHandlerFailed(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet && r.URL.Path == "/api/v1/version" {
// Client performs a request to check version
// Get json string from file
data, _ := retrieveData("data/Version.json")
_, _ = fmt.Fprint(w, string(data))
return
}

if r.Method == http.MethodGet && r.URL.Path == fmt.Sprintf("/api/v1/repos/%s/%s", giteaUser, giteaRepo) {
// Get json string from file
data, _ := retrieveData("data/GetRepoInfo.json")
_, _ = fmt.Fprint(w, string(data))
return
}

http.Error(w, "invalid route", http.StatusNotImplemented)
}

0 comments on commit 72a1ffe

Please sign in to comment.