- Remove internal/cmd/php/ (now core/php repo) - Remove internal/cmd/ci/ and internal/cmd/sdk/ (now core/ci repo) - Remove internal/variants/ build tag system entirely - Move all 30 remaining command packages from internal/cmd/ to cmd/ - Rewrite main.go with direct imports (no more variant selection) - Update all cross-references from internal/cmd/ to cmd/ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|