manifesttestutils

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

README

Manifest Test Library

This package contains some utils for easily parsing installation manifests (i.e. Helm-generated yaml files) and writing tests against those manifests. This is to ensure your Helm chart is properly linted and meets expectations.

Usage

  • Define a test suite that parses a manifest, for example see test/example_suite_test.go.
  • Define a test file that tests the manifest, for example see test/example_test.go.

These tests should be very concise based on the resource builder utilities provided.

Future

In the short term, the goal is increasing test coverage of helm charts that are published by different projects. Some useful extensions in the future would include:

  • Extra utilities for helping test helm charts with different values overrides.

It may make sense to turn this into a Helm chart generator in the future, to the extent that process can be simplified (see github.com/solo-io/build for more info about the Solo common build SDK).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAppLabels

func GetAppLabels(appName, category string) map[string]string

func GetClusterAdminRoleRef

func GetClusterAdminRoleRef() rbacv1.RoleRef

func GetClusterRoleRef

func GetClusterRoleRef(name string) rbacv1.RoleRef

func GetCoreRule

func GetCoreRule() rbacv1.PolicyRule

func GetCrdRule

func GetCrdRule() rbacv1.PolicyRule

func GetDefaultServiceAccountSubject

func GetDefaultServiceAccountSubject(namespace string) rbacv1.Subject

func GetIstioRule

func GetIstioRule() rbacv1.PolicyRule

func GetPodNamespaceEnvVar

func GetPodNamespaceEnvVar() v1.EnvVar

func GetServiceAccountSubject

func GetServiceAccountSubject(namespace, name string) rbacv1.Subject

func MustCanonicalizeYaml

func MustCanonicalizeYaml(input string) string

Types

type ApiGroupPermissions added in v0.10.2

type ApiGroupPermissions struct {
	ApiGroup map[string]*ResourcePermissions
}

type ContainerSpec

type ContainerSpec struct {
	Image      string
	PullPolicy v1.PullPolicy
	Name       string
	Args       []string
	EnvVars    []v1.EnvVar
}

func GetContainerSpec

func GetContainerSpec(registry, name, tag string, envVars ...v1.EnvVar) ContainerSpec

func GetQuayContainerSpec

func GetQuayContainerSpec(image, tag string, envVars ...v1.EnvVar) ContainerSpec

type NamespacePermissions added in v0.10.2

type NamespacePermissions struct {
	Namespace map[string]*ApiGroupPermissions
}

type PortSpec

type PortSpec struct {
	Name string
	Port int
}

type ResourceBuilder

type ResourceBuilder struct {
	Namespace          string
	Name               string
	Args               []string
	Labels             map[string]string
	Annotations        map[string]string
	Rules              []rbacv1.PolicyRule
	Data               map[string]string
	Subjects           []rbacv1.Subject
	RoleRef            rbacv1.RoleRef
	Containers         []ContainerSpec
	Service            ServiceSpec
	SecretType         v1.SecretType
	ServiceAccountName string
}

func (*ResourceBuilder) GetClusterRole

func (b *ResourceBuilder) GetClusterRole() *rbacv1.ClusterRole

func (*ResourceBuilder) GetClusterRoleBinding

func (b *ResourceBuilder) GetClusterRoleBinding() *rbacv1.ClusterRoleBinding

func (*ResourceBuilder) GetClusterRoleRef

func (b *ResourceBuilder) GetClusterRoleRef() rbacv1.RoleRef

func (*ResourceBuilder) GetConfigMap

func (b *ResourceBuilder) GetConfigMap() *v1.ConfigMap

func (*ResourceBuilder) GetDeployment

func (b *ResourceBuilder) GetDeployment() *v1beta1.Deployment

Deprecated

func (*ResourceBuilder) GetDeploymentAppsv1 added in v0.9.11

func (b *ResourceBuilder) GetDeploymentAppsv1() *appsv1.Deployment

func (*ResourceBuilder) GetNamespace

func (b *ResourceBuilder) GetNamespace() *v1.Namespace

func (*ResourceBuilder) GetRole added in v0.9.16

func (b *ResourceBuilder) GetRole() *rbacv1.Role

func (*ResourceBuilder) GetRoleBinding added in v0.9.16

func (b *ResourceBuilder) GetRoleBinding() *rbacv1.RoleBinding

func (*ResourceBuilder) GetSecret

func (b *ResourceBuilder) GetSecret() *v1.Secret

func (*ResourceBuilder) GetService

func (b *ResourceBuilder) GetService() *v1.Service

func (*ResourceBuilder) GetServiceAccount

func (b *ResourceBuilder) GetServiceAccount() *v1.ServiceAccount

func (*ResourceBuilder) GetServiceAccountSubject

func (b *ResourceBuilder) GetServiceAccountSubject() rbacv1.Subject

type ResourcePermissions added in v0.10.2

type ResourcePermissions struct {
	Resource map[string]*Verbs
}

type ServiceAccountPermissions added in v0.10.1

type ServiceAccountPermissions struct {
	ServiceAccount map[string]*NamespacePermissions
}

func (*ServiceAccountPermissions) AddExpectedPermission added in v0.10.1

func (p *ServiceAccountPermissions) AddExpectedPermission(serviceAccount, namespace string, apiGroups, resources, verbs []string)

type ServiceSpec

type ServiceSpec struct {
	Ports []PortSpec
}

type TestManifest

type TestManifest interface {
	// Deprecated
	ExpectDeployment(deployment *v1beta1.Deployment) *v1beta1.Deployment
	ExpectDeploymentAppsV1(deployment *appsv1.Deployment)
	ExpectServiceAccount(serviceAccount *corev1.ServiceAccount)
	ExpectClusterRole(clusterRole *rbacv1.ClusterRole)
	ExpectClusterRoleBinding(clusterRoleBinding *rbacv1.ClusterRoleBinding)
	ExpectRole(role *rbacv1.Role)
	ExpectRoleBinding(roleBinding *rbacv1.RoleBinding)
	ExpectConfigMap(configMap *corev1.ConfigMap)
	ExpectConfigMapWithYamlData(configMap *corev1.ConfigMap)
	ExpectSecret(secret *corev1.Secret)
	ExpectService(service *corev1.Service)
	ExpectNamespace(namespace *corev1.Namespace)
	ExpectCrd(crd *extv1beta1.CustomResourceDefinition)
	ExpectCustomResource(gvk, namespace, name string) *unstructured.Unstructured
	NumResources() int

	Expect(kind, namespace, name string) Assertion
	ExpectUnstructured(kind, namespace, name string) Assertion

	ExpectPermissions(permissions *ServiceAccountPermissions)

	// run this callback on all the resources contained in this TestManifest
	ExpectAll(callback func(*unstructured.Unstructured))

	// construct a new set of resources to make assertions against by collecting
	// all the resources for which `selector` returns true
	SelectResources(selector func(*unstructured.Unstructured) bool) TestManifest
}

func NewTestManifest

func NewTestManifest(relativePathToManifest string) TestManifest

func NewTestManifestWithResources

func NewTestManifestWithResources(resources kuberesource.UnstructuredResources) TestManifest

type Verbs added in v0.10.2

type Verbs struct {
	Values map[string]bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL