Updated GitHub Actions workflow for Go tests and coverage
This commit is contained in:
41
.github/workflows/go-test.yml
vendored
41
.github/workflows/go-test.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: Go CI - Tests
|
||||
name: Go Test and Coverage
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -8,11 +8,9 @@ on:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Run Go Tests
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./NewProxy
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
@@ -20,25 +18,24 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.25'
|
||||
go-version-file: ./NewProxy/go.mod
|
||||
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/go/pkg/mod
|
||||
~/.cache/go-build
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
|
||||
- name: Install dependencies
|
||||
- name: Verify Go modules
|
||||
working-directory: ./NewProxy
|
||||
run: go mod tidy
|
||||
|
||||
- name: Run unit tests
|
||||
run: go test ./... -v -cover
|
||||
|
||||
- name: Run vet & lint checks
|
||||
- name: Run unit tests with coverage
|
||||
working-directory: ./NewProxy
|
||||
run: |
|
||||
go vet ./...
|
||||
test -z "$(gofmt -l .)"
|
||||
go test ./... -v -coverpkg=./... -coverprofile=coverage.out
|
||||
|
||||
- name: Show coverage summary
|
||||
working-directory: ./NewProxy
|
||||
run: go tool cover -func=coverage.out
|
||||
|
||||
- name: Upload coverage report
|
||||
if: success()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: coverage-report
|
||||
path: NewProxy/coverage.out
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package tests
|
||||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"newproxy/routes"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -12,7 +11,7 @@ import (
|
||||
func TestBuildsHandler(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
r := gin.Default()
|
||||
routes.RegisterBuildsRoute(r)
|
||||
RegisterBuildsRoute(r)
|
||||
|
||||
req, _ := http.NewRequest("GET", "/client/builds.json", nil)
|
||||
w := httptest.NewRecorder()
|
||||
31
NewProxy/routes/forward_test.go
Normal file
31
NewProxy/routes/forward_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func TestForwardHandler(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
r := gin.Default()
|
||||
RegisterForwardRoute(r)
|
||||
|
||||
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("OK"))
|
||||
}))
|
||||
defer mockServer.Close()
|
||||
|
||||
req, _ := http.NewRequest("GET", "/?url="+mockServer.URL, nil)
|
||||
w := httptest.NewRecorder()
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Errorf("Expected 200 OK, got %d", w.Code)
|
||||
}
|
||||
if w.Body.String() != "OK" {
|
||||
t.Errorf("Expected body 'OK', got '%s'", w.Body.String())
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package tests
|
||||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"newproxy/routes"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -12,13 +11,13 @@ import (
|
||||
func TestStatusHandler(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
r := gin.Default()
|
||||
routes.RegisterStatusRoute(r)
|
||||
RegisterStatusRoute(r)
|
||||
|
||||
req, _ := http.NewRequest("GET", "/status", nil)
|
||||
w := httptest.NewRecorder()
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Errorf("Expected status 200 OK, got %d", w.Code)
|
||||
t.Errorf("Expected 200 OK, got %d", w.Code)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"newproxy/utils"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFetchLatestRelease_ValidFile(t *testing.T) {
|
||||
content := `{"release_version": "v1.0.0", "release_time": "2025-01-01T00:00:00Z"}`
|
||||
_ = os.WriteFile("data/release.json", []byte(content), 0644)
|
||||
utils.FetchLatestRelease()
|
||||
|
||||
if utils.LatestRelease.ReleaseVersion != "v1.0.0" {
|
||||
t.Errorf("Expected version v1.0.0, got %s", utils.LatestRelease.ReleaseVersion)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFetchLatestRelease_MissingFile(t *testing.T) {
|
||||
_ = os.Remove("data/release.json")
|
||||
utils.FetchLatestRelease()
|
||||
|
||||
if utils.LatestRelease.ReleaseVersion == "" {
|
||||
t.Errorf("Expected default release info, got empty version")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user