cli/pkg/sdk/detect_test.go
Snider c2b1e5dc61 feat(sdk): add OpenAPI spec detection
Detects OpenAPI spec via:
1. Configured spec path
2. Common paths (api/openapi.yaml, openapi.yaml, etc.)
3. Laravel Scramble (stub for now)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 01:11:15 +00:00

49 lines
1.1 KiB
Go

package sdk
import (
"os"
"path/filepath"
"testing"
)
func TestDetectSpec_Good_ConfigPath(t *testing.T) {
// Create temp directory with spec at configured path
tmpDir := t.TempDir()
specPath := filepath.Join(tmpDir, "api", "spec.yaml")
os.MkdirAll(filepath.Dir(specPath), 0755)
os.WriteFile(specPath, []byte("openapi: 3.0.0"), 0644)
sdk := New(tmpDir, &Config{Spec: "api/spec.yaml"})
got, err := sdk.DetectSpec()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got != specPath {
t.Errorf("got %q, want %q", got, specPath)
}
}
func TestDetectSpec_Good_CommonPath(t *testing.T) {
// Create temp directory with spec at common path
tmpDir := t.TempDir()
specPath := filepath.Join(tmpDir, "openapi.yaml")
os.WriteFile(specPath, []byte("openapi: 3.0.0"), 0644)
sdk := New(tmpDir, nil)
got, err := sdk.DetectSpec()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got != specPath {
t.Errorf("got %q, want %q", got, specPath)
}
}
func TestDetectSpec_Bad_NotFound(t *testing.T) {
tmpDir := t.TempDir()
sdk := New(tmpDir, nil)
_, err := sdk.DetectSpec()
if err == nil {
t.Fatal("expected error for missing spec")
}
}