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:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -8,11 +8,9 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
|
name: Run Go Tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: ./NewProxy
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -20,25 +18,24 @@ jobs:
|
|||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.25'
|
go-version-file: ./NewProxy/go.mod
|
||||||
|
|
||||||
- name: Cache Go modules
|
- name: Verify Go modules
|
||||||
uses: actions/cache@v4
|
working-directory: ./NewProxy
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/go/pkg/mod
|
|
||||||
~/.cache/go-build
|
|
||||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-go-
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: go mod tidy
|
run: go mod tidy
|
||||||
|
|
||||||
- name: Run unit tests
|
- name: Run unit tests with coverage
|
||||||
run: go test ./... -v -cover
|
working-directory: ./NewProxy
|
||||||
|
|
||||||
- name: Run vet & lint checks
|
|
||||||
run: |
|
run: |
|
||||||
go vet ./...
|
go test ./... -v -coverpkg=./... -coverprofile=coverage.out
|
||||||
test -z "$(gofmt -l .)"
|
|
||||||
|
- 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 (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"newproxy/routes"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -12,7 +11,7 @@ import (
|
|||||||
func TestBuildsHandler(t *testing.T) {
|
func TestBuildsHandler(t *testing.T) {
|
||||||
gin.SetMode(gin.TestMode)
|
gin.SetMode(gin.TestMode)
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
routes.RegisterBuildsRoute(r)
|
RegisterBuildsRoute(r)
|
||||||
|
|
||||||
req, _ := http.NewRequest("GET", "/client/builds.json", nil)
|
req, _ := http.NewRequest("GET", "/client/builds.json", nil)
|
||||||
w := httptest.NewRecorder()
|
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 (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"newproxy/routes"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -12,13 +11,13 @@ import (
|
|||||||
func TestStatusHandler(t *testing.T) {
|
func TestStatusHandler(t *testing.T) {
|
||||||
gin.SetMode(gin.TestMode)
|
gin.SetMode(gin.TestMode)
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
routes.RegisterStatusRoute(r)
|
RegisterStatusRoute(r)
|
||||||
|
|
||||||
req, _ := http.NewRequest("GET", "/status", nil)
|
req, _ := http.NewRequest("GET", "/status", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
r.ServeHTTP(w, req)
|
r.ServeHTTP(w, req)
|
||||||
|
|
||||||
if w.Code != http.StatusOK {
|
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