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:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"jiggablend/internal/auth"
|
||||
@@ -151,7 +152,15 @@ func runManager(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
func checkBlenderAvailable() error {
|
||||
cmd := exec.Command("blender", "--version")
|
||||
blenderPath, err := exec.LookPath("blender")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to locate blender in PATH: %w", err)
|
||||
}
|
||||
blenderPath, err = filepath.Abs(blenderPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve blender path %q: %w", blenderPath, err)
|
||||
}
|
||||
cmd := exec.Command(blenderPath, "--version")
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to run 'blender --version': %w (output: %s)", err, string(output))
|
||||
|
||||
23
cmd/jiggablend/cmd/managerconfig_test.go
Normal file
23
cmd/jiggablend/cmd/managerconfig_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGenerateAPIKey_Format(t *testing.T) {
|
||||
key, prefix, hash, err := generateAPIKey()
|
||||
if err != nil {
|
||||
t.Fatalf("generateAPIKey failed: %v", err)
|
||||
}
|
||||
if !strings.HasPrefix(prefix, "jk_r") {
|
||||
t.Fatalf("unexpected prefix: %q", prefix)
|
||||
}
|
||||
if !strings.HasPrefix(key, prefix+"_") {
|
||||
t.Fatalf("key does not include prefix: %q", key)
|
||||
}
|
||||
if len(hash) != 64 {
|
||||
t.Fatalf("expected sha256 hex hash length, got %d", len(hash))
|
||||
}
|
||||
}
|
||||
|
||||
16
cmd/jiggablend/cmd/root_test.go
Normal file
16
cmd/jiggablend/cmd/root_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package cmd
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRootCommand_HasKeySubcommands(t *testing.T) {
|
||||
names := map[string]bool{}
|
||||
for _, c := range rootCmd.Commands() {
|
||||
names[c.Name()] = true
|
||||
}
|
||||
for _, required := range []string{"manager", "runner", "version"} {
|
||||
if !names[required] {
|
||||
t.Fatalf("expected subcommand %q to be registered", required)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
cmd/jiggablend/cmd/runner_test.go
Normal file
17
cmd/jiggablend/cmd/runner_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGenerateShortID_IsHex8Bytes(t *testing.T) {
|
||||
id := generateShortID()
|
||||
if len(id) != 8 {
|
||||
t.Fatalf("expected 8 hex chars, got %q", id)
|
||||
}
|
||||
if _, err := hex.DecodeString(id); err != nil {
|
||||
t.Fatalf("id should be hex: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
13
cmd/jiggablend/cmd/version_test.go
Normal file
13
cmd/jiggablend/cmd/version_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package cmd
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestVersionCommand_Metadata(t *testing.T) {
|
||||
if versionCmd.Use != "version" {
|
||||
t.Fatalf("unexpected command use: %q", versionCmd.Use)
|
||||
}
|
||||
if versionCmd.Run == nil {
|
||||
t.Fatal("version command run function should be set")
|
||||
}
|
||||
}
|
||||
|
||||
8
cmd/jiggablend/main_test.go
Normal file
8
cmd/jiggablend/main_test.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMainPackage_Builds(t *testing.T) {
|
||||
// Smoke test placeholder to keep package main under test compilation.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user