Skip to content

Commit

Permalink
e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kidswiss committed Aug 30, 2023
1 parent ac75e6c commit a4c4953
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 3 deletions.
Binary file removed __debug_bin1327813625
Binary file not shown.
147 changes: 147 additions & 0 deletions operator/user/webhook_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package user

import (
"context"
"testing"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
"github.com/go-logr/logr"
miniov1 "github.com/vshn/provider-minio/apis/minio/v1"
)

func TestValidator_ValidateCreate(t *testing.T) {
tests := []struct {
name string
obj *miniov1.User
wantErr bool
}{
{
name: "GivenValidObject_ThenNoError",
obj: &miniov1.User{
Spec: miniov1.UserSpec{
ResourceSpec: xpv1.ResourceSpec{
ProviderConfigReference: &xpv1.Reference{
Name: "test",
},
},
},
},
},
{
name: "GivenInvalidObject_ThenError",
wantErr: true,
obj: &miniov1.User{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &Validator{
log: logr.Discard(),
}
_, err := v.ValidateCreate(context.TODO(), tt.obj)
if (err != nil) != tt.wantErr {
t.Errorf("Validator.ValidateCreate() error = %v, wantErr %v", err, tt.wantErr)
return
}
})
}
}

func TestValidator_ValidateUpdate(t *testing.T) {
type args struct {
oldObj *miniov1.User
newObj *miniov1.User
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "GivenSameObject_ThenNoError",
args: args{
oldObj: &miniov1.User{
Spec: miniov1.UserSpec{
ResourceSpec: xpv1.ResourceSpec{
ProviderConfigReference: &xpv1.Reference{
Name: "provider",
},
},
},
},
newObj: &miniov1.User{
Spec: miniov1.UserSpec{
ResourceSpec: xpv1.ResourceSpec{
ProviderConfigReference: &xpv1.Reference{
Name: "provider",
},
},
},
},
},
},
{
name: "GivenDifferentProviderConfigRef_ThenNoError",
args: args{
oldObj: &miniov1.User{
Spec: miniov1.UserSpec{
ResourceSpec: xpv1.ResourceSpec{
ProviderConfigReference: &xpv1.Reference{
Name: "provider",
},
},
},
},
newObj: &miniov1.User{
Spec: miniov1.UserSpec{
ResourceSpec: xpv1.ResourceSpec{
ProviderConfigReference: &xpv1.Reference{
Name: "new",
},
},
},
},
},
},
{
name: "GivenDifferentName_ThenError",
wantErr: true,
args: args{
oldObj: &miniov1.User{
Spec: miniov1.UserSpec{
ResourceSpec: xpv1.ResourceSpec{
ProviderConfigReference: &xpv1.Reference{
Name: "provider",
},
},
},
},
newObj: &miniov1.User{
Spec: miniov1.UserSpec{
ForProvider: miniov1.UserParameters{
UserName: "test",
},
ResourceSpec: xpv1.ResourceSpec{
ProviderConfigReference: &xpv1.Reference{
Name: "new",
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &Validator{
log: logr.Discard(),
}
_, err := v.ValidateUpdate(context.TODO(), tt.args.oldObj, tt.args.newObj)
if (err != nil) != tt.wantErr {
t.Errorf("Validator.ValidateUpdate() error = %v, wantErr %v", err, tt.wantErr)
return
}

})
}
}
File renamed without changes.
13 changes: 13 additions & 0 deletions test/e2e/connect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -eo pipefail
#set -x

endpoint=${1}
secret_name=${2}

access_key=$(kubectl -n default get secret ${secret_name} -o jsonpath='{.data.AWS_ACCESS_KEY_ID}' | base64 -d)
secret_key=$(kubectl -n default get secret ${secret_name} -o jsonpath='{.data.AWS_SECRET_ACCESS_KEY}' | base64 -d)
export MC_HOST_minio=http://${access_key}:${secret_key}@${endpoint}

${GOBIN}/mc mb --quiet "minio/bucket-$(date +%s)"
30 changes: 30 additions & 0 deletions test/e2e/user/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
---
apiVersion: minio.crossplane.io/v1
kind: User
metadata:
name: testuser
spec:
forProvider: {}
providerConfigRef:
name: provider-config
writeConnectionSecretToRef:
name: testuser
namespace: default
status:
atProvider:
userName: testuser
status: enabled
conditions:
- status: 'True'
- status: 'True'
---
apiVersion: v1
kind: Secret
metadata:
name: testuser
namespace: default
type: connection.crossplane.io/v1alpha1
---
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
---
apiVersion: minio.crossplane.io/v1
kind: User
metadata:
creationTimestamp: null
name: devuser1
name: testuser
spec:
forProvider:
userName: devuser
forProvider: {}
providerConfigRef:
name: provider-config
writeConnectionSecretToRef:
name: testuser
namespace: default
status:
atProvider: {}

---
7 changes: 7 additions & 0 deletions test/e2e/user/01-connect.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This test is currently not viable, as a user without any policy can't do anything at all.
# apiVersion: kuttl.dev/v1beta1
# kind: TestStep
# commands:
# # note: working dir is the where the yaml files are
# # Args: $endpoint $secret_name
# - command: ../connect.sh minio.127.0.0.1.nip.io:8088 testuser

0 comments on commit a4c4953

Please sign in to comment.