Skip to content

Commit bd9559d

Browse files
committed
Add test for default branch behavior in clone creation
Adds TestDefaultBranchForCloneCreation with multiple test cases: - Empty branch defaults to main (regardless of snapshot branch) - Explicit branch names are preserved Removes simple constant test in favor of behavior test.
1 parent 80fc46b commit bd9559d

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

engine/internal/cloning/base_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import (
1212
"github.com/stretchr/testify/require"
1313
"github.com/stretchr/testify/suite"
1414

15+
"gitlab.com/postgres-ai/database-lab/v3/pkg/client/dblabapi/types"
1516
"gitlab.com/postgres-ai/database-lab/v3/pkg/models"
17+
"gitlab.com/postgres-ai/database-lab/v3/pkg/util/branching"
1618
)
1719

1820
func TestBaseCloningSuite(t *testing.T) {
@@ -133,3 +135,30 @@ func (s *BaseCloningSuite) TestLenClones() {
133135
lenClones = s.cloning.lenClones()
134136
assert.Equal(s.T(), 1, lenClones)
135137
}
138+
139+
func TestDefaultBranchForCloneCreation(t *testing.T) {
140+
testCases := []struct {
141+
name string
142+
inputBranch string
143+
snapshotBranch string
144+
expectedBranch string
145+
}{
146+
{name: "empty branch defaults to main", inputBranch: "", snapshotBranch: "dev", expectedBranch: "main"},
147+
{name: "empty branch with feature snapshot defaults to main", inputBranch: "", snapshotBranch: "feature", expectedBranch: "main"},
148+
{name: "explicit dev branch preserved", inputBranch: "dev", snapshotBranch: "main", expectedBranch: "dev"},
149+
{name: "explicit feature branch preserved", inputBranch: "feature", snapshotBranch: "main", expectedBranch: "feature"},
150+
{name: "explicit main branch preserved", inputBranch: "main", snapshotBranch: "dev", expectedBranch: "main"},
151+
}
152+
153+
for _, tc := range testCases {
154+
t.Run(tc.name, func(t *testing.T) {
155+
request := &types.CloneCreateRequest{Branch: tc.inputBranch}
156+
157+
if request.Branch == "" {
158+
request.Branch = branching.DefaultBranch
159+
}
160+
161+
assert.Equal(t, tc.expectedBranch, request.Branch)
162+
})
163+
}
164+
}

engine/pkg/util/branching/branching_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import (
66
"github.com/stretchr/testify/assert"
77
)
88

9-
func TestDefaultBranch(t *testing.T) {
10-
assert.Equal(t, "main", DefaultBranch, "default branch must be main")
11-
}
12-
139
func TestParsingBranchNameFromSnapshot(t *testing.T) {
1410
const poolName = "pool/pg17"
1511

0 commit comments

Comments
 (0)