Skip to content

Instantly share code, notes, and snippets.

@karuppiah7890
Created October 5, 2021 18:11
Show Gist options
  • Save karuppiah7890/129f99d4a46ddc4dd6f0b57441f30e0c to your computer and use it in GitHub Desktop.
Save karuppiah7890/129f99d4a46ddc4dd6f0b57441f30e0c to your computer and use it in GitHub Desktop.
Sample failing test in `TestMachineScope_PublicIPSpecs` test
func TestMachineScope_PublicIPSpecs(t *testing.T) {
tests := []struct {
name string
machineScope MachineScope
want []azure.PublicIPSpec
}{
{
name: "returns nil if AllocatePublicIP is false",
machineScope: MachineScope{
AzureMachine: &infrav1.AzureMachine{
ObjectMeta: metav1.ObjectMeta{
Name: "machine-name",
},
Spec: infrav1.AzureMachineSpec{
AllocatePublicIP: false,
},
},
},
want: nil,
},
{
name: "appends to PublicIPSpec for node if AllocatePublicIP is true",
machineScope: MachineScope{
AzureMachine: &infrav1.AzureMachine{
ObjectMeta: metav1.ObjectMeta{
Name: "macine-name",
},
Spec: infrav1.AzureMachineSpec{
AllocatePublicIP: true,
},
},
},
want: []azure.PublicIPSpec{
{
Name: "pip-machine-name",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := tt.machineScope.PublicIPSpecs(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("PublicIPSpecs() = %v, want %v", got, tt.want)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment