Skip to content

Commit

Permalink
Updating broken test
Browse files Browse the repository at this point in the history
Signed-off-by: suvaanshkumar <[email protected]>
  • Loading branch information
suvaanshkumar committed Jan 7, 2025
1 parent 8fa0860 commit 387a974
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions pkg/registration/register/aws_irsa/aws_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package aws_irsa

import (
"reflect"
"fmt"
"open-cluster-management.io/ocm/test/integration/util"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -49,32 +50,38 @@ func TestBuildKubeconfig(t *testing.T) {
caData []byte
clientCertFile string
clientKeyFile string
hubClusterArn string
AuthInfoExec *clientcmdapi.ExecConfig
}{
{
name: "without proxy",
server: "https://127.0.0.1:6443",
caData: []byte("fake-ca-bundle"),
clientCertFile: "tls.crt",
clientKeyFile: "tls.key",
},
{
name: "with proxy",
server: "https://127.0.0.1:6443",
caData: []byte("fake-ca-bundle-with-proxy-ca"),
proxyURL: "https://127.0.0.1:3129",
clientCertFile: "tls.crt",
clientKeyFile: "tls.key",
name: "without proxy",
server: "https://127.0.0.1:6443",
hubClusterArn: util.HubClusterArn,
AuthInfoExec: &clientcmdapi.ExecConfig{
APIVersion: "client.authentication.k8s.io/v1beta1",
Command: "aws",
Args: []string{
"--region",
"us-west-2",
"eks",
"get-token",
"--cluster-name",
"testCluster",
"--output",
"json",
"--role",
fmt.Sprintf("arn:aws:iam::%s:role/ocm-hub-%s", "12345678910", "testRoleSuffix"),
},
},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
bootstrapKubeconfig := &clientcmdapi.Config{
Clusters: map[string]*clientcmdapi.Cluster{
"default-cluster": {
Server: c.server,
InsecureSkipTLSVerify: false,
CertificateAuthorityData: c.caData,
ProxyURL: c.proxyURL,
Server: c.server,
InsecureSkipTLSVerify: false,
}},
// Define a context that connects the auth info and cluster, and set it as the default
Contexts: map[string]*clientcmdapi.Context{register.DefaultKubeConfigContext: {
Expand All @@ -92,6 +99,7 @@ func TestBuildKubeconfig(t *testing.T) {
}

registerImpl := &AWSIRSADriver{}
registerImpl.hubClusterArn = util.HubClusterArn
kubeconfig := registerImpl.BuildKubeConfigFromTemplate(bootstrapKubeconfig)
currentContext, ok := kubeconfig.Contexts[kubeconfig.CurrentContext]
if !ok {
Expand All @@ -107,26 +115,23 @@ func TestBuildKubeconfig(t *testing.T) {
t.Errorf("expected server %q, but got %q", c.server, cluster.Server)
}

if cluster.ProxyURL != c.proxyURL {
t.Errorf("expected proxy URL %q, but got %q", c.proxyURL, cluster.ProxyURL)
}

if !reflect.DeepEqual(cluster.CertificateAuthorityData, c.caData) {
t.Errorf("expected ca data %v, but got %v", c.caData, cluster.CertificateAuthorityData)
}

authInfo, ok := kubeconfig.AuthInfos[currentContext.AuthInfo]
if !ok {
t.Errorf("auth info %q not found: %v", currentContext.AuthInfo, kubeconfig)
}

if authInfo.ClientCertificate != c.clientCertFile {
t.Errorf("expected client certificate %q, but got %q", c.clientCertFile, authInfo.ClientCertificate)
if authInfo.Exec.APIVersion != c.AuthInfoExec.APIVersion {
t.Errorf("%q is not equal to %q", authInfo.Exec.APIVersion, c.AuthInfoExec.APIVersion)
}

if authInfo.ClientKey != c.clientKeyFile {
t.Errorf("expected client key %q, but got %q", c.clientKeyFile, authInfo.ClientKey)
if authInfo.Exec.Command != c.AuthInfoExec.Command {
t.Errorf("%q is not equal to %q", authInfo.Exec.Command, c.AuthInfoExec.Command)
}

if len(authInfo.Exec.Args) != len(c.AuthInfoExec.Args) {
t.Errorf("Fill in the error")
}

})
}
}

0 comments on commit 387a974

Please sign in to comment.