-
Notifications
You must be signed in to change notification settings - Fork 102
/
claim_test.go
102 lines (88 loc) · 3.03 KB
/
claim_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
Copyright 2019 The Crossplane Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package compute
import (
"context"
"testing"
"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
runtimev1alpha1 "github.com/crossplaneio/crossplane-runtime/apis/core/v1alpha1"
"github.com/crossplaneio/crossplane-runtime/pkg/resource"
"github.com/crossplaneio/crossplane-runtime/pkg/test"
computev1alpha1 "github.com/crossplaneio/crossplane/apis/compute/v1alpha1"
"github.com/crossplaneio/stack-gcp/apis/compute/v1alpha2"
)
var _ resource.ManagedConfigurator = resource.ManagedConfiguratorFn(ConfigureGKECluster)
func TestConfigureGKECluster(t *testing.T) {
type args struct {
ctx context.Context
cm resource.Claim
cs resource.NonPortableClass
mg resource.Managed
}
type want struct {
mg resource.Managed
err error
}
claimUID := types.UID("definitely-a-uuid")
providerName := "coolprovider"
cases := map[string]struct {
args args
want want
}{
"Successful": {
args: args{
cm: &computev1alpha1.KubernetesCluster{ObjectMeta: metav1.ObjectMeta{UID: claimUID}},
cs: &v1alpha2.GKEClusterClass{
SpecTemplate: v1alpha2.GKEClusterClassSpecTemplate{
NonPortableClassSpecTemplate: runtimev1alpha1.NonPortableClassSpecTemplate{
ProviderReference: &corev1.ObjectReference{Name: providerName},
ReclaimPolicy: runtimev1alpha1.ReclaimDelete,
},
},
},
mg: &v1alpha2.GKECluster{},
},
want: want{
mg: &v1alpha2.GKECluster{
Spec: v1alpha2.GKEClusterSpec{
ResourceSpec: runtimev1alpha1.ResourceSpec{
ReclaimPolicy: runtimev1alpha1.ReclaimDelete,
WriteConnectionSecretToReference: corev1.LocalObjectReference{Name: string(claimUID)},
ProviderReference: &corev1.ObjectReference{Name: providerName},
},
GKEClusterParameters: v1alpha2.GKEClusterParameters{
NumNodes: 1,
Scopes: []string{},
Labels: map[string]string{},
},
},
},
err: nil,
},
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
err := ConfigureGKECluster(tc.args.ctx, tc.args.cm, tc.args.cs, tc.args.mg)
if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" {
t.Errorf("ConfigureGKECluster(...): -want error, +got error:\n%s", diff)
}
if diff := cmp.Diff(tc.want.mg, tc.args.mg, test.EquateConditions()); diff != "" {
t.Errorf("ConfigureGKECluster(...) Managed: -want, +got:\n%s", diff)
}
})
}
}