Add tests for main package, manager, and various components
- 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.
This commit is contained in:
56
internal/auth/auth_test.go
Normal file
56
internal/auth/auth_test.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestContextHelpers(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, contextKeyUserID, int64(123))
|
||||
ctx = context.WithValue(ctx, contextKeyIsAdmin, true)
|
||||
|
||||
id, ok := GetUserID(ctx)
|
||||
if !ok || id != 123 {
|
||||
t.Fatalf("GetUserID() = (%d,%v), want (123,true)", id, ok)
|
||||
}
|
||||
if !IsAdmin(ctx) {
|
||||
t.Fatal("expected IsAdmin to be true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsProductionMode_UsesEnv(t *testing.T) {
|
||||
t.Setenv("PRODUCTION", "true")
|
||||
if !IsProductionMode() {
|
||||
t.Fatal("expected production mode true when env is set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteUnauthorized_BehaviorByRequestType(t *testing.T) {
|
||||
a := &Auth{}
|
||||
|
||||
reqAPI := httptest.NewRequest(http.MethodGet, "/api/jobs", nil)
|
||||
rrAPI := httptest.NewRecorder()
|
||||
a.writeUnauthorized(rrAPI, reqAPI)
|
||||
if rrAPI.Code != http.StatusUnauthorized {
|
||||
t.Fatalf("api code = %d", rrAPI.Code)
|
||||
}
|
||||
|
||||
reqPage := httptest.NewRequest(http.MethodGet, "/dashboard", nil)
|
||||
rrPage := httptest.NewRecorder()
|
||||
a.writeUnauthorized(rrPage, reqPage)
|
||||
if rrPage.Code != http.StatusFound {
|
||||
t.Fatalf("page code = %d", rrPage.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsProductionMode_DefaultFalse(t *testing.T) {
|
||||
_ = os.Unsetenv("PRODUCTION")
|
||||
if IsProductionMode() {
|
||||
t.Fatal("expected false when PRODUCTION is unset")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user