Skip to content

Commit

Permalink
Update acceptance tests for updating profile
Browse files Browse the repository at this point in the history
  • Loading branch information
nikimanoledaki committed Feb 15, 2022
1 parent b20b80f commit 39e2b04
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
6 changes: 3 additions & 3 deletions cmd/gitops/update/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ func UpdateCommand(endpoint *string, client *resty.Client) *cobra.Command {
Use: "update",
Short: "Update a Weave GitOps resource",
Example: `
# Update an installed profile to a certain version
gitops update profile --name <profile-name> --version <version> --config-repo <config-repo-url> --cluster <cluster-name> --namespace <ns-name>
`,
# Update a profile that is installed on a cluster
gitops update profile --name=podinfo --cluster=prod --config-repo=ssh://git@github.com/owner/config-repo.git --version=1.0.0
`,
}

cmd.AddCommand(profiles.UpdateCommand())
Expand Down
8 changes: 4 additions & 4 deletions cmd/gitops/update/profiles/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ import (

var opts profiles.UpdateOptions

// UpdateCommand provides support for updating an installed profile's version.
// UpdateCommand provides support for updating a profile that is installed on a cluster.
func UpdateCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "profile",
Short: "Update a profile to a different version",
Short: "Update a profile installation",
SilenceUsage: true,
SilenceErrors: true,
Example: `
# Update an installed profile to a different version
gitops update profile --name=podinfo --cluster=prod --version=1.0.0 --config-repo=ssh://git@github.com/owner/config-repo.git --namespace=test-namespace
# Update a profile that is installed on a cluster
gitops update profile --name=podinfo --cluster=prod --config-repo=ssh://git@github.com/owner/config-repo.git --version=1.0.0
`,
RunE: updateProfileCmdRunE(),
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/helm/releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ var _ = Describe("AppendHelmReleaseToString", func() {
)
})

When("the file does not exist", func() {
It("creates one with the new helm release", func() {
When("the given string is empty", func() {
It("appends a helm release to it", func() {
s, err := helm.AppendHelmReleaseToString("", newRelease)
Expect(err).NotTo(HaveOccurred())
r, err := yaml.Marshal(newRelease)
Expand Down
30 changes: 18 additions & 12 deletions test/acceptance/test/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,27 @@ Namespace: %s`, clusterName, namespace)))
}, "120s", "1s").Should(Equal(http.StatusOK))

By("Updating the version of the installed profile")
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))
Expect(stdErr).To(BeEmpty())
time.Sleep(4 * time.Minute)
Eventually(func() string {
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))
return stdErr
}, "120s", "5s").Should(BeEmpty())

Expect(stdOut).To(ContainSubstring(
fmt.Sprintf(`Updating 1 profile:
Name: podinfo
Version: 6.0.0
Cluster: %s
Namespace: %s`, clusterName, namespace)))
fmt.Sprintf(
`Updating profile:
Name: podinfo
Version: 6.0.0
Cluster: %s
Namespace: %s`, clusterName, namespace)))

By("Verifying that the profile installed in the cluster's namespace was updated to the correct version")
Eventually(func() int {
resp, statusCode, err = kubernetesDoRequest(namespace, clusterName+"-"+profileName, "9898", "/healthz", clientSet)
return statusCode
}, "120s", "1s").Should(Equal(http.StatusOK))
Eventually(func() string {
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))
Expect(stdErr).Should(BeEmpty())
return stdOut
}, "240s", "5s").Should(ContainSubstring("ghcr.io/stefanprodan/podinfo:6.0.0"))
})

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

0 comments on commit 39e2b04

Please sign in to comment.