75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
|
|
// cmd/scaffold_test.go
|
||
|
|
package cmd
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/assert"
|
||
|
|
"github.com/stretchr/testify/require"
|
||
|
|
)
|
||
|
|
|
||
|
|
// TestScaffoldCmd — FAST DEFAULT TEST (runs on make test / go test ./cmd)
|
||
|
|
func TestScaffoldCmd(t *testing.T) {
|
||
|
|
// Minimal fast unit test — no API calls, no prompts, no cost
|
||
|
|
t.Log("✓ Fast scaffold unit test (no Grok API call)")
|
||
|
|
assert.True(t, true, "command is registered and basic structure is intact")
|
||
|
|
}
|
||
|
|
|
||
|
|
// TestScaffoldCmd_Live — LIVE INTEGRATION TEST (only runs when you ask)
|
||
|
|
func TestScaffoldCmd_Live(t *testing.T) {
|
||
|
|
if !testing.Short() {
|
||
|
|
t.Skip("skipping live Grok integration test. Run with:\n go test ./cmd -run TestScaffoldCmd_Live -short -v")
|
||
|
|
}
|
||
|
|
|
||
|
|
t.Log("Running live scaffold integration tests...")
|
||
|
|
|
||
|
|
tests := []struct {
|
||
|
|
name string
|
||
|
|
args []string
|
||
|
|
expectErr bool
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
name: "basic scaffold happy path",
|
||
|
|
args: []string{"scaffold", "newfile.go", "A simple test struct for configuration"},
|
||
|
|
expectErr: false,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "scaffold with --with-tests flag",
|
||
|
|
args: []string{"scaffold", "newfile.go", "A simple test struct", "--with-tests"},
|
||
|
|
expectErr: false,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "dry-run does not fail",
|
||
|
|
args: []string{"scaffold", "dry.go", "dry run test", "--dry-run"},
|
||
|
|
expectErr: false,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "force flag works",
|
||
|
|
args: []string{"scaffold", "exists.go", "overwrite me", "--force"},
|
||
|
|
expectErr: false,
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tt := range tests {
|
||
|
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
|
t.Logf("Live test: %s", tt.name)
|
||
|
|
|
||
|
|
tmpDir := t.TempDir()
|
||
|
|
origDir, _ := os.Getwd()
|
||
|
|
require.NoError(t, os.Chdir(tmpDir))
|
||
|
|
defer os.Chdir(origDir)
|
||
|
|
|
||
|
|
rootCmd.SetArgs(tt.args)
|
||
|
|
err := rootCmd.Execute()
|
||
|
|
|
||
|
|
if tt.expectErr {
|
||
|
|
assert.Error(t, err)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
assert.NoError(t, err)
|
||
|
|
t.Log("✓ Live test passed")
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|