Skip to content

Instantly share code, notes, and snippets.

@karuppiah7890
Created October 5, 2021 18:22
Show Gist options
  • Save karuppiah7890/b95fa2e33505c5670c1f46e8eb19e6c1 to your computer and use it in GitHub Desktop.
Save karuppiah7890/b95fa2e33505c5670c1f46e8eb19e6c1 to your computer and use it in GitHub Desktop.
Another sample failing test of `TestMachineScope_PublicIPSpecs` test, but with right test report
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: "mahine-name",
},
Spec: infrav1.AzureMachineSpec{
AllocatePublicIP: true,
},
},
},
want: []azure.PublicIPSpec{
{
Name: "pip-machine-name",
},
},
},
}
for _, tt := range tests {
want := tt.want
scope := tt.machineScope
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := scope.PublicIPSpecs(); !reflect.DeepEqual(got, want) {
t.Errorf("PublicIPSpecs() = %v, want %v", got, want)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment