mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-07-25 08:15:18 -04:00
Ref/want err from err expected (#82)
consistent naming for test values using 'want' instead of 'expect/ed'
This commit is contained in:
parent
6265b307af
commit
51068abc27
91 changed files with 2319 additions and 2319 deletions
|
@ -10,43 +10,43 @@ import (
|
|||
|
||||
func TestParseJoinCommand(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
joinCommand string
|
||||
expectedJoinArgs kubeadm.BootstrapTokenDiscovery
|
||||
expectErr bool
|
||||
joinCommand string
|
||||
wantJoinArgs kubeadm.BootstrapTokenDiscovery
|
||||
wantErr bool
|
||||
}{
|
||||
"join command can be parsed": {
|
||||
joinCommand: "kubeadm join 192.0.2.0:8443 --token dummy-token --discovery-token-ca-cert-hash sha512:dummy-hash --control-plane",
|
||||
expectedJoinArgs: kubeadm.BootstrapTokenDiscovery{
|
||||
wantJoinArgs: kubeadm.BootstrapTokenDiscovery{
|
||||
APIServerEndpoint: "192.0.2.0:8443",
|
||||
Token: "dummy-token",
|
||||
CACertHashes: []string{"sha512:dummy-hash"},
|
||||
},
|
||||
expectErr: false,
|
||||
wantErr: false,
|
||||
},
|
||||
"incorrect join command returns error": {
|
||||
joinCommand: "some string",
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing api server endpoint is checked": {
|
||||
joinCommand: "kubeadm join --token dummy-token --discovery-token-ca-cert-hash sha512:dummy-hash --control-plane",
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing token is checked": {
|
||||
joinCommand: "kubeadm join 192.0.2.0:8443 --discovery-token-ca-cert-hash sha512:dummy-hash --control-plane",
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing discovery-token-ca-cert-hash is checked": {
|
||||
joinCommand: "kubeadm join 192.0.2.0:8443 --token dummy-token --control-plane",
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"missing control-plane": {
|
||||
joinCommand: "kubeadm join 192.0.2.0:8443 --token dummy-token --discovery-token-ca-cert-hash sha512:dummy-hash",
|
||||
expectedJoinArgs: kubeadm.BootstrapTokenDiscovery{
|
||||
wantJoinArgs: kubeadm.BootstrapTokenDiscovery{
|
||||
APIServerEndpoint: "192.0.2.0:8443",
|
||||
Token: "dummy-token",
|
||||
CACertHashes: []string{"sha512:dummy-hash"},
|
||||
},
|
||||
expectErr: false,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -57,13 +57,13 @@ func TestParseJoinCommand(t *testing.T) {
|
|||
|
||||
joinArgs, err := ParseJoinCommand(tc.joinCommand)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
require.NoError(err)
|
||||
|
||||
assert.Equal(&tc.expectedJoinArgs, joinArgs)
|
||||
assert.Equal(&tc.wantJoinArgs, joinArgs)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,25 +176,25 @@ func marshalYAML(obj runtime.Object) ([]byte, error) {
|
|||
func TestApplyOneObject(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
httpResponseData map[string]string
|
||||
expectedObj runtime.Object
|
||||
wantObj runtime.Object
|
||||
resourcesYAML string
|
||||
failingClient bool
|
||||
expectErr bool
|
||||
wantErr bool
|
||||
}{
|
||||
"apply works": {
|
||||
httpResponseData: map[string]string{
|
||||
"/deployments/my-nginx?fieldManager=constellation-coordinator&force=true": string(nginxDeplJSON),
|
||||
},
|
||||
expectedObj: nginxDeployment,
|
||||
wantObj: nginxDeployment,
|
||||
resourcesYAML: string(nginxDeplYAML),
|
||||
expectErr: false,
|
||||
wantErr: false,
|
||||
},
|
||||
"apply fails": {
|
||||
httpResponseData: map[string]string{},
|
||||
expectedObj: nginxDeployment,
|
||||
wantObj: nginxDeployment,
|
||||
resourcesYAML: string(nginxDeplYAML),
|
||||
failingClient: true,
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -205,9 +205,9 @@ func TestApplyOneObject(t *testing.T) {
|
|||
|
||||
var client Client
|
||||
if tc.failingClient {
|
||||
client = newFailingClient(tc.expectedObj)
|
||||
client = newFailingClient(tc.wantObj)
|
||||
} else {
|
||||
client = newClientWithFakes(t, tc.httpResponseData, tc.expectedObj)
|
||||
client = newClientWithFakes(t, tc.httpResponseData, tc.wantObj)
|
||||
}
|
||||
|
||||
reader := bytes.NewReader([]byte(tc.resourcesYAML))
|
||||
|
@ -223,7 +223,7 @@ func TestApplyOneObject(t *testing.T) {
|
|||
|
||||
err = client.ApplyOneObject(infos[0], true)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
|
@ -234,30 +234,30 @@ func TestApplyOneObject(t *testing.T) {
|
|||
|
||||
func TestGetObjects(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
expectedResources resources.Marshaler
|
||||
httpResponseData map[string]string
|
||||
resourcesYAML string
|
||||
expectErr bool
|
||||
wantResources resources.Marshaler
|
||||
httpResponseData map[string]string
|
||||
resourcesYAML string
|
||||
wantErr bool
|
||||
}{
|
||||
"GetObjects works on flannel deployment": {
|
||||
expectedResources: resources.NewDefaultFlannelDeployment(),
|
||||
resourcesYAML: string(nginxDeplYAML),
|
||||
expectErr: false,
|
||||
wantResources: resources.NewDefaultFlannelDeployment(),
|
||||
resourcesYAML: string(nginxDeplYAML),
|
||||
wantErr: false,
|
||||
},
|
||||
"GetObjects works on cluster-autoscaler deployment": {
|
||||
expectedResources: resources.NewDefaultFlannelDeployment(),
|
||||
resourcesYAML: string(nginxDeplYAML),
|
||||
expectErr: false,
|
||||
wantResources: resources.NewDefaultFlannelDeployment(),
|
||||
resourcesYAML: string(nginxDeplYAML),
|
||||
wantErr: false,
|
||||
},
|
||||
"GetObjects works on cloud-controller-manager deployment": {
|
||||
expectedResources: resources.NewDefaultCloudControllerManagerDeployment("someProvider", "someImage", "somePath", nil, nil, nil, nil),
|
||||
resourcesYAML: string(nginxDeplYAML),
|
||||
expectErr: false,
|
||||
wantResources: resources.NewDefaultCloudControllerManagerDeployment("someProvider", "someImage", "somePath", nil, nil, nil, nil),
|
||||
resourcesYAML: string(nginxDeplYAML),
|
||||
wantErr: false,
|
||||
},
|
||||
"GetObjects Marshal failure detected": {
|
||||
expectedResources: &unmarshableResource{},
|
||||
resourcesYAML: string(nginxDeplYAML),
|
||||
expectErr: true,
|
||||
wantResources: &unmarshableResource{},
|
||||
resourcesYAML: string(nginxDeplYAML),
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -267,9 +267,9 @@ func TestGetObjects(t *testing.T) {
|
|||
require := require.New(t)
|
||||
|
||||
client := newClientWithFakes(t, tc.httpResponseData)
|
||||
infos, err := client.GetObjects(tc.expectedResources)
|
||||
infos, err := client.GetObjects(tc.wantResources)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ import (
|
|||
|
||||
func TestMarshalK8SResources(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
resources interface{}
|
||||
expectErr bool
|
||||
expectedYAML string
|
||||
resources interface{}
|
||||
wantErr bool
|
||||
wantYAML string
|
||||
}{
|
||||
"ConfigMap as only field can be marshaled": {
|
||||
resources: &struct {
|
||||
|
@ -31,7 +31,7 @@ func TestMarshalK8SResources(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
expectedYAML: `apiVersion: v1
|
||||
wantYAML: `apiVersion: v1
|
||||
data:
|
||||
key: value
|
||||
kind: ConfigMap
|
||||
|
@ -63,7 +63,7 @@ metadata:
|
|||
},
|
||||
},
|
||||
},
|
||||
expectedYAML: `apiVersion: v1
|
||||
wantYAML: `apiVersion: v1
|
||||
data:
|
||||
key: value
|
||||
kind: ConfigMap
|
||||
|
@ -80,11 +80,11 @@ metadata:
|
|||
},
|
||||
"Non-pointer is detected": {
|
||||
resources: "non-pointer",
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"Nil resource pointer is detected": {
|
||||
resources: nil,
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"Non-pointer field is ignored": {
|
||||
resources: &struct{ String string }{String: "somestring"},
|
||||
|
@ -105,23 +105,23 @@ metadata:
|
|||
|
||||
yaml, err := MarshalK8SResources(tc.resources)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
require.NoError(err)
|
||||
|
||||
assert.Equal(tc.expectedYAML, string(yaml))
|
||||
assert.Equal(tc.wantYAML, string(yaml))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalK8SResources(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
data string
|
||||
into interface{}
|
||||
expectedObj interface{}
|
||||
expectErr bool
|
||||
data string
|
||||
into interface{}
|
||||
wantObj interface{}
|
||||
wantErr bool
|
||||
}{
|
||||
"ConfigMap as only field can be unmarshaled": {
|
||||
data: `apiVersion: v1
|
||||
|
@ -134,7 +134,7 @@ metadata:
|
|||
into: &struct {
|
||||
ConfigMap k8s.ConfigMap
|
||||
}{},
|
||||
expectedObj: &struct {
|
||||
wantObj: &struct {
|
||||
ConfigMap k8s.ConfigMap
|
||||
}{
|
||||
ConfigMap: k8s.ConfigMap{
|
||||
|
@ -167,7 +167,7 @@ metadata:
|
|||
ConfigMap k8s.ConfigMap
|
||||
Secret k8s.Secret
|
||||
}{},
|
||||
expectedObj: &struct {
|
||||
wantObj: &struct {
|
||||
ConfigMap k8s.ConfigMap
|
||||
Secret k8s.Secret
|
||||
}{
|
||||
|
@ -209,15 +209,15 @@ metadata:
|
|||
into: &struct {
|
||||
ConfigMap k8s.ConfigMap
|
||||
}{},
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"Non-struct pointer is detected": {
|
||||
into: proto.String("test"),
|
||||
expectErr: true,
|
||||
into: proto.String("test"),
|
||||
wantErr: true,
|
||||
},
|
||||
"Nil into is detected": {
|
||||
into: nil,
|
||||
expectErr: true,
|
||||
into: nil,
|
||||
wantErr: true,
|
||||
},
|
||||
"Invalid yaml is detected": {
|
||||
data: `duplicateKey: value
|
||||
|
@ -225,7 +225,7 @@ metadata:
|
|||
into: &struct {
|
||||
ConfigMap k8s.ConfigMap
|
||||
}{},
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"Struct field cannot interface with runtime.Object": {
|
||||
data: `apiVersion: v1
|
||||
|
@ -238,7 +238,7 @@ metadata:
|
|||
into: &struct {
|
||||
String string
|
||||
}{},
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"Struct field mismatch": {
|
||||
data: `apiVersion: v1
|
||||
|
@ -251,7 +251,7 @@ metadata:
|
|||
into: &struct {
|
||||
Secret k8s.Secret
|
||||
}{},
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -262,22 +262,22 @@ metadata:
|
|||
|
||||
err := UnmarshalK8SResources([]byte(tc.data), tc.into)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
require.NoError(err)
|
||||
|
||||
assert.Equal(tc.expectedObj, tc.into)
|
||||
assert.Equal(tc.wantObj, tc.into)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalK8SResourcesList(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
resources []runtime.Object
|
||||
expectErr bool
|
||||
expectedYAML string
|
||||
resources []runtime.Object
|
||||
wantErr bool
|
||||
wantYAML string
|
||||
}{
|
||||
"ConfigMap as only element be marshaled": {
|
||||
resources: []runtime.Object{
|
||||
|
@ -291,7 +291,7 @@ func TestMarshalK8SResourcesList(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
expectedYAML: `apiVersion: v1
|
||||
wantYAML: `apiVersion: v1
|
||||
data:
|
||||
key: value
|
||||
kind: ConfigMap
|
||||
|
@ -320,7 +320,7 @@ metadata:
|
|||
},
|
||||
},
|
||||
},
|
||||
expectedYAML: `apiVersion: v1
|
||||
wantYAML: `apiVersion: v1
|
||||
data:
|
||||
key: value
|
||||
kind: ConfigMap
|
||||
|
@ -336,8 +336,8 @@ metadata:
|
|||
`,
|
||||
},
|
||||
"Nil resource pointer is encodes": {
|
||||
resources: []runtime.Object{nil},
|
||||
expectedYAML: "null\n",
|
||||
resources: []runtime.Object{nil},
|
||||
wantYAML: "null\n",
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -348,13 +348,13 @@ metadata:
|
|||
|
||||
yaml, err := MarshalK8SResourcesList(tc.resources)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
require.NoError(err)
|
||||
|
||||
assert.Equal(tc.expectedYAML, string(yaml))
|
||||
assert.Equal(tc.wantYAML, string(yaml))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ func TestInitCluster(t *testing.T) {
|
|||
kubeconfigReader stubKubeconfigReader
|
||||
initConfig k8sapi.KubeadmInitYAML
|
||||
joinConfig k8sapi.KubeadmJoinYAML
|
||||
expectErr bool
|
||||
wantErr bool
|
||||
}{
|
||||
"kubeadm init works": {
|
||||
clusterUtil: stubClusterUtil{
|
||||
|
@ -144,7 +144,7 @@ func TestInitCluster(t *testing.T) {
|
|||
kubeconfigReader: stubKubeconfigReader{
|
||||
Kubeconfig: []byte("someKubeconfig"),
|
||||
},
|
||||
expectErr: false,
|
||||
wantErr: false,
|
||||
},
|
||||
"kubeadm init errors": {
|
||||
clusterUtil: stubClusterUtil{
|
||||
|
@ -154,7 +154,7 @@ func TestInitCluster(t *testing.T) {
|
|||
kubeconfigReader: stubKubeconfigReader{
|
||||
Kubeconfig: []byte("someKubeconfig"),
|
||||
},
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"pod network setup errors": {
|
||||
clusterUtil: stubClusterUtil{
|
||||
|
@ -164,7 +164,7 @@ func TestInitCluster(t *testing.T) {
|
|||
kubeconfigReader: stubKubeconfigReader{
|
||||
Kubeconfig: []byte("someKubeconfig"),
|
||||
},
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,7 @@ func TestInitCluster(t *testing.T) {
|
|||
},
|
||||
)
|
||||
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
|
@ -223,15 +223,15 @@ func TestJoinCluster(t *testing.T) {
|
|||
|
||||
testCases := map[string]struct {
|
||||
clusterUtil stubClusterUtil
|
||||
expectErr bool
|
||||
wantErr bool
|
||||
}{
|
||||
"kubeadm join works": {
|
||||
clusterUtil: stubClusterUtil{},
|
||||
expectErr: false,
|
||||
wantErr: false,
|
||||
},
|
||||
"kubeadm join errors": {
|
||||
clusterUtil: stubClusterUtil{joinClusterErr: someErr},
|
||||
expectErr: true,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ func TestJoinCluster(t *testing.T) {
|
|||
|
||||
kube := New(&tc.clusterUtil, &stubConfigProvider{}, &client)
|
||||
err := kube.JoinCluster(joinCommand, instanceName, nodeVPNIP, nodeVPNIP, coordinatorProviderID, "", role.Node)
|
||||
if tc.expectErr {
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ func TestJoinCluster(t *testing.T) {
|
|||
func TestGetKubeconfig(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
Kubewrapper KubeWrapper
|
||||
expectErr bool
|
||||
wantErr bool
|
||||
}{
|
||||
"check single replacement": {
|
||||
Kubewrapper: KubeWrapper{kubeconfigReader: &stubKubeconfigReader{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue