This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Wenqi Qiu <[email protected]>
- Loading branch information
Showing
15 changed files
with
1,522 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/vmware-tanzu/tanzu-framework/apis/addonconfigs/cni/v1alpha2" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
) | ||
|
||
func TestGetNSXCert(t *testing.T) { | ||
fakeClient := fake.NewFakeClientWithScheme(scheme.Scheme) | ||
|
||
secretName := "test-secret" | ||
secretNamespace := "test-namespace" | ||
testSecret := &corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: secretName, | ||
Namespace: secretNamespace, | ||
}, | ||
Data: map[string][]byte{ | ||
"tls.crt": []byte("fake-certificate-data"), | ||
"tls.key": []byte("fake-key-data"), | ||
}, | ||
} | ||
if err := fakeClient.Create(context.Background(), testSecret); err != nil { | ||
t.Fatalf("failed to create test secret: %v", err) | ||
} | ||
|
||
returnedSecret, err := getNSXCert(fakeClient, secretName, secretNamespace) | ||
require.NoError(t, err, "getNSXCert returned an unexpected error") | ||
require.NotNil(t, returnedSecret, "getNSXCert returned a nil secret") | ||
|
||
assert.Equal(t, secretName, returnedSecret.Name, "returned secret has unexpected name") | ||
assert.Equal(t, secretNamespace, returnedSecret.Namespace, "returned secret has unexpected namespace") | ||
assert.Equal(t, 2, len(returnedSecret.Data), "returned secret has unexpected number of data fields") | ||
|
||
if _, ok := returnedSecret.Data["tls.crt"]; !ok { | ||
t.Error("returned secret missing tls.crt field") | ||
} | ||
if _, ok := returnedSecret.Data["tls.key"]; !ok { | ||
t.Error("returned secret missing tls.key field") | ||
} | ||
} | ||
|
||
func TestCopyStruct(t *testing.T) { | ||
ccpConf := v1alpha2.CcpAdapterConf{ | ||
EnableDebugServer: true, | ||
APIServerPort: 1234, | ||
} | ||
descCcpAdapterConf := ccpAdapterConf{ | ||
EnableDebugServer: false, | ||
APIServerPort: 0, | ||
} | ||
err := copyStructAtoB(ccpConf, &descCcpAdapterConf) | ||
require.NoError(t, err, "copy CcpAdapterConf values error") | ||
assert.Equal(t, 1234, descCcpAdapterConf.APIServerPort) | ||
assert.Equal(t, true, descCcpAdapterConf.EnableDebugServer) | ||
|
||
mpConf := v1alpha2.MpAdapterConf{ | ||
NSXClientAuthCertFile: "fake-cert-file", | ||
ConditionTimeout: 150, | ||
} | ||
descMpAdapterConf := mpAdapterConf{ | ||
NSXClientAuthCertFile: "", | ||
ConditionTimeout: 0, | ||
} | ||
err = copyStructAtoB(mpConf, &descMpAdapterConf) | ||
require.NoError(t, err, "copy MpAdapterConf values error") | ||
assert.Equal(t, "fake-cert-file", descMpAdapterConf.NSXClientAuthCertFile) | ||
assert.Equal(t, 150, descMpAdapterConf.ConditionTimeout) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.