Skip to content

Commit 62de952

Browse files
author
nikimanoledaki
committed
Update acceptance tests for updating profile
1 parent b20b80f commit 62de952

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

cmd/gitops/update/cmd.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ func UpdateCommand(endpoint *string, client *resty.Client) *cobra.Command {
1212
Use: "update",
1313
Short: "Update a Weave GitOps resource",
1414
Example: `
15-
# Update an installed profile to a certain version
16-
gitops update profile --name <profile-name> --version <version> --config-repo <config-repo-url> --cluster <cluster-name> --namespace <ns-name>
17-
`,
15+
# Update a profile that is installed on a cluster
16+
gitops update profile --name=podinfo --cluster=prod --config-repo=ssh://[email protected]/owner/config-repo.git --version=1.0.0
17+
`,
1818
}
1919

2020
cmd.AddCommand(profiles.UpdateCommand())

cmd/gitops/update/profiles/profiles.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ import (
2424

2525
var opts profiles.UpdateOptions
2626

27-
// UpdateCommand provides support for updating an installed profile's version.
27+
// UpdateCommand provides support for updating a profile that is installed on a cluster.
2828
func UpdateCommand() *cobra.Command {
2929
cmd := &cobra.Command{
3030
Use: "profile",
31-
Short: "Update a profile to a different version",
31+
Short: "Update a profile installation",
3232
SilenceUsage: true,
3333
SilenceErrors: true,
3434
Example: `
35-
# Update an installed profile to a different version
36-
gitops update profile --name=podinfo --cluster=prod --version=1.0.0 --config-repo=ssh://[email protected]/owner/config-repo.git --namespace=test-namespace
35+
# Update a profile that is installed on a cluster
36+
gitops update profile --name=podinfo --cluster=prod --config-repo=ssh://[email protected]/owner/config-repo.git --version=1.0.0
3737
`,
3838
RunE: updateProfileCmdRunE(),
3939
}

pkg/helm/releases_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ var _ = Describe("AppendHelmReleaseToString", func() {
7575
)
7676
})
7777

78-
When("the file does not exist", func() {
79-
It("creates one with the new helm release", func() {
78+
When("the given string is empty", func() {
79+
It("appends a helm release to it", func() {
8080
s, err := helm.AppendHelmReleaseToString("", newRelease)
8181
Expect(err).NotTo(HaveOccurred())
8282
r, err := yaml.Marshal(newRelease)

pkg/services/profiles/get_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ podinfo Podinfo Helm chart for Kubernetes 6.0.0,6.0.1
196196
Expect(err).To(MatchError("no version found for profile 'podinfo' in prod/test-namespace"))
197197
})
198198

199-
It("fails if the available profile's HelmRepository name or namespace if empty", func() {
199+
It("fails if the available profile's HelmRepository name or namespace are empty", func() {
200200
badProfileResp := `{
201201
"profiles": [
202202
{

test/acceptance/test/profiles_test.go

+18-12
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,27 @@ Namespace: %s`, clusterName, namespace)))
131131
}, "120s", "1s").Should(Equal(http.StatusOK))
132132

133133
By("Updating the version of the installed profile")
134-
stdOut, stdErr = runCommandAndReturnStringOutput(fmt.Sprintf("%s update profile --name %s --version 6.0.0 --namespace %s --cluster %s --config-repo %s --auto-merge", gitopsBinaryPath, profileName, namespace, clusterName, appRepoRemoteURL))
135-
Expect(stdErr).To(BeEmpty())
134+
time.Sleep(4 * time.Minute)
135+
Eventually(func() string {
136+
stdOut, stdErr = runCommandAndReturnStringOutput(fmt.Sprintf("%s update profile --name %s --version 6.0.0 --namespace %s --cluster %s --config-repo %s --auto-merge", gitopsBinaryPath, profileName, namespace, clusterName, appRepoRemoteURL))
137+
return stdErr
138+
}, "120s", "5s").Should(BeEmpty())
139+
136140
Expect(stdOut).To(ContainSubstring(
137-
fmt.Sprintf(`Updating 1 profile:
138-
139-
Name: podinfo
140-
Version: 6.0.0
141-
Cluster: %s
142-
Namespace: %s`, clusterName, namespace)))
141+
fmt.Sprintf(
142+
`Updating profile:
143+
144+
Name: podinfo
145+
Version: 6.0.0
146+
Cluster: %s
147+
Namespace: %s`, clusterName, namespace)))
143148

144149
By("Verifying that the profile installed in the cluster's namespace was updated to the correct version")
145-
Eventually(func() int {
146-
resp, statusCode, err = kubernetesDoRequest(namespace, clusterName+"-"+profileName, "9898", "/healthz", clientSet)
147-
return statusCode
148-
}, "120s", "1s").Should(Equal(http.StatusOK))
150+
Eventually(func() string {
151+
stdOut, stdErr = runCommandAndReturnStringOutput(fmt.Sprintf("kubectl get pods -n %s --selector=app.kubernetes.io/name=%s-%s -o jsonpath='{.items[*].spec.containers[*].image}'", namespace, clusterName, profileName))
152+
Expect(stdErr).Should(BeEmpty())
153+
return stdOut
154+
}, "240s", "5s").Should(ContainSubstring("ghcr.io/stefanprodan/podinfo:6.0.0"))
149155
})
150156

151157
It("@skipOnNightly profiles are installed into a different namespace", func() {

0 commit comments

Comments
 (0)