## Summary - Extract PHP/Laravel commands to `core/php` repo (42 files, standalone module) - Extract CI/release + SDK commands to `core/ci` repo (10 files) - Remove `internal/variants/` build tag system entirely - Move all 30 remaining command packages from `internal/cmd/` to top-level `cmd/` - Rewrite `main.go` with direct imports — no more variant selection - PHP and CI are now optional via commented import lines in main.go Co-authored-by: Claude <developers@lethean.io> Reviewed-on: #2 Co-authored-by: Charon <charon@lthn.ai> Co-committed-by: Charon <charon@lthn.ai>
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package updater
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetLatestUpdateFromURL(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
handler http.HandlerFunc
|
|
expectError bool
|
|
expectedVersion string
|
|
expectedURL string
|
|
}{
|
|
{
|
|
name: "Valid latest.json",
|
|
handler: func(w http.ResponseWriter, r *http.Request) {
|
|
_, _ = fmt.Fprintln(w, `{"version": "v1.1.0", "url": "http://example.com/release.zip"}`)
|
|
},
|
|
expectedVersion: "v1.1.0",
|
|
expectedURL: "http://example.com/release.zip",
|
|
},
|
|
{
|
|
name: "Invalid JSON",
|
|
handler: func(w http.ResponseWriter, r *http.Request) {
|
|
_, _ = fmt.Fprintln(w, `{"version": "v1.1.0", "url": "http://example.com/release.zip"`) // Missing closing brace
|
|
},
|
|
expectError: true,
|
|
},
|
|
{
|
|
name: "Missing version",
|
|
handler: func(w http.ResponseWriter, r *http.Request) {
|
|
_, _ = fmt.Fprintln(w, `{"url": "http://example.com/release.zip"}`)
|
|
},
|
|
expectError: true,
|
|
},
|
|
{
|
|
name: "Missing URL",
|
|
handler: func(w http.ResponseWriter, r *http.Request) {
|
|
_, _ = fmt.Fprintln(w, `{"version": "v1.1.0"}`)
|
|
},
|
|
expectError: true,
|
|
},
|
|
{
|
|
name: "Server error",
|
|
handler: func(w http.ResponseWriter, r *http.Request) {
|
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
|
},
|
|
expectError: true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
server := httptest.NewServer(tc.handler)
|
|
defer server.Close()
|
|
|
|
info, err := GetLatestUpdateFromURL(server.URL)
|
|
|
|
if (err != nil) != tc.expectError {
|
|
t.Errorf("Expected error: %v, got: %v", tc.expectError, err)
|
|
}
|
|
|
|
if !tc.expectError {
|
|
if info.Version != tc.expectedVersion {
|
|
t.Errorf("Expected version: %s, got: %s", tc.expectedVersion, info.Version)
|
|
}
|
|
if info.URL != tc.expectedURL {
|
|
t.Errorf("Expected URL: %s, got: %s", tc.expectedURL, info.URL)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|