Documentation ¶
Overview ¶
testhelpers contains helpers for tests
Index ¶
- Constants
- Variables
- func BuildManifestFile(inputFolderPath string, outputFolderPath string, targetType string, ...) error
- func Cleanup(testName string)
- func CleanupManifests(ctx context.Context) error
- func CleanupWithTunnel(cancel context.CancelFunc, tunnelPid int, testName string)
- func DumpClusterState(ctx context.Context)
- func EnsureNamespace(namespace string) error
- func KubeClient() (*kubernetes.Clientset, error)
- func PatchInstance(data []byte, opts InstanceOptions) ([]byte, error)
- func PatchSolution(data []byte, opts SolutionOptions) ([]byte, error)
- func PatchSolutionContainer(data []byte, opts ContainerOptions) ([]byte, error)
- func PatchTarget(data []byte, opts TargetOptions) ([]byte, error)
- func RestConfig() (*rest.Config, error)
- func SetupCluster() error
- func SetupClusterWithTunnel() (context.CancelFunc, int, error)
- func ShellExec(cmd string) error
- type Array
- type Binding
- type ComponentSpec
- type Config
- type ContainerOptions
- type HelmValues
- type Instance
- type InstanceOptions
- type InstanceSpec
- type Map
- type Metadata
- type ParameterDefinition
- type Solution
- type SolutionContainer
- type SolutionContainerSpec
- type SolutionOptions
- type SolutionSpec
- type Target
- type TargetOptions
- type TargetSelector
- type TargetSpec
- type Topology
Constants ¶
const (
AzureOperationIdKey = "management.azure.com/operationId"
)
Variables ¶
var ( ComponetsMap = map[string]ComponentSpec{ "simple-chart-1": { Name: "simple-chart-1", Properties: Map{ "chart": Map{ "repo": "ghcr.io/eclipse-symphony/tests/helm/simple-chart", "version": "0.3.0", }, }, Type: "helm.v3", }, "simple-chart-1-nonexistent": { Name: "simple-chart-1", Properties: Map{ "chart": Map{ "repo": "ghcr.io/eclipse-symphony/tests/helm/simple-chart", "version": "0.3.0-nonexistent", }, }, Type: "helm.v3", }, "simple-chart-1-with-values": { Name: "simple-chart-1", Properties: Map{ "chart": Map{ "repo": "ghcr.io/eclipse-symphony/tests/helm/simple-chart", "version": "0.3.0", }, "values": Map{ "configData": Map{ "key": "value", }, }, }, Type: "helm.v3", }, "simple-chart-2": { Name: "simple-chart-2", Properties: Map{ "chart": Map{ "repo": "ghcr.io/eclipse-symphony/tests/helm/simple-chart", "version": "0.3.0", }, }, Type: "helm.v3", }, "simple-chart-2-nonexistent": { Name: "simple-chart-2", Properties: Map{ "chart": Map{ "repo": "ghcr.io/eclipse-symphony/tests/helm/simple-chart", "version": "0.3.0-non-existent", }, }, Type: "helm.v3", }, "mongodb-configmap": { Name: "mongodb", Type: "yaml.k8s", Properties: Map{ "resource": Map{ "apiVersion": "v1", "kind": "ConfigMap", "metadata": Map{ "name": "mongodb", }, "data": Map{ "database": "mongodb", "database_uri": "mongodb://localhost:27017", }, }, }, }, "mongodb-configmap-modified": { Name: "mongodb", Type: "yaml.k8s", Properties: Map{ "resource": Map{ "apiVersion": "v1", "kind": "ConfigMap", "metadata": Map{ "name": "mongodb", }, "data": Map{ "database": "mongodb", "database_uri": "mongodb://localhost:27020", }, }, }, }, "mongodb-constraint": { Name: "mongodb-constraint", Type: "yaml.k8s", Properties: Map{ "resource": Map{ "apiVersion": "v1", "kind": "ConfigMap", "metadata": Map{ "name": "mongodb-constraint", }, "data": Map{ "database": "mongodb", "database_uri": "mongodb://localhost:27017", }, }, }, Constraints: "${{$equal($property('OS'),'windows')}}", }, "nginx": { Name: "nginx", Properties: Map{ "resource": Map{ "apiVersion": "apps/v1", "kind": "Deployment", "metadata": Map{ "name": "nginx", }, "spec": Map{ "replicas": int64(1), "selector": Map{ "matchLabels": Map{ "app": "nginx", }, }, "template": Map{ "metadata": Map{ "labels": Map{ "app": "nginx", }, }, "spec": Map{ "containers": []Map{ { "image": "nginx:1.21", "name": "nginx", "ports": Array{ Map{"containerPort": int64(80)}, }, }, }, }, }, }, }, }, Type: "yaml.k8s", }, "basic-clusterrole": { Name: "basic-clusterrole", Properties: Map{ "resource": Map{ "apiVersion": "rbac.authorization.k8s.io/v1", "kind": "ClusterRole", "metadata": Map{ "name": "basic-clusterrole", }, "rules": Array{ Map{ "apiGroups": Array{ "apps", }, "resources": Array{ "deployments", }, "verbs": Array{ "get", "list", "watch", "create", "update", }, }, }, }, }, Type: "yaml.k8s", }, "basic-configmap-1": { Name: "basic-configmap-1", Properties: Map{ "resource": Map{ "apiVersion": "v1", "kind": "ConfigMap", "metadata": Map{ "name": "basic-configmap-1", }, "data": Map{ "key": "value", }, }, }, Type: "yaml.k8s", }, "basic-configmap-1-modified": { Name: "basic-configmap-1", Properties: Map{ "resource": Map{ "apiVersion": "v1", "kind": "ConfigMap", "metadata": Map{ "name": "basic-configmap-1", }, "data": Map{ "key": "value-modified", }, }, }, Type: "yaml.k8s", }, "basic-configmap-1-params": { Name: "basic-configmap-1", Properties: Map{ "resource": Map{ "apiVersion": "v1", "kind": "ConfigMap", "metadata": Map{ "name": "basic-configmap-1", }, "data": Map{ "database": "@{{ $param('database')}}", "database_uri": "@{{ $param('database_uri')}}", }, }, }, Type: "yaml.k8s", }, "basic-configmap-1-params-modified": { Name: "basic-configmap-1", Properties: Map{ "resource": Map{ "apiVersion": "v1", "kind": "ConfigMap", "metadata": Map{ "name": "basic-configmap-1", }, "data": Map{ "uri": "${{ $param('test')}}", }, }, }, Type: "yaml.k8s", }, "foobar-crd": { Name: "foobar-crd", Properties: Map{ "resource": Map{ "apiVersion": "apiextensions.k8s.io/v1", "kind": "CustomResourceDefinition", "metadata": Map{ "name": "foobars.contoso.io", }, "spec": Map{ "group": "contoso.io", "version": "v1", "scope": "Namespaced", "names": Map{ "plural": "foobars", "singular": "foobar", "kind": "FooBar", "shortNames": Array{ "fb", }, }, "versions": Array{ Map{ "name": "v1", "served": true, "storage": true, "schema": Map{ "openAPIV3Schema": Map{ "type": "object", "properties": Map{ "spec": Map{ "type": "object", "properties": Map{ "foo": Map{ "type": "string", }, "bar": Map{ "type": "string", }, }, }, }, }, }, }, }, }, }, "statusProbe": Map{ "succeededValues": Array{"True"}, "statusPath": `$.status.conditions[?(@.type == "Established")].status`, "initialWait": "5s", }, }, Type: "yaml.k8s", }, "simple-foobar": { Name: "simple-foobar", Properties: Map{ "resource": Map{ "apiVersion": "contoso.io/v1", "kind": "FooBar", "metadata": Map{ "name": "simple-foobar", }, "spec": Map{ "foo": "foo", "bar": "bar", }, }, }, Type: "yaml.k8s", Dependencies: []string{ "foobar-crd", }, }, "expressions-1": { Name: "expressions-1", Properties: Map{ "chart": Map{ "repo": "ghcr.io/eclipse-symphony/tests/helm/simple-chart", "version": "0.3.0", }, "foo": `@{{ $property("color") + ' ' + $property("OS") }}`, "testGtNumbers": `@{{ $gt("2", 1.0)}}`, "testGeNumbers": `@{{ $ge(2, "1.0")}}`, "testLtNumbers": `@{{ $lt("2", 1.0)}}`, "testLeNumbers": `@{{ $le(2, "1.0")}}`, "testBetweenNumbers": `@{{ $between(2, "1", 3)}}`, }, Type: "helm.v3", }, "expressions-1-failed": { Name: "expressions-1", Properties: Map{ "chart": Map{ "repo": "ghcr.io/eclipse-symphony/tests/helm/simple-chart", "version": "0.3.0", }, "foo": `${{ $property("will-fail") + ' ' + $property("OS") }}`, "testGtNumbers": `${{ $gt("2", 1.0)}}`, "testGeNumbers": `${{ $ge(2, "1.0")}}`, "testLtNumbers": `${{ $lt("2", 1.0)}}`, "testLeNumbers": `${{ $le(2, "1.0")}}`, "testBetweenNumbers": `${{ $between(2, "1", 3)}}`, }, Type: "helm.v3", }, "expressions-1-soln": { Name: "expressions-1-soln", Properties: Map{ "resource": Map{ "apiVersion": "v1", "kind": "ConfigMap", "metadata": Map{ "name": "expressions-1-soln", "foo": `@{{ $property("color") + ' ' + $property("OS") }}`, "normalString": `This is interpreted as a normal string @{{ $property("wont-fail") }}`, "testEqualNumbers": `@{{ $equal(123, 123) }}`, "testNotTrue": `@{{ $not("true")}}`, "testNotNotTrue": `@{{ $not($not(true))}}`, "testPropertyAnd": `@{{ $and($equal($property("OS"), "windows") , $equal("yes", "no"))}}`, "testPropertyOr": `@{{ $or($equal($property("OS"), "windows") , $equal("yes", "no"))}}`, }, }, }, Type: "yaml.k8s", }, "expressions-1-soln-failed": { Name: "expressions-1-soln", Properties: Map{ "chart": Map{ "repo": "ghcr.io/eclipse-symphony/tests/helm/simple-chart", "version": "0.3.0", }, "name": "expressions-1-soln", "foo": `@{{ $property("will-fail") + ' ' + $property("OS") }}`, "normalString": `This is interpreted as a normal string @{{ $property("wont-fail") }}`, "testEqualNumbers": `@{{ $equal(123, 123) }}`, "testNotTrue": `@{{ $not("true")}}`, "testNotNotTrue": `@{{ $not($not(true))}}`, "testPropertyAnd": `@{{ $and($equal($property("OS"), "windows") , $equal("yes", "no"))}}`, "testPropertyOr": `@{{ $or($equal($property("OS"), "windows") , $equal("yes", "no"))}}`, }, Type: "helm.v3", }, "simple-http": { Name: "simple-http", Properties: Map{ "http.url": "https://learn.microsoft.com/en-us/content-nav/azure.json?", "http.method": "GET", }, Type: "http", }, "simple-http-invalid-url": { Name: "simple-http", Properties: Map{ "http.url": "https://learn.microsoft.com/en-us/test/invalid/url", "http.method": "GET", }, Type: "http", }, "nginx-ingress": { Name: "proxy", Properties: map[string]interface{}{ "chart": map[string]interface{}{ "repo": "ghcr.io/nginxinc/charts/nginx-ingress", "version": "0.18.1", }, }, Type: "helm.v3", }, "redis": { Name: "redis", Properties: map[string]interface{}{ "container.image": "redis:latest", }, Type: "container", }, "bitnami-nginx": { Name: "nginx", Properties: map[string]interface{}{ "chart": map[string]interface{}{ "name": "nginx", "repo": "https://charts.bitnami.com/bitnami", "version": "18.1.7", }, }, Type: "helm.v3", }, "prometheus-server": { Name: "prometheus-server", Properties: map[string]interface{}{ "container.image": "prom/prometheus", }, Type: "container", }, } )
Todo: Switch over to symphony core types from the /k8s/api folder
Functions ¶
func BuildManifestFile ¶
func BuildManifestFile(inputFolderPath string, outputFolderPath string, targetType string, components []string) error
BuildManifestFile modifies the target/solution manifest files
func CleanupManifests ¶
func CleanupWithTunnel ¶
func CleanupWithTunnel(cancel context.CancelFunc, tunnelPid int, testName string)
func DumpClusterState ¶
func EnsureNamespace ¶
Ensures that the namespace exists. If it does not exist, it creates it.
func KubeClient ¶
func KubeClient() (*kubernetes.Clientset, error)
KubeClient returns the kubectl client
func PatchInstance ¶
func PatchInstance(data []byte, opts InstanceOptions) ([]byte, error)
func PatchSolution ¶
func PatchSolution(data []byte, opts SolutionOptions) ([]byte, error)
func PatchSolutionContainer ¶
func PatchSolutionContainer(data []byte, opts ContainerOptions) ([]byte, error)
func PatchTarget ¶
func PatchTarget(data []byte, opts TargetOptions) ([]byte, error)
func SetupCluster ¶
func SetupCluster() error
Prepare the cluster Run this manually to prepare your local environment for testing/debugging
func SetupClusterWithTunnel ¶
func SetupClusterWithTunnel() (context.CancelFunc, int, error)
Types ¶
type Binding ¶
type Binding struct { Config Config `yaml:"config"` Provider string `yaml:"provider"` Role string `yaml:"role"` }
TODO: Switch over to symphony core types from the /k8s/api folder
type ComponentSpec ¶
type ComponentSpec struct { Name string `yaml:"name"` Parameters map[string]ParameterDefinition `yaml:"parameters,omitempty"` Properties map[string]interface{} `yaml:"properties"` Type string `yaml:"type"` Constraints string `yaml:"constraints,omitempty"` Dependencies []string `yaml:"dependencies,omitempty"` }
TODO: Switch over to symphony core types from the /k8s/api folder
type Config ¶
type Config struct { InCluster string `yaml:"inCluster"` NoWait string `yaml:"noWait"` Timeout string `yaml:"timeout"` }
TODO: Switch over to symphony core types from the /k8s/api folder
type ContainerOptions ¶
type ContainerOptions = struct {
Namespace string
}
type HelmValues ¶
type HelmValues map[string]interface{}
func (HelmValues) String ¶
func (h HelmValues) String() string
type Instance ¶
type Instance struct { ApiVersion string `yaml:"apiVersion"` Kind string `yaml:"kind"` Metadata Metadata `yaml:"metadata"` Spec InstanceSpec `yaml:"spec"` }
TODO: Switch over to symphony core types from the /k8s/api folder
type InstanceOptions ¶
type InstanceSpec ¶
type InstanceSpec struct { DisplayName string `yaml:"displayName"` Target TargetSelector `yaml:"target"` Solution string `yaml:"solution"` Scope string `yaml:"scope"` Parameters map[string]interface{} `yaml:"parameters,omitempty"` }
TODO: Switch over to symphony core types from the /k8s/api folder
type Metadata ¶
type Metadata struct { Annotations map[string]string `yaml:"annotations,omitempty"` Name string `yaml:"name,omitempty"` Namespace string `yaml:"namespace,omitempty"` }
TODO: Switch over to symphony core types from the /k8s/api folder
type ParameterDefinition ¶
type ParameterDefinition struct { Type string `yaml:"type"` DefaultValue interface{} `yaml:"default"` }
TODO: Switch over to symphony core types from the /k8s/api folder
type Solution ¶
type Solution struct { ApiVersion string `yaml:"apiVersion"` Kind string `yaml:"kind"` Metadata Metadata `yaml:"metadata"` Spec SolutionSpec `yaml:"spec"` }
Solution describes the structure of symphony solution yaml file
type SolutionContainer ¶
type SolutionContainer struct { ApiVersion string `yaml:"apiVersion"` Kind string `yaml:"kind"` Metadata Metadata `yaml:"metadata"` Spec SolutionContainerSpec `yaml:"spec"` }
TODO: Switch over to symphony core types from the /k8s/api folder
type SolutionContainerSpec ¶
type SolutionContainerSpec struct { }
TODO: Switch over to symphony core types from the /k8s/api folder
type SolutionOptions ¶
type SolutionSpec ¶
type SolutionSpec struct { DisplayName string `yaml:"displayName,omitempty"` Scope string `yaml:"scope,omitempty"` Metadata map[string]string `yaml:"metadata,omitempty"` Components []ComponentSpec `yaml:"components,omitempty"` RootResource string `yaml:"rootResource"` }
TODO: Switch over to symphony core types from the /k8s/api folder
type Target ¶
type Target struct { ApiVersion string `yaml:"apiVersion"` Kind string `yaml:"kind"` Metadata Metadata `yaml:"metadata"` Spec TargetSpec `yaml:"spec"` }
Target describes the structure of symphony target yaml file
type TargetOptions ¶
type TargetSelector ¶
type TargetSelector struct { Name string `yaml:"name,omitempty"` Selector map[string]string `yaml:"selector,omitempty"` }
TODO: Switch over to symphony core types from the /k8s/api folder
type TargetSpec ¶
type TargetSpec struct { DisplayName string `yaml:"displayName"` Scope string `yaml:"scope"` Components []ComponentSpec `yaml:"components,omitempty"` Topologies []Topology `yaml:"topologies"` Properties map[string]string `yaml:"properties,omitempty"` }
TODO: Switch over to symphony core types from the /k8s/api folder