Skip to content

Commit

Permalink
Cleanup agent integrationtests
Browse files Browse the repository at this point in the history
* remove init() for setting up test data per file, as test data is shared across
  files now.
* helpers don't Expect so missing resources are retried
  • Loading branch information
manno committed Dec 12, 2024
1 parent b444f2f commit c448345
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 96 deletions.
16 changes: 0 additions & 16 deletions integrationtests/agent/adoption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ import (
"github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
)

func init() {
resources["BundleDeploymentConfigMap"] = []v1alpha1.BundleResource{
{
Name: "configmap.yaml",
Content: `apiVersion: v1
kind: ConfigMap
metadata:
name: cm1
data:
key: value
`,
Encoding: "",
},
}
}

var _ = Describe("Adoption", Label("adopt"), func() {
var (
namespace string
Expand Down
32 changes: 7 additions & 25 deletions integrationtests/agent/bundle_deployment_drift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package agent_test
import (
"context"
"fmt"
"os"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -21,27 +20,6 @@ import (
"github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
)

func init() {
withStatus, _ := os.ReadFile(assetsPath + "/deployment-with-status.yaml")
withDeployment, _ := os.ReadFile(assetsPath + "/deployment-with-deployment.yaml")

resources["with-status"] = []v1alpha1.BundleResource{
{
Name: "deployment-with-status.yaml",
Content: string(withStatus),
Encoding: "",
},
}

resources["with-deployment"] = []v1alpha1.BundleResource{
{
Name: "deployment-with-deployment.yaml",
Content: string(withDeployment),
Encoding: "",
},
}
}

var _ = Describe("BundleDeployment drift correction", Ordered, func() {

const svcName = "svc-test"
Expand Down Expand Up @@ -280,8 +258,12 @@ var _ = Describe("BundleDeployment drift correction", Ordered, func() {

It("Updates the BundleDeployment status as not Ready, including the error message", func() {
By("Receiving a modification on a service")
svc, err := env.getService(svcName)
Expect(err).NotTo(HaveOccurred())
svc := corev1.Service{}
Eventually(func(g Gomega) {
var err error
svc, err = env.getService(svcName)
g.Expect(err).NotTo(HaveOccurred())
}).Should(Succeed())
patchedSvc := svc.DeepCopy()
patchedSvc.Spec.Ports[0].TargetPort = intstr.FromInt(4242)
patchedSvc.Spec.Ports[0].Port = 4242
Expand Down Expand Up @@ -311,7 +293,7 @@ var _ = Describe("BundleDeployment drift correction", Ordered, func() {
nsn := types.NamespacedName{Namespace: clusterNS, Name: name}
bd := v1alpha1.BundleDeployment{}

err = k8sClient.Get(ctx, nsn, &bd, &client.GetOptions{})
err := k8sClient.Get(ctx, nsn, &bd, &client.GetOptions{})
Expect(err).ToNot(HaveOccurred())

patchedBD := bd.DeepCopy()
Expand Down
21 changes: 0 additions & 21 deletions integrationtests/agent/bundle_deployment_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package agent_test

import (
"context"
"os"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -17,26 +16,6 @@ import (
"github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
)

func init() {
v1, _ := os.ReadFile(assetsPath + "/deployment-v1.yaml")
v2, _ := os.ReadFile(assetsPath + "/deployment-v2.yaml")

resources["v1"] = []v1alpha1.BundleResource{
{
Name: "deployment-v1.yaml",
Content: string(v1),
Encoding: "",
},
}
resources["v2"] = []v1alpha1.BundleResource{
{
Name: "deployment-v2.yaml",
Content: string(v2),
Encoding: "",
},
}
}

var _ = Describe("BundleDeployment status", Ordered, func() {

const (
Expand Down
32 changes: 0 additions & 32 deletions integrationtests/agent/helm_capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,6 @@ import (
"k8s.io/apimachinery/pkg/types"
)

func init() {
resources["capabilitiesv1"] = []v1alpha1.BundleResource{
{
Content: "apiVersion: v2\nname: config-chart\ndescription: A test chart that verifies its config\ntype: application\nversion: 0.1.0\nappVersion: \"1.16.0\"\nkubeVersion: '>= 1.20.0-0'\n",
Name: "config-chart/Chart.yaml",
},
{
Content: "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: test-simple-chart-config\ndata:\n test: \"value123\"\n name: {{ .Values.name }}\n kubeVersion: {{ .Capabilities.KubeVersion.Version }}\n apiVersions: {{ join \", \" .Capabilities.APIVersions | }}\n helmVersion: {{ .Capabilities.HelmVersion.Version }}\n",
Name: "config-chart/templates/configmap.yaml",
},
{
Content: "helm:\n chart: config-chart\n values:\n name: example-value\n",
Name: "fleet.yaml",
},
}

resources["capabilitiesv2"] = []v1alpha1.BundleResource{
{
Content: "apiVersion: v2\nname: config-chart\ndescription: A test chart that verifies its config\ntype: application\nversion: 0.1.0\nappVersion: \"1.16.0\"\nkubeVersion: '>= 920.920.0-0'\n",
Name: "config-chart/Chart.yaml",
},
{
Content: "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: test-simple-chart-config\ndata:\n test: \"value123\"\n name: {{ .Values.name }}\n",
Name: "config-chart/templates/configmap.yaml",
},
{
Content: "helm:\n chart: config-chart\n values:\n name: example-value\n",
Name: "fleet.yaml",
},
}
}

var _ = Describe("Helm Chart uses Capabilities", Ordered, func() {

var (
Expand Down
91 changes: 89 additions & 2 deletions integrationtests/agent/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ var _ = BeforeSuite(func() {
})
Expect(err).ToNot(HaveOccurred())

setupFakeContents()

driftChan := make(chan event.GenericEvent)

// Set up the bundledeployment reconciler
Expand Down Expand Up @@ -269,7 +271,10 @@ type specEnv struct {
func (se specEnv) isNotReadyAndModified(name string, modifiedStatus v1alpha1.ModifiedStatus, message string) (bool, string) {
bd := &v1alpha1.BundleDeployment{}
err := k8sClient.Get(context.TODO(), types.NamespacedName{Namespace: clusterNS, Name: name}, bd, &client.GetOptions{})
Expect(err).NotTo(HaveOccurred())
if err != nil {
return false, err.Error()
}

isReadyCondition := checkCondition(bd.Status.Conditions, "Ready", "False", message)

isOK := cmp.Equal(bd.Status.ModifiedStatus, []v1alpha1.ModifiedStatus{modifiedStatus}) &&
Expand All @@ -286,7 +291,10 @@ func (se specEnv) isNotReadyAndModified(name string, modifiedStatus v1alpha1.Mod
func (se specEnv) isBundleDeploymentReadyAndNotModified(name string) bool {
bd := &v1alpha1.BundleDeployment{}
err := k8sClient.Get(context.TODO(), types.NamespacedName{Namespace: clusterNS, Name: name}, bd, &client.GetOptions{})
Expect(err).NotTo(HaveOccurred())
if err != nil {
return false
}

return bd.Status.Ready && bd.Status.NonModified
}

Expand Down Expand Up @@ -337,3 +345,82 @@ func createNamespace() string {

return namespace
}

func setupFakeContents() {
withStatus, _ := os.ReadFile(assetsPath + "/deployment-with-status.yaml")
withDeployment, _ := os.ReadFile(assetsPath + "/deployment-with-deployment.yaml")
v1, _ := os.ReadFile(assetsPath + "/deployment-v1.yaml")
v2, _ := os.ReadFile(assetsPath + "/deployment-v2.yaml")

resources = map[string][]v1alpha1.BundleResource{
"with-status": []v1alpha1.BundleResource{
{
Name: "deployment-with-status.yaml",
Content: string(withStatus),
Encoding: "",
},
},
"with-deployment": []v1alpha1.BundleResource{
{
Name: "deployment-with-deployment.yaml",
Content: string(withDeployment),
Encoding: "",
},
},
"BundleDeploymentConfigMap": []v1alpha1.BundleResource{
{
Name: "configmap.yaml",
Content: `apiVersion: v1
kind: ConfigMap
metadata:
name: cm1
data:
key: value
`,
Encoding: "",
},
},
"v1": []v1alpha1.BundleResource{
{
Name: "deployment-v1.yaml",
Content: string(v1),
Encoding: "",
},
},
"v2": []v1alpha1.BundleResource{
{
Name: "deployment-v2.yaml",
Content: string(v2),
Encoding: "",
},
},
"capabilitiesv1": []v1alpha1.BundleResource{
{
Content: "apiVersion: v2\nname: config-chart\ndescription: A test chart that verifies its config\ntype: application\nversion: 0.1.0\nappVersion: \"1.16.0\"\nkubeVersion: '>= 1.20.0-0'\n",
Name: "config-chart/Chart.yaml",
},
{
Content: "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: test-simple-chart-config\ndata:\n test: \"value123\"\n name: {{ .Values.name }}\n kubeVersion: {{ .Capabilities.KubeVersion.Version }}\n apiVersions: {{ join \", \" .Capabilities.APIVersions | }}\n helmVersion: {{ .Capabilities.HelmVersion.Version }}\n",
Name: "config-chart/templates/configmap.yaml",
},
{
Content: "helm:\n chart: config-chart\n values:\n name: example-value\n",
Name: "fleet.yaml",
},
},
"capabilitiesv2": []v1alpha1.BundleResource{
{
Content: "apiVersion: v2\nname: config-chart\ndescription: A test chart that verifies its config\ntype: application\nversion: 0.1.0\nappVersion: \"1.16.0\"\nkubeVersion: '>= 920.920.0-0'\n",
Name: "config-chart/Chart.yaml",
},
{
Content: "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: test-simple-chart-config\ndata:\n test: \"value123\"\n name: {{ .Values.name }}\n",
Name: "config-chart/templates/configmap.yaml",
},
{
Content: "helm:\n chart: config-chart\n values:\n name: example-value\n",
Name: "fleet.yaml",
},
},
}
}

0 comments on commit c448345

Please sign in to comment.