Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Bigler <[email protected]>
  • Loading branch information
TheBigLee committed Nov 28, 2023
1 parent 95fc8de commit c972772
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 19 deletions.
4 changes: 0 additions & 4 deletions apis/vshn/v1/dbaas_vshn_mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ type VSHNMariaDBServiceSpec struct {

// +kubebuilder:default="standalone"
// +kubebuilder:validation:Enum=replication;standalone

// Mode configures the mode of MariaDB.
// Valid values are "replication" and "standalone".
Mode string `json:"mode,omitempty"`
}

// VSHNMariaDBTLSSpec contains settings to control tls traffic of a service.
Expand Down
7 changes: 0 additions & 7 deletions crds/vshn.appcat.vshn.io_vshnmariadbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ spec:
mariadbSettings:
description: MariadbSettings contains additional MariaDB settings.
type: string
mode:
default: standalone
description: Mode configures the mode of MariaDB. Valid values are "replication" and "standalone".
enum:
- replication
- standalone
type: string
serviceLevel:
default: besteffort
description: ServiceLevel defines the service level of this service. Either Best Effort or Guaranteed Availability is allowed.
Expand Down
8 changes: 0 additions & 8 deletions crds/vshn.appcat.vshn.io_xvshnmariadbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,6 @@ spec:
mariadbSettings:
description: MariadbSettings contains additional MariaDB settings.
type: string
mode:
default: standalone
description: Mode configures the mode of MariaDB. Valid values
are "replication" and "standalone".
enum:
- replication
- standalone
type: string
serviceLevel:
default: besteffort
description: ServiceLevel defines the service level of this
Expand Down
52 changes: 52 additions & 0 deletions pkg/comp-functions/functions/vshnmariadb/mariadb_deploy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package vshnmariadb

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
xhelmbeta1 "github.com/vshn/appcat/v4/apis/helm/release/v1beta1"
vshnv1 "github.com/vshn/appcat/v4/apis/vshn/v1"
"github.com/vshn/appcat/v4/pkg/comp-functions/functions/commontest"
"github.com/vshn/appcat/v4/pkg/comp-functions/runtime"
corev1 "k8s.io/api/core/v1"
)

func TestMariadbDeploy(t *testing.T) {

svc, comp := getMariadbComp(t)

ctx := context.TODO()

rootUser := "root"
rootPassword := "mariadb123"
mariadbHost := "mariadb-gc9x4.vshn-mariadb-mariadb-gc9x4.svc.cluster.local"
mariadbPort := "3306"
mariadbUrl := "mysql://mariadb-gc9x4.vshn-mariadb-mariadb-gc9x4.svc.cluster.local:3306"

assert.Nil(t, DeployMariadb(ctx, svc))

ns := &corev1.Namespace{}
assert.NoError(t, svc.GetObservedKubeObject(ns, comp.Name+"-ns"))

r := &xhelmbeta1.Release{}
assert.NoError(t, svc.GetObservedComposedResource(r, comp.Name+"-release"))

cd := svc.GetConnectionDetails()
assert.Equal(t, mariadbHost, string(cd["MARIADB_HOST"]))
assert.Equal(t, mariadbPort, string(cd["MARIADB_PORT"]))
assert.Equal(t, mariadbUrl, string(cd["MARIADB_URL"]))
assert.Equal(t, rootUser, string(cd["MARIADB_USER"]))
assert.Equal(t, rootPassword, string(cd["MARIADB_PASSWORD"]))

}

func getMariadbComp(t *testing.T) (*runtime.ServiceRuntime, *vshnv1.VSHNMariaDB) {
svc := commontest.LoadRuntimeFromFile(t, "vshnmariadb/deploy/01_default.yaml")

comp := &vshnv1.VSHNMariaDB{}
err := svc.GetObservedComposite(comp)
assert.NoError(t, err)

return svc, comp
}
90 changes: 90 additions & 0 deletions test/functions/vshnmariadb/deploy/01_default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
desired: {}
input:
apiVersion: v1
data:
defaultPlan: standard-1
mariadbChartRepo: https://charts.bitnami.com/bitnami
mariadbChartVersion: 10.1.3
plans: '{"standard-1": {"size": {"cpu": "250m", "disk": "16Gi", "enabled": true,
"memory": "1Gi"}}}'
providerEnabled: "true"
kind: ConfigMap
metadata:
annotations: {}
labels:
name: xfn-config
name: xfn-config
observed:
composite:
resource:
apiVersion: vshn.appcat.vshn.io/v1
kind: XVSHNMariaDB
metadata:
annotations: null
creationTimestamp: "2023-03-21T16:52:31Z"
finalizers:
- composite.apiextensions.crossplane.io
generateName: mariadb-
generation: 13
labels:
appuio.io/organization: vshn
crossplane.io/claim-name: mariadb
crossplane.io/claim-namespace: unit-test
crossplane.io/composite: mariadb-gc9x4
name: mariadb-gc9x4
spec:
claimRef:
apiVersion: vshn.appcat.vshn.io/v1
kind: VSHNMariaDB
name: mariadb
namespace: unit-test
compositionRef:
name: vshnmariadb.vshn.appcat.vshn.io
compositionRevisionRef:
name: vshnmariadb.vshn.appcat.vshn.io-ce52f13
compositionUpdatePolicy: Automatic
resources:
mariadb-gc9x4-ns:
resource:
apiVersion: v1
kind: Object
metadata:
name: vshn-mariadb-mariadb-gc9x4
spec:
forProvider:
manifest:
apiVersion: v1
kind: Namespace
metadata:
name: vshn-mariadb-mariadb-gc9x4
status:
atProvider:
manifest:
apiVersion: v1
kind: Namespace
metadata:
name: vshn-mariadb-mariadb-gc9x4
mariadb-gc9x4-release:
connection_details:
MARIADB_USER: cm9vdA== #root
MARIADB_PASSWORD: bWFyaWFkYjEyMw== #mariadb123
resource:
apiVersion: helm.crossplane.io/v1beta1
kind: Release
spec:
forProvider:
chart:
name: mariadb-galera
repository: https://charts.bitnami.com/bitnami
values:
fullnameOverride: mariadb
persistence:
size: 50Gi
replicasCount: 1
resources:
limits:
cpu: 1
memory: 1Gi
requests:
cpu: 1
memory: 1Gi

0 comments on commit c972772

Please sign in to comment.