TestCheckoutManagerMerging verifies that duplicate checkout configs are merged.
(t *testing.T)
| 42 | |
| 43 | // TestCheckoutManagerMerging verifies that duplicate checkout configs are merged. |
| 44 | func TestCheckoutManagerMerging(t *testing.T) { |
| 45 | t.Run("duplicate default checkout takes deepest fetch-depth", func(t *testing.T) { |
| 46 | depth1 := 1 |
| 47 | depth10 := 10 |
| 48 | cm := NewCheckoutManager([]*CheckoutConfig{ |
| 49 | {FetchDepth: &depth1}, |
| 50 | {FetchDepth: &depth10}, |
| 51 | }) |
| 52 | assert.Len(t, cm.ordered, 1, "should have merged into a single entry") |
| 53 | override := cm.GetDefaultCheckoutOverride() |
| 54 | require.NotNil(t, override.fetchDepth, "fetch depth should be set after merge") |
| 55 | assert.Equal(t, 10, *override.fetchDepth, "should use deeper fetch-depth (10 > 1)") |
| 56 | }) |
| 57 | |
| 58 | t.Run("zero fetch-depth wins over any positive value", func(t *testing.T) { |
| 59 | depth0 := 0 |
| 60 | depth5 := 5 |
| 61 | cm := NewCheckoutManager([]*CheckoutConfig{ |
| 62 | {FetchDepth: &depth5}, |
| 63 | {FetchDepth: &depth0}, |
| 64 | }) |
| 65 | override := cm.GetDefaultCheckoutOverride() |
| 66 | require.NotNil(t, override.fetchDepth, "fetch depth should be set") |
| 67 | assert.Equal(t, 0, *override.fetchDepth, "0 (full history) should win") |
| 68 | }) |
| 69 | |
| 70 | t.Run("sparse-checkout patterns are merged", func(t *testing.T) { |
| 71 | cm := NewCheckoutManager([]*CheckoutConfig{ |
| 72 | {Path: "./workspace", SparseCheckout: ".github/"}, |
| 73 | {Path: "./workspace", SparseCheckout: "src/"}, |
| 74 | }) |
| 75 | assert.Len(t, cm.ordered, 1, "should have merged into a single entry") |
| 76 | additional := cm.GenerateAdditionalCheckoutSteps(func(s string) string { return s }) |
| 77 | combined := strings.Join(additional, "") |
| 78 | assert.Contains(t, combined, ".github/", "should contain first sparse pattern") |
| 79 | assert.Contains(t, combined, "src/", "should contain second sparse pattern") |
| 80 | }) |
| 81 | |
| 82 | t.Run("different paths produce separate checkouts", func(t *testing.T) { |
| 83 | cm := NewCheckoutManager([]*CheckoutConfig{ |
| 84 | {Path: "./workspace1"}, |
| 85 | {Path: "./workspace2"}, |
| 86 | }) |
| 87 | assert.Len(t, cm.ordered, 2, "different paths should not be merged") |
| 88 | }) |
| 89 | |
| 90 | t.Run("different repos produce separate checkouts", func(t *testing.T) { |
| 91 | cm := NewCheckoutManager([]*CheckoutConfig{ |
| 92 | {Repository: "owner/repo1", Path: "./r1"}, |
| 93 | {Repository: "owner/repo2", Path: "./r2"}, |
| 94 | }) |
| 95 | assert.Len(t, cm.ordered, 2, "different repos should not be merged") |
| 96 | }) |
| 97 | |
| 98 | t.Run("same path with different refs merges to first ref", func(t *testing.T) { |
| 99 | cm := NewCheckoutManager([]*CheckoutConfig{ |
| 100 | {Path: "./workspace", Ref: "main"}, |
| 101 | {Path: "./workspace", Ref: "develop"}, |
nothing calls this directly
no test coverage detected