-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lh-87215): allow deletion of MSP-managed tenants (#147)
This is a faux deletion, as described in the documentation. It removes the tenant from the MSP portal, but doesn't actually delete it from the database.
- Loading branch information
1 parent
bf6e271
commit 1022180
Showing
9 changed files
with
100 additions
and
9 deletions.
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
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,17 @@ | ||
package tenants | ||
|
||
import ( | ||
"context" | ||
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http" | ||
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url" | ||
) | ||
|
||
func DeleteByUid(ctx context.Context, client http.Client, deleteInp DeleteByUidInput) (interface{}, error) { | ||
client.Logger.Println("Removing tenant by UID from the MSP portal " + deleteInp.Uid) | ||
deleteUrl := url.MspManagedTenantByUid(client.BaseUrl(), deleteInp.Uid) | ||
if err := client.NewDelete(ctx, deleteUrl).Send(&DeleteOutput{}); err != nil { | ||
return nil, err | ||
} | ||
|
||
return nil, nil | ||
} |
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,50 @@ | ||
package tenants_test | ||
|
||
import ( | ||
"context" | ||
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http" | ||
"github.com/CiscoDevnet/terraform-provider-cdo/go-client/msp/tenants" | ||
"github.com/google/uuid" | ||
"github.com/jarcoal/httpmock" | ||
"github.com/stretchr/testify/assert" | ||
netHttp "net/http" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestDelete(t *testing.T) { | ||
httpmock.Activate() | ||
defer httpmock.DeactivateAndReset() | ||
|
||
t.Run("successfully delete tenant", func(t *testing.T) { | ||
httpmock.Reset() | ||
var tenantUid = uuid.New().String() | ||
var deleteInput = tenants.DeleteByUidInput{ | ||
Uid: tenantUid, | ||
} | ||
httpmock.RegisterResponder( | ||
netHttp.MethodDelete, | ||
"/api/rest/v1/msp/tenants/"+tenantUid, | ||
httpmock.NewJsonResponderOrPanic(204, nil), | ||
) | ||
response, err := tenants.DeleteByUid(context.Background(), *http.MustNewWithConfig(baseUrl, "valid_token", 0, 0, time.Minute), deleteInput) | ||
assert.Nil(t, response) | ||
assert.Nil(t, err) | ||
}) | ||
|
||
t.Run("send through error if deletion failed", func(t *testing.T) { | ||
httpmock.Reset() | ||
var tenantUid = uuid.New().String() | ||
var deleteInput = tenants.DeleteByUidInput{ | ||
Uid: tenantUid, | ||
} | ||
httpmock.RegisterResponder( | ||
netHttp.MethodDelete, | ||
"/api/rest/v1/msp/tenants/"+tenantUid, | ||
httpmock.NewJsonResponderOrPanic(500, "Not found"), | ||
) | ||
response, err := tenants.DeleteByUid(context.Background(), *http.MustNewWithConfig(baseUrl, "valid_token", 0, 0, time.Minute), deleteInput) | ||
assert.Nil(t, response) | ||
assert.NotNil(t, err) | ||
}) | ||
} |
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
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
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