e2e

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultNamespace = "gingersnap-operator-system"
)

Variables

View Source
var (
	OperatorNamespace    = EnvWithDefault("TEST_OPERATOR_NAMESPACE", DefaultNamespace)
	Namespace            = EnvWithDefault("TEST_NAMESPACE", DefaultNamespace)
	CleanupTestNamespace = EnvWithDefaultBool("TEST_NAMESPACE_DELETE", true)
	OutputDir            = EnvWithDefault("TEST_OUTPUT_DIR", os.TempDir()+"/gingersnap-operator")

	MultiNamespace = Namespace != OperatorNamespace
)
View Source
var MysqlConfigMap = &corev1.ConfigMap{
	ObjectMeta: metav1.ObjectMeta{
		Name:      "mysql",
		Namespace: Namespace,
	},
	Data: map[string]string{"setup.sql": `
create schema debezium;
create table debezium.customer(id int not null, fullname varchar(255), email varchar(255), constraint primary key (id));
create table debezium.car_model(id int not null, model varchar(255), brand varchar(255), constraint primary key (id));
GRANT SELECT, RELOAD, SHOW DATABASES, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'gingersnap_user';
`},
}
View Source
var MysqlConnectionSecret = &corev1.Secret{
	ObjectMeta: metav1.ObjectMeta{
		Name:      "db-credentials",
		Namespace: Namespace,
	},
	StringData: map[string]string{
		"host":     fmt.Sprintf("%s.%s.svc.cluster.local", MysqlService.Name, MysqlService.Namespace),
		"port":     "3306",
		"username": "gingersnap_user",
		"password": "password",
		"database": "debezium",
	},
}
View Source
var MysqlDeployment = &appsv1.Deployment{
	ObjectMeta: metav1.ObjectMeta{
		Name:      "mysql",
		Namespace: Namespace,
		Labels:    mysqlLabels,
	},
	Spec: appsv1.DeploymentSpec{
		Selector: &metav1.LabelSelector{
			MatchLabels: mysqlLabels,
		},
		Template: corev1.PodTemplateSpec{
			ObjectMeta: metav1.ObjectMeta{
				Labels: mysqlLabels,
			},
			Spec: corev1.PodSpec{
				Containers: []corev1.Container{{
					Name:  "mysql",
					Image: "mysql:latest",
					Args:  []string{"--default-authentication-plugin=mysql_native_password"},
					Env: []corev1.EnvVar{
						{Name: "MYSQL_ROOT_PASSWORD", Value: "root"},
						{Name: "MYSQL_USER", Value: "gingersnap_user"},
						{Name: "MYSQL_PASSWORD", Value: "password"},
					},
					Ports: []corev1.ContainerPort{{
						ContainerPort: 3306,
					}},
					VolumeMounts: []corev1.VolumeMount{{
						Name:      "init-db",
						MountPath: "/docker-entrypoint-initdb.d",
						ReadOnly:  true,
					}},
				}},
				Volumes: []corev1.Volume{{
					Name: "init-db",
					VolumeSource: corev1.VolumeSource{
						ConfigMap: &corev1.ConfigMapVolumeSource{
							LocalObjectReference: corev1.LocalObjectReference{
								Name: MysqlConfigMap.Name,
							},
						},
					},
				}},
			},
		},
	},
}
View Source
var MysqlService = &corev1.Service{
	ObjectMeta: metav1.ObjectMeta{
		Name:      "mysql",
		Namespace: Namespace,
	},
	Spec: corev1.ServiceSpec{
		Type: corev1.ServiceTypeClusterIP,
		Ports: []corev1.ServicePort{{
			Port:     3306,
			Protocol: corev1.ProtocolTCP,
		}},
		Selector: MysqlDeployment.Labels,
	},
}

Functions

func EnvWithDefault

func EnvWithDefault(name, defValue string) string

EnvWithDefault return os.Getenv(name) if exists else return defValue

func EnvWithDefaultBool

func EnvWithDefaultBool(name string, defValue bool) bool

EnvWithDefaultBool return os.Getenv(name) if exists else return defValue

func WithDefault

func WithDefault(value, defValue string) string

WithDefault return value if not empty else return defValue

Types

type TestClient

type TestClient struct {
	*client.Runtime
	Ctx  context.Context
	Rest rest.Interface
}

func (*TestClient) DeleteAllForeground

func (c *TestClient) DeleteAllForeground(set map[string]string, obj runtimeClient.Object) error

func (*TestClient) Logs

func (c *TestClient) Logs(pod, container, namespace string) (string, error)

func (*TestClient) WriteAllResourcesToFile

func (c *TestClient) WriteAllResourcesToFile(dir string)

func (*TestClient) WriteKindToFile

func (c *TestClient) WriteKindToFile(dir, namespace, suffix string, list runtimeClient.ObjectList, set labels.Set)

Jump to

Keyboard shortcuts

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