-
Notifications
You must be signed in to change notification settings - Fork 413
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
1 parent
145c137
commit 787f1fe
Showing
3 changed files
with
202 additions
and
1 deletion.
There are no files selected for viewing
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,121 @@ | ||
/* | ||
Copyright 2018 The Kubernetes 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 scope | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"testing" | ||
|
||
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha3" | ||
azure "sigs.k8s.io/cluster-api-provider-azure/cloud" | ||
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" | ||
) | ||
|
||
func TestMachineScope_Name(t *testing.T) { | ||
type fields struct { | ||
ClusterScoper azure.ClusterScoper | ||
AzureMachine *infrav1.AzureMachine | ||
} | ||
tests := []struct { | ||
name string | ||
machineScope MachineScope | ||
want string | ||
testLength bool | ||
}{ | ||
{ | ||
name: "linux can be any length", | ||
machineScope: MachineScope{ | ||
AzureMachine: &infrav1.AzureMachine{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "machine-with-really-really-long-name", | ||
}, | ||
Spec: infrav1.AzureMachineSpec{ | ||
OSDisk: infrav1.OSDisk{ | ||
OSType: "Linux", | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: "machine-with-really-really-long-name", | ||
}, | ||
{ | ||
name: "Windows name with long MachineName and short cluster name", | ||
machineScope: MachineScope{ | ||
ClusterScoper: &ClusterScope{ | ||
Cluster: &clusterv1.Cluster{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "cluster", | ||
}, | ||
}, | ||
}, | ||
AzureMachine: &infrav1.AzureMachine{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "machine-90123456", | ||
}, | ||
Spec: infrav1.AzureMachineSpec{ | ||
OSDisk: infrav1.OSDisk{ | ||
OSType: "Windows", | ||
}, | ||
}, | ||
Status: infrav1.AzureMachineStatus{}, | ||
}, | ||
}, | ||
want: "cluster-23456", | ||
testLength: true, | ||
}, | ||
{ | ||
name: "Windows name with long MachineName and long cluster name", | ||
machineScope: MachineScope{ | ||
ClusterScoper: &ClusterScope{ | ||
Cluster: &clusterv1.Cluster{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "cluster8901234", | ||
}, | ||
}, | ||
}, | ||
AzureMachine: &infrav1.AzureMachine{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "machine-90123456", | ||
}, | ||
Spec: infrav1.AzureMachineSpec{ | ||
OSDisk: infrav1.OSDisk{ | ||
OSType: "Windows", | ||
}, | ||
}, | ||
Status: infrav1.AzureMachineStatus{}, | ||
}, | ||
}, | ||
want: "cluster89-23456", | ||
testLength: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
||
got := tt.machineScope.Name() | ||
if got != tt.want { | ||
t.Errorf("MachineScope.Name() = %v, want %v", got, tt.want) | ||
} | ||
|
||
if tt.testLength && len(got) > 15 { | ||
t.Errorf("Length of MachineScope.Name() = %v, want less than %v", len(got), 15) | ||
} | ||
}) | ||
} | ||
} |
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
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,80 @@ | ||
/* | ||
Copyright 2020 The Kubernetes 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 scope | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha3" | ||
"testing" | ||
|
||
infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1alpha3" | ||
) | ||
|
||
func TestMachinePoolScope_Name(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
machinePoolScope MachinePoolScope | ||
want string | ||
testLength bool | ||
}{ | ||
{ | ||
name: "linux can be any length", | ||
machinePoolScope: MachinePoolScope{ | ||
MachinePool: nil, | ||
AzureMachinePool: &infrav1exp.AzureMachinePool{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "some-really-really-long-name", | ||
}, | ||
}, | ||
ClusterScoper: nil, | ||
}, | ||
want: "some-really-really-long-name", | ||
}, | ||
{ | ||
name: "windows longer than 9 should be shortened", | ||
machinePoolScope: MachinePoolScope{ | ||
MachinePool: nil, | ||
AzureMachinePool: &infrav1exp.AzureMachinePool{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "machine-90123456", | ||
}, | ||
Spec: infrav1exp.AzureMachinePoolSpec{ | ||
Template: infrav1exp.AzureMachineTemplate{ | ||
OSDisk: infrav1.OSDisk{ | ||
OSType: "Windows", | ||
}, | ||
}, | ||
}, | ||
}, | ||
ClusterScoper: nil, | ||
}, | ||
want: "win-23456", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := tt.machinePoolScope.Name() | ||
if got != tt.want { | ||
t.Errorf("MachinePoolScope.Name() = %v, want %v", got, tt.want) | ||
} | ||
|
||
if tt.testLength && len(got) > 9 { | ||
t.Errorf("Length of MachinePoolScope.Name() = %v, want less than %v", len(got), 9) | ||
} | ||
}) | ||
} | ||
} |