- Introduced unit tests for the main package to ensure compilation. - Added tests for the manager, including validation of upload sessions and handling of Blender binary paths. - Implemented tests for job token generation and validation, ensuring security and integrity. - Created tests for configuration management and database schema to verify functionality. - Added tests for logger and runner components to enhance overall test coverage and reliability.
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewManagerClient_TrimsTrailingSlash(t *testing.T) {
|
|
c := NewManagerClient("http://example.com/")
|
|
if c.GetBaseURL() != "http://example.com" {
|
|
t.Fatalf("unexpected base url: %q", c.GetBaseURL())
|
|
}
|
|
}
|
|
|
|
func TestDoRequest_SetsAuthorizationHeader(t *testing.T) {
|
|
var authHeader string
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
authHeader = r.Header.Get("Authorization")
|
|
_ = json.NewEncoder(w).Encode(map[string]bool{"ok": true})
|
|
}))
|
|
defer ts.Close()
|
|
|
|
c := NewManagerClient(ts.URL)
|
|
c.SetCredentials(1, "abc123")
|
|
|
|
resp, err := c.Request(http.MethodGet, "/x", nil)
|
|
if err != nil {
|
|
t.Fatalf("Request failed: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if authHeader != "Bearer abc123" {
|
|
t.Fatalf("unexpected Authorization header: %q", authHeader)
|
|
}
|
|
}
|
|
|
|
func TestRequest_RequiresAuth(t *testing.T) {
|
|
c := NewManagerClient("http://example.com")
|
|
if _, err := c.Request(http.MethodGet, "/x", nil); err == nil {
|
|
t.Fatal("expected auth error when api key is missing")
|
|
}
|
|
}
|
|
|