Skip to content

Commit

Permalink
added ut for generateMachineManifest
Browse files Browse the repository at this point in the history
  • Loading branch information
smritidahal653 committed Nov 13, 2023
1 parent 3e985b6 commit 82f2688
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/machine/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func TestCreateMachine(t *testing.T) {
expectedError error
}{
"Machine creation fails": {
callMocks: func(c *utils.MockClient) {
c.On("Create", mock.IsType(context.Background()), mock.IsType(&v1alpha5.Machine{}), mock.Anything).Return(errors.New("Failed to create machine"))
},
expectedError: errors.New("Failed to create machine"),
},
"Machine creation fails because SKU is not available": {
callMocks: func(c *utils.MockClient) {
c.On("Create", mock.IsType(context.Background()), mock.IsType(&v1alpha5.Machine{}), mock.Anything).Return(nil)
c.On("Get", mock.IsType(context.Background()), mock.Anything, mock.IsType(&v1alpha5.Machine{}), mock.Anything).Return(nil)
Expand Down Expand Up @@ -156,3 +162,14 @@ func TestWaitForPendingMachines(t *testing.T) {
})
}
}

func TestGenerateMachineManifiest(t *testing.T) {
t.Run("Should generate a machine object from the given workspace", func(t *testing.T) {
mockWorkspace := utils.MockWorkspace

machine := GenerateMachineManifest(context.Background(), "0", mockWorkspace)

assert.Check(t, machine != nil, "Machine must not be nil")
assert.Equal(t, machine.Namespace, mockWorkspace.Namespace, "Machine must have same namespace as workspace")
})
}

0 comments on commit 82f2688

Please sign in to comment.