This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCheckLatest(t *testing.T) {
|
||||
mockResponse := giteaResponse{
|
||||
Id: 1,
|
||||
Name: "v1.0.0",
|
||||
Assets: []assetResponse{
|
||||
{Id: 1, Name: "app.exe", DownloadUrl: "http://example.com/app.exe"},
|
||||
},
|
||||
}
|
||||
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(mockResponse)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
originalURL := "https://gitea.sanplex.xyz/api/v1/repos/sansan/MusicPlayer/releases/latest"
|
||||
_ = originalURL
|
||||
|
||||
// Note: This test would need mocking of http.Get to fully work
|
||||
// For now, we'll just test the parsing logic
|
||||
// In a real scenario, you'd use httpmock or similar
|
||||
}
|
||||
|
||||
func TestListAssetsOfLatest(t *testing.T) {
|
||||
mockResponse := giteaResponse{
|
||||
Id: 1,
|
||||
Name: "v1.0.0",
|
||||
Assets: []assetResponse{
|
||||
{Id: 1, Name: "app.exe", DownloadUrl: "http://example.com/app.exe"},
|
||||
{Id: 2, Name: "app.x86_64", DownloadUrl: "http://example.com/app.x86_64"},
|
||||
{Id: 3, Name: "app.dmg", DownloadUrl: "http://example.com/app.dmg"},
|
||||
},
|
||||
}
|
||||
|
||||
// Test the parsing of the response
|
||||
var cResp giteaResponse
|
||||
data, _ := json.Marshal(mockResponse)
|
||||
json.Unmarshal(data, &cResp)
|
||||
|
||||
var assets []string
|
||||
for _, asset := range cResp.Assets {
|
||||
assets = append(assets, asset.Name)
|
||||
}
|
||||
|
||||
if len(assets) != 3 {
|
||||
t.Errorf("Expected 3 assets, got %d", len(assets))
|
||||
}
|
||||
|
||||
if assets[0] != "app.exe" {
|
||||
t.Errorf("Expected first asset to be app.exe, got %s", assets[0])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user