Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
add unit tests for retreiving proxy settings from management cluster …
Browse files Browse the repository at this point in the history
…and workload cluster

Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>
  • Loading branch information
andrewsykim authored and vuil committed Sep 14, 2021
1 parent 87e5ad1 commit 074a3f4
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions pkg/v1/tkg/client/upgrade_addon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
package client_test

import (
"testing"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pkg/errors"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

capi "sigs.k8s.io/cluster-api/api/v1alpha3"
Expand All @@ -17,6 +20,7 @@ import (
"github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/clusterclient"
"github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/constants"
"github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/fakes"
fakehelper "github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/fakes/helper"
)

var _ = Describe("Unit tests for addons upgrade", func() {
Expand Down Expand Up @@ -225,3 +229,97 @@ var _ = Describe("Unit tests for addons upgrade", func() {
})
})
})

// Test_RetrieveProxySettings tests a previous regression where the proxy settings
// for a workload cluster was being incorrectly inherited from the management cluster.
// Specifically, this test validates retreiving proxy settings for a workload cluster
// with different settings from the management cluster.
func Test_RetrieveProxySettings(t *testing.T) {
RegisterTestingT(t)
g := NewWithT(t)

tkgClient, err := CreateTKGClient("../fakes/config/config2.yaml", fakehelper.CreateTempTestingDirectory(), "../fakes/config/bom/tkg-bom-v1.3.1.yaml", 2*time.Millisecond)
g.Expect(err).To(BeNil())

regionalClusterClient := &fakes.ClusterClient{}
regionalClusterClient.ListClustersReturns([]capi.Cluster{
{
ObjectMeta: metav1.ObjectMeta{
Name: "regional-cluster-2",
Namespace: constants.DefaultNamespace,
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "workload-cluster",
Namespace: constants.DefaultNamespace,
},
},
}, nil)
regionalClusterClient.GetResourceStub = func(obj interface{}, name string, namespace string, verifyFunc clusterclient.PostVerifyrFunc, pollOptions *clusterclient.PollOptions) error {
if name == constants.KappControllerConfigMapName {
cm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: constants.KappControllerConfigMapName,
Namespace: constants.KappControllerNamespace,
},
Data: map[string]string{
"httpProxy": "http://10.0.0.1:8080",
"httpsProxy": "http://10.0.0.1:8080",
"noProxy": "127.0.0.1,foo.com",
},
}
cm.DeepCopyInto(obj.(*corev1.ConfigMap))
}

return nil
}

workloadClusterClient := &fakes.ClusterClient{}
workloadClusterClient.GetResourceStub = func(obj interface{}, name string, namespace string, verifyFunc clusterclient.PostVerifyrFunc, pollOptions *clusterclient.PollOptions) error {
if name == constants.KappControllerConfigMapName {
cm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: constants.KappControllerConfigMapName,
Namespace: constants.KappControllerNamespace,
},
Data: map[string]string{
"httpProxy": "http://10.0.0.1:8081",
"httpsProxy": "http://10.0.0.1:8081",
"noProxy": "127.0.0.1,bar.com",
},
}
cm.DeepCopyInto(obj.(*corev1.ConfigMap))
}

return nil
}

// validate retrieving management cluster settings
err = tkgClient.RetrieveRegionalClusterConfiguration(regionalClusterClient)
g.Expect(err).To(BeNil())

httpProxy, err := tkgClient.TKGConfigReaderWriter().Get(constants.TKGHTTPProxy)
g.Expect(httpProxy).To(Equal("http://10.0.0.1:8080"))
g.Expect(err).To(BeNil())
httpsProxy, err := tkgClient.TKGConfigReaderWriter().Get(constants.TKGHTTPSProxy)
g.Expect(httpsProxy).To(Equal("http://10.0.0.1:8080"))
g.Expect(err).To(BeNil())
noProxy, err := tkgClient.TKGConfigReaderWriter().Get(constants.TKGNoProxy)
g.Expect(noProxy).To(Equal("127.0.0.1,foo.com"))
g.Expect(err).To(BeNil())

// validate retrieving workload cluster settings
err = tkgClient.RetrieveWorkloadClusterConfiguration(regionalClusterClient, workloadClusterClient, "workload-cluster", constants.DefaultNamespace)
g.Expect(err).To(BeNil())

httpProxy, err = tkgClient.TKGConfigReaderWriter().Get(constants.TKGHTTPProxy)
g.Expect(httpProxy).To(Equal("http://10.0.0.1:8081"))
g.Expect(err).To(BeNil())
httpsProxy, err = tkgClient.TKGConfigReaderWriter().Get(constants.TKGHTTPSProxy)
g.Expect(httpsProxy).To(Equal("http://10.0.0.1:8081"))
g.Expect(err).To(BeNil())
noProxy, err = tkgClient.TKGConfigReaderWriter().Get(constants.TKGNoProxy)
g.Expect(noProxy).To(Equal("127.0.0.1,bar.com"))
g.Expect(err).To(BeNil())
}

0 comments on commit 074a3f4

Please # to comment.