Merge pull request #167 from muvaf/mockme

Export mock secret owner structs to be used in tests outside this repo
This commit is contained in:
Nic Cope 2020-04-28 19:19:25 -07:00 committed by GitHub
commit 4e5f08ced5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 32 deletions

View File

@ -459,3 +459,73 @@ func SchemeWith(o ...runtime.Object) *runtime.Scheme {
s.AddKnownTypes(GV, o...)
return s
}
// MockConnectionSecretOwner is a mock object that satisfies ConnectionSecretOwner
// interface.
type MockConnectionSecretOwner struct {
runtime.Object
metav1.ObjectMeta
Ref *v1alpha1.SecretReference
}
// GetWriteConnectionSecretToReference returns the connection secret reference.
func (m *MockConnectionSecretOwner) GetWriteConnectionSecretToReference() *v1alpha1.SecretReference {
return m.Ref
}
// SetWriteConnectionSecretToReference sets the connection secret reference.
func (m *MockConnectionSecretOwner) SetWriteConnectionSecretToReference(r *v1alpha1.SecretReference) {
m.Ref = r
}
// GetObjectKind returns schema.ObjectKind.
func (m *MockConnectionSecretOwner) GetObjectKind() schema.ObjectKind {
return schema.EmptyObjectKind
}
// DeepCopyObject returns a copy of the object as runtime.Object
func (m *MockConnectionSecretOwner) DeepCopyObject() runtime.Object {
out := &MockConnectionSecretOwner{}
j, err := json.Marshal(m)
if err != nil {
panic(err)
}
_ = json.Unmarshal(j, out)
return out
}
// MockLocalConnectionSecretOwner is a mock object that satisfies LocalConnectionSecretOwner
// interface.
type MockLocalConnectionSecretOwner struct {
runtime.Object
metav1.ObjectMeta
Ref *v1alpha1.LocalSecretReference
}
// GetWriteConnectionSecretToReference returns the connection secret reference.
func (m *MockLocalConnectionSecretOwner) GetWriteConnectionSecretToReference() *v1alpha1.LocalSecretReference {
return m.Ref
}
// SetWriteConnectionSecretToReference sets the connection secret reference.
func (m *MockLocalConnectionSecretOwner) SetWriteConnectionSecretToReference(r *v1alpha1.LocalSecretReference) {
m.Ref = r
}
// GetObjectKind returns schema.ObjectKind.
func (m *MockLocalConnectionSecretOwner) GetObjectKind() schema.ObjectKind {
return schema.EmptyObjectKind
}
// DeepCopyObject returns a copy of the object as runtime.Object
func (m *MockLocalConnectionSecretOwner) DeepCopyObject() runtime.Object {
out := &MockLocalConnectionSecretOwner{}
j, err := json.Marshal(m)
if err != nil {
panic(err)
}
_ = json.Unmarshal(j, out)
return out
}

View File

@ -46,21 +46,6 @@ var MockOwnerGVK = schema.GroupVersionKind{
Kind: "MockOwner",
}
type MockLocalOwner struct {
runtime.Object
metav1.ObjectMeta
Ref *v1alpha1.LocalSecretReference
}
func (m *MockLocalOwner) GetWriteConnectionSecretToReference() *v1alpha1.LocalSecretReference {
return m.Ref
}
func (m *MockLocalOwner) SetWriteConnectionSecretToReference(r *v1alpha1.LocalSecretReference) {
m.Ref = r
}
func TestLocalConnectionSecretFor(t *testing.T) {
secretName := "coolsecret"
@ -77,7 +62,7 @@ func TestLocalConnectionSecretFor(t *testing.T) {
}{
"Success": {
args: args{
o: &MockLocalOwner{
o: &fake.MockLocalConnectionSecretOwner{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
@ -114,21 +99,6 @@ func TestLocalConnectionSecretFor(t *testing.T) {
}
}
type MockOwner struct {
runtime.Object
metav1.ObjectMeta
Ref *v1alpha1.SecretReference
}
func (m *MockOwner) GetWriteConnectionSecretToReference() *v1alpha1.SecretReference {
return m.Ref
}
func (m *MockOwner) SetWriteConnectionSecretToReference(r *v1alpha1.SecretReference) {
m.Ref = r
}
func TestConnectionSecretFor(t *testing.T) {
secretName := "coolsecret"
@ -145,7 +115,7 @@ func TestConnectionSecretFor(t *testing.T) {
}{
"Success": {
args: args{
o: &MockOwner{
o: &fake.MockConnectionSecretOwner{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,