-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
205 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
--- |
11 changes: 8 additions & 3 deletions
11
samples/minio.crossplane.io_user copy.yaml → test/e2e/user/00-install-user.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {} | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |