|
7 | 7 | "testing"
|
8 | 8 |
|
9 | 9 | v1alpha5 "github.com/crusoecloud/client-go/swagger/v1alpha5"
|
| 10 | + "github.com/crusoecloud/crusoe-cloud-controller-manager/internal/client" |
10 | 11 | mock_client "github.com/crusoecloud/crusoe-cloud-controller-manager/internal/client/mock"
|
11 | 12 | "github.com/crusoecloud/crusoe-cloud-controller-manager/internal/instances"
|
12 | 13 | "github.com/golang/mock/gomock"
|
@@ -109,6 +110,37 @@ func TestInstanceShutdownByProviderID(t *testing.T) {
|
109 | 110 | require.True(t, shutdown)
|
110 | 111 | }
|
111 | 112 |
|
| 113 | +func TestInstanceShutdownByProviderIDInstanceMissingFromCloudProvider(t *testing.T) { |
| 114 | + t.Parallel() |
| 115 | + ctrl := gomock.NewController(t) |
| 116 | + defer ctrl.Finish() |
| 117 | + |
| 118 | + mockClient := mock_client.NewMockApiClient(ctrl) |
| 119 | + mockClient.EXPECT().GetInstanceByID(gomock.Any(), TESTInstanceID).Return(nil, nil, client.ErrInstanceNotFound).AnyTimes() |
| 120 | + instanceService := instances.NewCrusoeInstances(mockClient) |
| 121 | + |
| 122 | + // Instance shutdown by ID should return true on third attempt |
| 123 | + // attempt #1 |
| 124 | + shutdown, err := instanceService.InstanceShutdownByProviderID(context.Background(), ProviderIDPrefix+TESTInstanceID) |
| 125 | + require.ErrorIs(t, err, client.ErrInstanceNotFound) |
| 126 | + require.False(t, shutdown) |
| 127 | + |
| 128 | + // attempt #2 |
| 129 | + shutdown, err = instanceService.InstanceShutdownByProviderID(context.Background(), ProviderIDPrefix+TESTInstanceID) |
| 130 | + require.ErrorIs(t, err, client.ErrInstanceNotFound) |
| 131 | + require.False(t, shutdown) |
| 132 | + |
| 133 | + // attempt #3 |
| 134 | + shutdown, err = instanceService.InstanceShutdownByProviderID(context.Background(), ProviderIDPrefix+TESTInstanceID) |
| 135 | + require.ErrorIs(t, err, client.ErrInstanceNotFound) |
| 136 | + require.False(t, shutdown) |
| 137 | + |
| 138 | + // attempt #4 |
| 139 | + shutdown, err = instanceService.InstanceShutdownByProviderID(context.Background(), ProviderIDPrefix+TESTInstanceID) |
| 140 | + require.NoError(t, err) |
| 141 | + require.True(t, shutdown) |
| 142 | +} |
| 143 | + |
112 | 144 | func TestInstanceMetadata(t *testing.T) {
|
113 | 145 | t.Parallel()
|
114 | 146 | ctrl := gomock.NewController(t)
|
|
0 commit comments