Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions cmd/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/lugassawan/rimba/internal/config"
"github.com/lugassawan/rimba/internal/operations"
"github.com/lugassawan/rimba/testutil"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -201,6 +202,33 @@ func TestAddWithSource(t *testing.T) {
}
}

func TestPrintWorktreeResult(t *testing.T) {
cmd, buf := newTestCmd()
result := operations.AddResult{
Branch: branchFeature,
Path: pathWtFeatureLogin,
Copied: []string{".env", "config/local.json"},
Skipped: []string{"missing.env"},
SkippedSymlinks: []string{"linked-dir"},
}

printWorktreeResult(cmd, "Created worktree", result)

out := buf.String()
for _, want := range []string{
"Created worktree\n",
" Branch: " + branchFeature + "\n",
" Path: " + pathWtFeatureLogin + "\n",
" Copied: [.env config/local.json]\n",
" Skipped (not found): [missing.env]\n",
" Skipped (symlinks): [linked-dir]\n",
} {
if !strings.Contains(out, want) {
t.Errorf("output = %q, want %q", out, want)
}
}
}

func TestAddPRCmd(t *testing.T) {
t.Setenv("RIMBA_TRUST_YES", "1")
repoDir := t.TempDir()
Expand Down
46 changes: 46 additions & 0 deletions cmd/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,52 @@ func TestSyncAllDryRun(t *testing.T) {
}
}

func TestPrintSyncDryRun(t *testing.T) {
tests := []struct {
name string
useMerge bool
push bool
want []string
notWant []string
}{
{
name: "rebase without push",
want: []string{"[dry-run] would rebase " + branchFeature + " onto " + branchMain + "\n"},
notWant: []string{"would push"},
},
{
name: "merge with push",
useMerge: true,
push: true,
want: []string{
"[dry-run] would merge " + branchFeature + " onto " + branchMain + "\n",
"[dry-run] would push " + branchFeature + " to origin\n",
},
notWant: []string{"would rebase"},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd, buf := newTestCmd()

printSyncDryRun(cmd, branchFeature, branchMain, tt.useMerge, tt.push)

out := buf.String()
for _, want := range tt.want {
if !strings.Contains(out, want) {
t.Errorf("output = %q, want %q", out, want)
}
}
for _, notWant := range tt.notWant {
if strings.Contains(out, notWant) {
t.Errorf("output = %q, must not contain %q", out, notWant)
}
}
})
}
}

func TestSyncWorktreeSkipWarningOnStderr(t *testing.T) {
var outBuf, errBuf bytes.Buffer
cmd := &cobra.Command{}
Expand Down
Loading