-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): display status of Azure compliance subscriptions
Signed-off-by: Salim Afiune Maya <[email protected]>
- Loading branch information
Showing
4 changed files
with
207 additions
and
40 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 |
---|---|---|
|
@@ -84,3 +84,84 @@ func TestSplitAzureSubscriptionsApiResponse(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestCliListAzureTenantsAndSubscriptionsWithoutData(t *testing.T) { | ||
cliOutput := captureOutput(func() { | ||
assert.Nil(t, cliListTenantsAndSubscriptions(new(api.AzureIntegrationsResponse))) | ||
}) | ||
assert.Contains(t, cliOutput, "There are no Azure Tenants configured in your account.") | ||
|
||
t.Run("test JSON output", func(t *testing.T) { | ||
cli.EnableJSONOutput() | ||
defer cli.EnableHumanOutput() | ||
cliJSONOutput := captureOutput(func() { | ||
assert.Nil(t, cliListTenantsAndSubscriptions(new(api.AzureIntegrationsResponse))) | ||
}) | ||
expectedJSON := `{ | ||
"azure_subscriptions": [] | ||
} | ||
` | ||
assert.Equal(t, expectedJSON, cliJSONOutput) | ||
}) | ||
} | ||
|
||
/* | ||
func TestCliListAzureTenantsAndSubscriptionsWithDataEnabled(t *testing.T) { | ||
cliOutput := captureOutput(func() { | ||
assert.Nil(t, cliListTenantsAndSubscriptions(mockAzureIntegrationsResponse(1))) | ||
}) | ||
// NOTE (@afiune): We purposly leave trailing spaces in this table, we need them! | ||
expectedTable := ` | ||
AZURE TENANT AZURE SUBSCRIPTION STATUS | ||
---------------------------------------+--------------------------------------+---------- | ||
abc123xy-1234-abcd-a1b2-09876zxy1234 ABC123XX-1234-ABCD-1234-ABCD1234XYZZ Enabled | ||
` | ||
assert.Equal(t, strings.TrimPrefix(expectedTable, "\n"), cliOutput) | ||
} | ||
func TestCliListAzureTenantsAndSubscriptionsWithDataDisabled(t *testing.T) { | ||
cliOutput := captureOutput(func() { | ||
assert.Nil(t, cliListTenantsAndSubscriptions(mockAzureIntegrationsResponse(0))) | ||
}) | ||
// NOTE (@afiune): We purposly leave trailing spaces in this table, we need them! | ||
expectedTable := ` | ||
AZURE TENANT AZURE SUBSCRIPTION STATUS | ||
---------------------------------------+--------------------------------------+---------- | ||
abc123xy-1234-abcd-a1b2-09876zxy1234 ABC123XX-1234-ABCD-1234-ABCD1234XYZZ Disabled | ||
` | ||
assert.Equal(t, strings.TrimPrefix(expectedTable, "\n"), cliOutput) | ||
} | ||
func mockAzureIntegrationsResponse(enabled int) *api.AzureIntegrationsResponse { | ||
response := &api.AzureIntegrationsResponse{} | ||
err := json.Unmarshal([]byte(`{ | ||
"data": [ | ||
{ | ||
"CREATED_OR_UPDATED_BY": "[email protected]", | ||
"CREATED_OR_UPDATED_TIME": "2021-08-02T17:53:24.116Z", | ||
"DATA": { | ||
"TENANT_ID": "abc123xy-1234-abcd-a1b2-09876zxy1234" | ||
}, | ||
"ENABLED": `+strconv.Itoa(enabled)+`, | ||
"INTG_GUID": "MOCK_1234", | ||
"IS_ORG": 0, | ||
"NAME": "TF Config", | ||
"STATE": { | ||
"lastSuccessfulTime": "2021-Jun-04 09:40:39 UTC", | ||
"lastUpdatedTime": "2022-Jan-31 11:49:09 UTC", | ||
"ok": false | ||
}, | ||
"TYPE": "AZURE_CFG", | ||
"TYPE_NAME": "Azure Compliance" | ||
} | ||
], | ||
"message": "SUCCESS", | ||
"ok": true | ||
} | ||
`), response) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
return response | ||
} | ||
*/ |
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