mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-01-08 15:21:55 +00:00
Add integration test to check app is running
Signed-off-by: Monis Khan <mok@vmware.com>
This commit is contained in:
35
test/integration/deployment_test.go
Normal file
35
test/integration/deployment_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright 2020 VMware, Inc.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/suzerain-io/placeholder-name/test/library"
|
||||
)
|
||||
|
||||
const appNamespace = "integration"
|
||||
|
||||
func TestGetDeployment(t *testing.T) {
|
||||
client := library.NewClientset(t)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
appDeployment, err := client.AppsV1().Deployments(appNamespace).Get(ctx, appNamespace, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
cond := library.GetDeploymentCondition(appDeployment.Status, appsv1.DeploymentAvailable)
|
||||
require.NotNil(t, cond)
|
||||
require.Equalf(t, corev1.ConditionTrue, cond.Status, "app should be available: %s", library.Sdump(appDeployment))
|
||||
}
|
||||
32
test/library/client.go
Normal file
32
test/library/client.go
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright 2020 VMware, Inc.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package library
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
func NewClientConfig(t *testing.T) *rest.Config {
|
||||
t.Helper()
|
||||
|
||||
loader := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loader, &clientcmd.ConfigOverrides{})
|
||||
config, err := clientConfig.ClientConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
func NewClientset(t *testing.T) kubernetes.Interface {
|
||||
t.Helper()
|
||||
|
||||
return kubernetes.NewForConfigOrDie(NewClientConfig(t))
|
||||
}
|
||||
20
test/library/deployment.go
Normal file
20
test/library/deployment.go
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
Copyright 2020 VMware, Inc.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package library
|
||||
|
||||
import appsv1 "k8s.io/api/apps/v1"
|
||||
|
||||
// GetDeploymentCondition returns the condition with the provided type.
|
||||
// Copied from k8s.io/kubectl/pkg/util/deployment/deployment.go to prevent us from vendoring the world.
|
||||
func GetDeploymentCondition(status appsv1.DeploymentStatus, condType appsv1.DeploymentConditionType) *appsv1.DeploymentCondition {
|
||||
for i := range status.Conditions {
|
||||
c := status.Conditions[i]
|
||||
if c.Type == condType {
|
||||
return &c
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
23
test/library/spew.go
Normal file
23
test/library/spew.go
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright 2020 VMware, Inc.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package library
|
||||
|
||||
import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
func Sdump(a ...interface{}) string {
|
||||
config := spew.ConfigState{
|
||||
Indent: "\t",
|
||||
MaxDepth: 10, // prevent log explosion
|
||||
DisableMethods: true,
|
||||
DisablePointerMethods: true,
|
||||
DisablePointerAddresses: true,
|
||||
DisableCapacities: true,
|
||||
ContinueOnMethod: true,
|
||||
SortKeys: true,
|
||||
SpewKeys: true,
|
||||
}
|
||||
return config.Sdump(a...)
|
||||
}
|
||||
Reference in New Issue
Block a user