[object Object]

← back to Cli Printing Press

test(cli): add integration tests for claimOrForce behavior

bc6867314a966c29557b297e9da4136049204d17 · 2026-03-27 19:44:26 -0700 · Trevin Chow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files touched

Diff

commit bc6867314a966c29557b297e9da4136049204d17
Author: Trevin Chow <trevin@trevinchow.com>
Date:   Fri Mar 27 19:44:26 2026 -0700

    test(cli): add integration tests for claimOrForce behavior
    
    Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---
 internal/cli/claim_integration_test.go | 77 ++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/internal/cli/claim_integration_test.go b/internal/cli/claim_integration_test.go
new file mode 100644
index 00000000..0c92c8fd
--- /dev/null
+++ b/internal/cli/claim_integration_test.go
@@ -0,0 +1,77 @@
+package cli
+
+import (
+	"os"
+	"path/filepath"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+)
+
+func TestClaimOrForce_DefaultAutoIncrements(t *testing.T) {
+	tmp := t.TempDir()
+	base := filepath.Join(tmp, "myapi-pp-cli")
+
+	// First call claims the base
+	got, err := claimOrForce(base, false, false)
+	require.NoError(t, err)
+	assert.Equal(t, base, got)
+
+	// Second call auto-increments to -2
+	got, err = claimOrForce(base, false, false)
+	require.NoError(t, err)
+	assert.Equal(t, base+"-2", got)
+
+	// Third call auto-increments to -3
+	got, err = claimOrForce(base, false, false)
+	require.NoError(t, err)
+	assert.Equal(t, base+"-3", got)
+}
+
+func TestClaimOrForce_ForceOverwrites(t *testing.T) {
+	tmp := t.TempDir()
+	base := filepath.Join(tmp, "myapi-pp-cli")
+
+	// Create base with a file in it
+	require.NoError(t, os.MkdirAll(base, 0o755))
+	require.NoError(t, os.WriteFile(filepath.Join(base, "main.go"), []byte("package main"), 0o644))
+
+	// Force should blow it away and recreate
+	got, err := claimOrForce(base, true, false)
+	require.NoError(t, err)
+	assert.Equal(t, base, got)
+
+	// Old contents should be gone
+	entries, err := os.ReadDir(base)
+	require.NoError(t, err)
+	assert.Empty(t, entries)
+}
+
+func TestClaimOrForce_ExplicitOutputErrorsOnCollision(t *testing.T) {
+	tmp := t.TempDir()
+	base := filepath.Join(tmp, "myapi-pp-cli")
+
+	// Create base with content
+	require.NoError(t, os.MkdirAll(base, 0o755))
+	require.NoError(t, os.WriteFile(filepath.Join(base, "main.go"), []byte("package main"), 0o644))
+
+	// Explicit output without force should error
+	_, err := claimOrForce(base, false, true)
+	assert.Error(t, err)
+	assert.Contains(t, err.Error(), "already exists")
+}
+
+func TestClaimOrForce_ExplicitOutputWithForce(t *testing.T) {
+	tmp := t.TempDir()
+	base := filepath.Join(tmp, "myapi-pp-cli")
+
+	// Create base with content
+	require.NoError(t, os.MkdirAll(base, 0o755))
+	require.NoError(t, os.WriteFile(filepath.Join(base, "main.go"), []byte("package main"), 0o644))
+
+	// Explicit output with force should succeed
+	got, err := claimOrForce(base, true, true)
+	require.NoError(t, err)
+	assert.Equal(t, base, got)
+}

← 51ba9996 docs(cli): update --force flag description to reflect auto-i  ·  back to Cli Printing Press  ·  docs: mark implementation plan as completed e2e68fb9 →