2020-07-31 16:08:07 +00:00
|
|
|
/*
|
|
|
|
Copyright 2020 VMware, Inc.
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/base64"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/client-go/rest"
|
|
|
|
|
2020-08-20 17:54:15 +00:00
|
|
|
crdpinnipedv1alpha1 "github.com/suzerain-io/pinniped/kubernetes/1.19/api/apis/crdpinniped/v1alpha1"
|
|
|
|
"github.com/suzerain-io/pinniped/test/library"
|
2020-07-31 16:08:07 +00:00
|
|
|
)
|
|
|
|
|
2020-08-20 17:54:15 +00:00
|
|
|
func TestSuccessfulPinnipedDiscoveryInfo(t *testing.T) {
|
2020-08-07 01:44:14 +00:00
|
|
|
library.SkipUnlessIntegration(t)
|
2020-08-20 17:54:15 +00:00
|
|
|
namespaceName := library.Getenv(t, "PINNIPED_NAMESPACE")
|
2020-07-31 16:08:07 +00:00
|
|
|
|
2020-08-20 17:54:15 +00:00
|
|
|
client := library.NewPinnipedClientset(t)
|
2020-07-31 16:08:07 +00:00
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
config := library.NewClientConfig(t)
|
2020-08-03 18:36:08 +00:00
|
|
|
expectedLDCSpec := expectedLDCSpec(config)
|
2020-07-31 16:08:07 +00:00
|
|
|
configList, err := client.
|
2020-08-20 17:54:15 +00:00
|
|
|
CrdV1alpha1().
|
|
|
|
PinnipedDiscoveryInfos(namespaceName).
|
2020-07-31 16:08:07 +00:00
|
|
|
List(ctx, metav1.ListOptions{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, configList.Items, 1)
|
2020-07-31 21:35:20 +00:00
|
|
|
require.Equal(t, expectedLDCSpec, &configList.Items[0].Spec)
|
2020-07-31 16:08:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-20 17:54:15 +00:00
|
|
|
func TestReconcilingPinnipedDiscoveryInfo(t *testing.T) {
|
2020-08-07 01:44:14 +00:00
|
|
|
library.SkipUnlessIntegration(t)
|
2020-08-20 17:54:15 +00:00
|
|
|
namespaceName := library.Getenv(t, "PINNIPED_NAMESPACE")
|
2020-07-31 16:08:07 +00:00
|
|
|
|
2020-08-20 17:54:15 +00:00
|
|
|
client := library.NewPinnipedClientset(t)
|
2020-07-31 16:08:07 +00:00
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
2020-07-31 21:35:20 +00:00
|
|
|
err := client.
|
2020-08-20 17:54:15 +00:00
|
|
|
CrdV1alpha1().
|
|
|
|
PinnipedDiscoveryInfos(namespaceName).
|
|
|
|
Delete(ctx, "pinniped-config", metav1.DeleteOptions{})
|
2020-07-31 16:08:07 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
config := library.NewClientConfig(t)
|
2020-08-03 18:36:08 +00:00
|
|
|
expectedLDCSpec := expectedLDCSpec(config)
|
2020-07-31 21:35:20 +00:00
|
|
|
|
2020-08-20 17:54:15 +00:00
|
|
|
var actualLDC *crdpinnipedv1alpha1.PinnipedDiscoveryInfo
|
2020-07-31 21:35:20 +00:00
|
|
|
for i := 0; i < 10; i++ {
|
2020-08-01 00:22:12 +00:00
|
|
|
actualLDC, err = client.
|
2020-08-20 17:54:15 +00:00
|
|
|
CrdV1alpha1().
|
|
|
|
PinnipedDiscoveryInfos(namespaceName).
|
|
|
|
Get(ctx, "pinniped-config", metav1.GetOptions{})
|
2020-07-31 21:35:20 +00:00
|
|
|
if err == nil {
|
|
|
|
break
|
2020-07-31 16:08:07 +00:00
|
|
|
}
|
2020-07-31 21:35:20 +00:00
|
|
|
time.Sleep(time.Millisecond * 750)
|
2020-07-31 16:08:07 +00:00
|
|
|
}
|
2020-07-31 21:35:20 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expectedLDCSpec, &actualLDC.Spec)
|
2020-07-31 16:08:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-20 17:54:15 +00:00
|
|
|
func expectedLDCSpec(config *rest.Config) *crdpinnipedv1alpha1.PinnipedDiscoveryInfoSpec {
|
|
|
|
return &crdpinnipedv1alpha1.PinnipedDiscoveryInfoSpec{
|
2020-08-03 18:36:08 +00:00
|
|
|
Server: config.Host,
|
2020-07-31 21:35:20 +00:00
|
|
|
CertificateAuthorityData: base64.StdEncoding.EncodeToString(config.TLSClientConfig.CAData),
|
2020-07-31 16:08:07 +00:00
|
|
|
}
|
|
|
|
}
|