2020-09-16 14:19:51 +00:00
|
|
|
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2020-08-25 12:26:42 +00:00
|
|
|
|
2020-08-25 01:07:34 +00:00
|
|
|
package library
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2020-08-26 01:22:53 +00:00
|
|
|
"sigs.k8s.io/yaml"
|
2020-08-25 01:07:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type TestClusterCapability string
|
|
|
|
|
|
|
|
const (
|
|
|
|
ClusterSigningKeyIsAvailable = TestClusterCapability("clusterSigningKeyIsAvailable")
|
|
|
|
)
|
|
|
|
|
|
|
|
type capabilitiesConfig struct {
|
|
|
|
Capabilities map[TestClusterCapability]bool `yaml:"capabilities,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func ClusterHasCapability(t *testing.T, capability TestClusterCapability) bool {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
capabilitiesDescriptionYAML := os.Getenv("PINNIPED_CLUSTER_CAPABILITY_YAML")
|
|
|
|
capabilitiesDescriptionFile := os.Getenv("PINNIPED_CLUSTER_CAPABILITY_FILE")
|
|
|
|
require.NotEmptyf(t,
|
|
|
|
capabilitiesDescriptionYAML+capabilitiesDescriptionFile,
|
|
|
|
"must specify either PINNIPED_CLUSTER_CAPABILITY_YAML or PINNIPED_CLUSTER_CAPABILITY_FILE env var for integration tests",
|
|
|
|
)
|
|
|
|
|
|
|
|
if capabilitiesDescriptionYAML == "" {
|
|
|
|
bytes, err := ioutil.ReadFile(capabilitiesDescriptionFile)
|
|
|
|
capabilitiesDescriptionYAML = string(bytes)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var capabilities capabilitiesConfig
|
|
|
|
err := yaml.Unmarshal([]byte(capabilitiesDescriptionYAML), &capabilities)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
isCapable, capabilityWasDescribed := capabilities.Capabilities[capability]
|
|
|
|
require.True(t, capabilityWasDescribed, `the cluster's "%s" capability was not described`, capability)
|
|
|
|
|
|
|
|
return isCapable
|
|
|
|
}
|
|
|
|
|
|
|
|
func SkipUnlessClusterHasCapability(t *testing.T, capability TestClusterCapability) {
|
|
|
|
t.Helper()
|
|
|
|
if !ClusterHasCapability(t, capability) {
|
|
|
|
t.Skipf(`skipping integration test because cluster lacks the "%s" capability`, capability)
|
|
|
|
}
|
|
|
|
}
|
2020-08-26 01:22:53 +00:00
|
|
|
|
|
|
|
func SkipWhenClusterHasCapability(t *testing.T, capability TestClusterCapability) {
|
|
|
|
t.Helper()
|
|
|
|
if ClusterHasCapability(t, capability) {
|
|
|
|
t.Skipf(`skipping integration test because cluster has the "%s" capability`, capability)
|
|
|
|
}
|
|
|
|
}
|