- Config loader with env var expansion and validation - SQLite database with tasks and toolchain_versions tables - Gitea REST API client for repository and branch operations - K8s client for Job lifecycle management (with noop fallback for local dev) - REST API: tasks CRUD, retry, plugins, version management - Worker/scheduler with polling, concurrency control, and job tracking - Static frontend: generate, tasks, settings pages - Toolchain images: Go and Node.js Dockerfiles with entrypoint scripts - Helm chart with deployment, service, configmap, ingress, PVC - Multi-stage Dockerfile for service - Unit tests for config, database, gitclient, k8s, api, worker - E2E tests for idempotency, version switch, failure recovery
79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
package gitclient
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetBranch(t *testing.T) {
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/api/v1/repos/test-owner/test-repo/branches/main" {
|
|
t.Errorf("unexpected path: %s", r.URL.Path)
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
if r.Header.Get("Authorization") != "token test-token" {
|
|
t.Errorf("unexpected auth header: %s", r.Header.Get("Authorization"))
|
|
}
|
|
json.NewEncoder(w).Encode(Branch{Name: "main", Commit: "abc123"})
|
|
}))
|
|
defer server.Close()
|
|
|
|
client := NewClient(server.URL, "test-token")
|
|
b, err := client.GetBranch("test-owner", "test-repo", "main")
|
|
if err != nil {
|
|
t.Fatalf("GetBranch: %v", err)
|
|
}
|
|
if b.Name != "main" {
|
|
t.Errorf("Name = %q, want %q", b.Name, "main")
|
|
}
|
|
if b.Commit != "abc123" {
|
|
t.Errorf("Commit = %q, want %q", b.Commit, "abc123")
|
|
}
|
|
}
|
|
|
|
func TestListBranches(t *testing.T) {
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
json.NewEncoder(w).Encode([]Branch{
|
|
{Name: "main", Commit: "abc"},
|
|
{Name: "dev", Commit: "def"},
|
|
})
|
|
}))
|
|
defer server.Close()
|
|
|
|
client := NewClient(server.URL, "test-token")
|
|
branches, err := client.ListBranches("owner", "repo")
|
|
if err != nil {
|
|
t.Fatalf("ListBranches: %v", err)
|
|
}
|
|
if len(branches) != 2 {
|
|
t.Errorf("len(branches) = %d, want 2", len(branches))
|
|
}
|
|
}
|
|
|
|
func TestCreateRepository(t *testing.T) {
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != "POST" {
|
|
t.Errorf("unexpected method: %s", r.Method)
|
|
}
|
|
var body map[string]interface{}
|
|
json.NewDecoder(r.Body).Decode(&body)
|
|
if body["name"] != "new-repo" {
|
|
t.Errorf("name = %v, want new-repo", body["name"])
|
|
}
|
|
json.NewEncoder(w).Encode(Repository{Name: "new-repo", FullName: "owner/new-repo"})
|
|
}))
|
|
defer server.Close()
|
|
|
|
client := NewClient(server.URL, "test-token")
|
|
repo, err := client.CreateRepository("owner", "new-repo", "test", false)
|
|
if err != nil {
|
|
t.Fatalf("CreateRepository: %v", err)
|
|
}
|
|
if repo.Name != "new-repo" {
|
|
t.Errorf("Name = %q, want %q", repo.Name, "new-repo")
|
|
}
|
|
}
|