Convert the controllerlib tests to use the same structure as our other integration tests.
Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
parent
a503fa8673
commit
1fcf95af01
@ -17,10 +17,12 @@ import (
|
|||||||
|
|
||||||
"github.com/suzerain-io/pinniped/internal/controllerlib/test/integration/examplecontroller/api"
|
"github.com/suzerain-io/pinniped/internal/controllerlib/test/integration/examplecontroller/api"
|
||||||
examplestart "github.com/suzerain-io/pinniped/internal/controllerlib/test/integration/examplecontroller/starter"
|
examplestart "github.com/suzerain-io/pinniped/internal/controllerlib/test/integration/examplecontroller/starter"
|
||||||
"github.com/suzerain-io/pinniped/internal/controllerlib/test/library"
|
"github.com/suzerain-io/pinniped/test/library"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExampleController(t *testing.T) {
|
func TestExampleController(t *testing.T) {
|
||||||
|
library.SkipUnlessIntegration(t)
|
||||||
|
|
||||||
config := library.NewClientConfig(t)
|
config := library.NewClientConfig(t)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2020 VMware, Inc.
|
|
||||||
SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
package integration
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
// force users to opt-in to running the integration tests.
|
|
||||||
// this prevents them from running if someone does `go test ./...`
|
|
||||||
// these tests could be destructive to the cluster under test.
|
|
||||||
const magicIntegrationTestsEnvVar = "CONTROLLER_GO_TEST_INTEGRATION"
|
|
||||||
|
|
||||||
var shouldRunIntegrationTests = func() bool {
|
|
||||||
b, _ := strconv.ParseBool(os.Getenv(magicIntegrationTestsEnvVar))
|
|
||||||
return b
|
|
||||||
}()
|
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
|
||||||
if !shouldRunIntegrationTests {
|
|
||||||
fmt.Printf("SKIP: %s=true env var must be explicitly set for integration tests to run\n", magicIntegrationTestsEnvVar)
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Exit(m.Run())
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
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"
|
|
||||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewClientConfig(t *testing.T) *rest.Config {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
return newClientConfigWithOverrides(t, &clientcmd.ConfigOverrides{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewClientConfigWithCertAndKey(t *testing.T, cert, key string) *rest.Config {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
return newClientConfigWithOverrides(t, &clientcmd.ConfigOverrides{
|
|
||||||
AuthInfo: clientcmdapi.AuthInfo{
|
|
||||||
ClientCertificateData: []byte(cert),
|
|
||||||
ClientKeyData: []byte(key),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func newClientConfigWithOverrides(t *testing.T, overrides *clientcmd.ConfigOverrides) *rest.Config {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
loader := clientcmd.NewDefaultClientConfigLoadingRules()
|
|
||||||
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loader, overrides)
|
|
||||||
config, err := clientConfig.ClientConfig()
|
|
||||||
require.NoError(t, err)
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewClientset(t *testing.T) kubernetes.Interface {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
return NewClientsetWithConfig(t, NewClientConfig(t))
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewClientsetWithConfig(t *testing.T, config *rest.Config) kubernetes.Interface {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
result, err := kubernetes.NewForConfig(config)
|
|
||||||
require.NoError(t, err, "unexpected failure from kubernetes.NewForConfig()")
|
|
||||||
return result
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
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...)
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user