- Added .github/workflows/go-test.yml for automated CI testing using GitHub Actions - Implemented unit tests for: • utils/release.go (FetchLatestRelease) • routes/builds.go (buildsHandler) • routes/status.go (statusHandler) - Ensured tests run with go test ./... -v -cover - Included go vet and gofmt checks in the CI pipeline - Improved project reliability and continuous integration setup
27 lines
668 B
Go
27 lines
668 B
Go
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")
|
|
}
|
|
}
|