Repository navigation
Expand file tree
/
Copy pathgitprovider_immutability_test.go
More file actions
62 lines (53 loc) · 2.25 KB
/
Copy pathgitprovider_immutability_test.go
File metadata and controls
62 lines (53 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: Apache-2.0
package controller
import (
"context"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
configbutleraiv1alpha3 "github.com/ConfigButler/gitops-reverser/api/v1alpha3"
)
// A GitProvider's repository URL is the destination identity its GitTargets materialize
// into, so it is immutable (delete + recreate to repoint). Everything else is
// operational and must stay mutable — especially allowedBranches: widening or narrowing
// the writable set is a routine change that must not force tearing down every GitTarget.
var _ = Describe("GitProvider URL Immutability", func() {
const (
timeout = time.Second * 10
interval = time.Millisecond * 250
)
It("rejects a change to the URL but allows changing allowedGitBranches", func() {
ctx := context.Background()
key := types.NamespacedName{Name: "immutable-provider", Namespace: "default"}
provider := &configbutleraiv1alpha3.GitProvider{
ObjectMeta: metav1.ObjectMeta{Name: key.Name, Namespace: key.Namespace},
Spec: configbutleraiv1alpha3.GitProviderSpec{
URL: "https://example.com/repo.git",
AllowedGitBranches: branchesFromSame("main"),
},
}
Expect(k8sClient.Create(ctx, provider)).Should(Succeed())
DeferCleanup(func() { _ = k8sClient.Delete(ctx, provider) })
// allowedGitBranches is operational and mutable: widening the set succeeds.
Eventually(func(g Gomega) {
current := &configbutleraiv1alpha3.GitProvider{}
g.Expect(k8sClient.Get(ctx, key, current)).To(Succeed())
current.Spec.AllowedGitBranches[0].BranchPatterns = []configbutleraiv1alpha3.BranchPattern{
"main",
"develop",
}
g.Expect(k8sClient.Update(ctx, current)).To(Succeed())
}, timeout, interval).Should(Succeed())
// The URL is the destination identity and is immutable.
Eventually(func(g Gomega) {
current := &configbutleraiv1alpha3.GitProvider{}
g.Expect(k8sClient.Get(ctx, key, current)).To(Succeed())
current.Spec.URL = "https://example.com/other.git"
err := k8sClient.Update(ctx, current)
g.Expect(err).To(HaveOccurred())
g.Expect(err.Error()).To(ContainSubstring("spec.url is immutable"))
}, timeout, interval).Should(Succeed())
})
})