Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Commit

Permalink
fix problems in unit tests, e.g. YAML indentatation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
luxas authored and twelho committed Jul 31, 2020
1 parent 40fd12b commit bfc899f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 45 deletions.
43 changes: 20 additions & 23 deletions pkg/cluster/machine/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/weaveworks/wksctl/pkg/utilities/manifest"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/client-go/kubernetes/scheme"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
)

Expand Down Expand Up @@ -76,7 +75,8 @@ const machinesValid = `
metadata:
name: master-0
spec:
address: "172.17.8.101"
private:
address: "172.17.8.101"
---
apiVersion: "cluster.x-k8s.io/v1alpha3"
kind: Machine
Expand All @@ -95,11 +95,8 @@ const machinesValid = `
metadata:
name: node-0
spec:
address: "172.17.8.102"
authenticationWebhook:
cacheTTL: 2m0s
server:
url: http://127.0.0.1:5000/authenticate
private:
address: "172.17.8.102"
`

// A machine doesn't have a matching Kubernetes version.
Expand All @@ -121,7 +118,8 @@ const machinesInconsistentKubeVersion = `
metadata:
name: master-0
spec:
address: "172.17.8.101"
private:
address: "172.17.8.101"
---
apiVersion: "cluster.x-k8s.io/v1alpha3"
kind: Machine
Expand All @@ -140,7 +138,8 @@ const machinesInconsistentKubeVersion = `
metadata:
name: node-0
spec:
address: "172.17.8.102"
private:
address: "172.17.8.102"
`

// Unsupported Kubernetes version.
Expand All @@ -161,7 +160,8 @@ const machinesUnsupportedKubernetesVersion = ` apiVersion: "cluster.x-k8s.io/v1
metadata:
name: master-0
spec:
address: "172.17.8.101"
private:
address: "172.17.8.101"
---
apiVersion: "cluster.x-k8s.io/v1alpha3"
kind: Machine
Expand All @@ -180,7 +180,8 @@ const machinesUnsupportedKubernetesVersion = ` apiVersion: "cluster.x-k8s.io/v1
metadata:
name: node-0
spec:
address: "172.17.8.102"
private:
address: "172.17.8.102"
`

const machinesNoGodNoMaster = `
Expand All @@ -201,7 +202,8 @@ const machinesNoGodNoMaster = `
metadata:
name: node-0
spec:
address: "172.17.8.102"
private:
address: "172.17.8.102"
`

func machinesFromString(t *testing.T, s string) ([]*clusterv1.Machine, []*existinginfrav1.ExistingInfraMachine) {
Expand All @@ -221,9 +223,6 @@ func fieldsInError(errors field.ErrorList) []string {
}

func TestValidateMachines(t *testing.T) {
assert.NoError(t, clusterv1.AddToScheme(scheme.Scheme))
assert.NoError(t, existinginfrav1.AddToScheme(scheme.Scheme))

tests := []struct {
input string
errors []string
Expand Down Expand Up @@ -264,15 +263,16 @@ const machinesWithoutVersions = `
set: master
spec:
infrastructureRef:
kind: ExistingInfraMachine
name: master-0
kind: ExistingInfraMachine
name: master-0
---
apiVersion: "cluster.weave.works/v1alpha3"
kind: "ExistingInfraMachine"
metadata:
name: master-0
spec:
address: "172.17.8.101"
private:
address: "172.17.8.101"
---
apiVersion: "cluster.x-k8s.io/v1alpha3"
kind: Machine
Expand All @@ -290,11 +290,8 @@ const machinesWithoutVersions = `
metadata:
name: node-0
spec:
address: "172.17.8.102"
authenticationWebhook:
cacheTTL: 2m0s
server:
url: http://127.0.0.1:5000/authenticate
private:
address: "172.17.8.102"
`

// Ensure we populate the Kubernetes version if not provided.
Expand Down
24 changes: 11 additions & 13 deletions pkg/specs/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ const clusterMissingClusterDefinition = `
apiVersion: "cluster.weave.works/v1alpha3"
kind: "ExistingInfraCluster"
metadata:
name: example
name: example
spec:
user: "vagrant"
user: "vagrant"
`

const clusterMissingExistingInfraClusterDefinition = `
apiVersion: "cluster.x-k8s.io/v1alpha3"
kind: Cluster
metadata:
name: example
name: example
spec:
clusterNetwork:
services:
cidrBlocks: ["10.96.0.0/12"]
pods:
cidrBlocks: ["192.168.0.0/16"]
infrastructureRef:
kind: ExistingInfraCluster
name: example
clusterNetwork:
services:
cidrBlocks: ["10.96.0.0/12"]
pods:
cidrBlocks: ["192.168.0.0/16"]
infrastructureRef:
kind: ExistingInfraCluster
name: example
`

func mergeObjects(a string, b string) string {
Expand All @@ -48,8 +48,6 @@ func parseConfig(s string) (err error) {
}

func TestParseCluster(t *testing.T) {
assert.NoError(t, clusterv1.AddToScheme(scheme.Scheme))
assert.NoError(t, existinginfrav1.AddToScheme(scheme.Scheme))
assert.NoError(t, parseConfig(mergeObjects(clusterMissingExistingInfraClusterDefinition, clusterMissingClusterDefinition)))

// Verify that the objects individually don't result in a successful parse
Expand Down
15 changes: 6 additions & 9 deletions pkg/specs/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/stretchr/testify/assert"
existinginfrav1 "github.com/weaveworks/wksctl/pkg/existinginfra/v1alpha3"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/client-go/kubernetes/scheme"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
)

Expand All @@ -23,9 +22,9 @@ spec:
cidrBlocks: ["10.96.0.0/12"]
pods:
cidrBlocks: ["192.168.0.0/16"]
infrastructureRef:
kind: ExistingInfraCluster
name: example
infrastructureRef:
kind: ExistingInfraCluster
name: example
---
apiVersion: "cluster.weave.works/v1alpha3"
kind: "ExistingInfraCluster"
Expand All @@ -46,9 +45,9 @@ spec:
cidrBlocks: ["10.96.0.0/12"]
pods:
cidrBlocks: ["192.168.0.0/16"]
infrastructureRef:
kind: ExistingInfraCluster
name: example
infrastructureRef:
kind: ExistingInfraCluster
name: example
---
apiVersion: "cluster.weave.works/v1alpha3"
kind: "ExistingInfraCluster"
Expand Down Expand Up @@ -291,8 +290,6 @@ func fieldsInError(errors field.ErrorList) []string {
}

func TestValidateCluster(t *testing.T) {
assert.NoError(t, clusterv1.AddToScheme(scheme.Scheme))
assert.NoError(t, existinginfrav1.AddToScheme(scheme.Scheme))
tests := []struct {
input string
errors []string
Expand Down

0 comments on commit bfc899f

Please sign in to comment.