-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for cloud ints #32
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d9da0cf
Add tests for cloud ints and refactor AWS test
Ricky-Thomas 8d57719
Apply suggestions from code review
Ricky-Thomas d0311d6
Refactor to accomodate review suggestions
Ricky-Thomas c2ed278
Merge branch 'master' into ricky/add_cloud_ints_tests
jirikuncar 1e2033c
Merge branch 'master' into ricky/add_cloud_ints_tests
jirikuncar 6fe0ace
Merge master into branch
Ricky-Thomas 07ae4b3
Update tests
Ricky-Thomas bc48b25
Merge branch 'ricky/add_cloud_ints_tests' of github.com:DataDog/datad…
Ricky-Thomas 43cc488
Refactor test suite
Ricky-Thomas b3ccb03
Cleanup updated Azure account
nmuesch 6c0070f
Make unique account generator function
nmuesch 93ab727
Merge branch 'master' into ricky/add_cloud_ints_tests
nmuesch be8e966
Use function to generate Azure + GCP accounts too
nmuesch d343619
Merge branch 'master' into ricky/add_cloud_ints_tests
nmuesch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,131 @@ | ||||||
package datadog_test | ||||||
|
||||||
import ( | ||||||
"fmt" | ||||||
"testing" | ||||||
"time" | ||||||
|
||||||
"github.com/DataDog/datadog-api-client-go/api/v1/datadog" | ||||||
"gotest.tools/assert" | ||||||
) | ||||||
|
||||||
func generateUniqueAwsLambdaAccounts() (datadog.AwsAccount, datadog.AwsAccountAndLambdaInput, datadog.AwsLogsServicesInput) { | ||||||
accountId := fmt.Sprintf("go_%09d", time.Now().UnixNano()%1000000000) | ||||||
var uniqueAwsAccount = datadog.AwsAccount{ | ||||||
AccountId: &accountId, | ||||||
RoleName: datadog.PtrString("DatadogAWSIntegrationRole"), | ||||||
AccountSpecificNamespaceRules: &map[string]bool{"opsworks": true}, | ||||||
FilterTags: &[]string{"testTag", "test:Tag2"}, | ||||||
HostTags: &[]string{"filter:one", "filtertwo"}, | ||||||
} | ||||||
|
||||||
var testLambdaArn = datadog.AwsAccountAndLambdaInput{ | ||||||
AccountId: *uniqueAwsAccount.AccountId, | ||||||
LambdaArn: "arn:aws:lambda:us-east-1:123456789101:function:GoClientTest", | ||||||
} | ||||||
|
||||||
var savedServices = datadog.AwsLogsServicesInput{ | ||||||
AccountId: *uniqueAwsAccount.AccountId, | ||||||
Services: []string{"s3", "elb", "elbv2", "cloudfront", "redshift", "lambda"}, | ||||||
} | ||||||
|
||||||
return uniqueAwsAccount, testLambdaArn, savedServices | ||||||
} | ||||||
|
||||||
// Test AddAWSLambdaARN and EnableServices endpoints | ||||||
func TestAddAndSaveAWSLogs(t *testing.T) { | ||||||
// Setup the Client we'll use to interact with the Test account | ||||||
teardownTest := setupTest(t) | ||||||
defer teardownTest(t) | ||||||
testawsacc, testLambdaAcc, testServices := generateUniqueAwsLambdaAccounts() | ||||||
defer uninstallAWSIntegration(testawsacc) | ||||||
|
||||||
// Assert AWS Integration Created with proper fields | ||||||
TESTAPICLIENT.AWSIntegrationApi.CreateAWSAccount(TESTAUTH, testawsacc) | ||||||
_, httpResp, err := TESTAPICLIENT.AWSLogsIntegrationApi.AddAWSLambdaARN(TESTAUTH, testLambdaAcc) | ||||||
if err != nil { | ||||||
t.Errorf("Error Creating AWS account: %v: %v", testawsacc.AccountId, err) | ||||||
} | ||||||
assert.Equal(t, httpResp.StatusCode, 200) | ||||||
|
||||||
_, httpResp, err = TESTAPICLIENT.AWSLogsIntegrationApi.EnableAWSLogServices(TESTAUTH, testServices) | ||||||
if err != nil { | ||||||
t.Errorf("Error enabling log services: %v", err) | ||||||
} | ||||||
assert.Equal(t, httpResp.StatusCode, 200) | ||||||
} | ||||||
|
||||||
func TestListAWSLogsServices(t *testing.T) { | ||||||
// Setup the Client we'll use to interact with the Test account | ||||||
teardownTest := setupTest(t) | ||||||
defer teardownTest(t) | ||||||
list_services_output, _, err := TESTAPICLIENT.AWSLogsIntegrationApi.AWSLogsServicesList(TESTAUTH) | ||||||
if err != nil { | ||||||
t.Errorf("Error list log services: %v", err) | ||||||
} | ||||||
|
||||||
// There are currently 6 supported AWS Logs services as noted in the docs | ||||||
// https://docs.datadoghq.com/api/?lang=bash#get-list-of-aws-log-ready-services | ||||||
assert.Check(t, len(list_services_output) >= 6) | ||||||
} | ||||||
|
||||||
func TestListAndDeleteAWSLogs(t *testing.T) { | ||||||
// Setup the Client we'll use to interact with the Test account | ||||||
teardownTest := setupTest(t) | ||||||
defer teardownTest(t) | ||||||
testAWSAcc, testLambdaAcc, testServices := generateUniqueAwsLambdaAccounts() | ||||||
defer uninstallAWSIntegration(testAWSAcc) | ||||||
// Create the AWS integration. | ||||||
TESTAPICLIENT.AWSIntegrationApi.CreateAWSAccount(TESTAUTH, testAWSAcc) | ||||||
|
||||||
// Add Lambda to Account | ||||||
add_output, httpresp, err := TESTAPICLIENT.AWSLogsIntegrationApi.AddAWSLambdaARN(TESTAUTH, testLambdaAcc) | ||||||
if err != nil || httpresp.StatusCode != 200 { | ||||||
t.Errorf("Error Adding Lambda %v: Status: %v: %v", add_output, httpresp.StatusCode, err) | ||||||
} | ||||||
|
||||||
// Enable services for Lambda | ||||||
TESTAPICLIENT.AWSLogsIntegrationApi.EnableAWSLogServices(TESTAUTH, testServices) | ||||||
|
||||||
// List AWS Logs integrations before deleting | ||||||
list_output_1, _, err := TESTAPICLIENT.AWSLogsIntegrationApi.AWSLogsList(TESTAUTH) | ||||||
if err != nil { | ||||||
t.Errorf("Error list logs: %v", err) | ||||||
} | ||||||
// Iterate over output and list Lambdas | ||||||
var x = false | ||||||
for _, Account := range list_output_1 { | ||||||
if Account.GetAccountId() == *testAWSAcc.AccountId { | ||||||
if Account.GetLambdas()[0].GetArn() == testLambdaAcc.LambdaArn { | ||||||
x = true | ||||||
} | ||||||
} | ||||||
} | ||||||
// Test that variable is true as expected | ||||||
assert.Equal(t, x, true) | ||||||
|
||||||
// Delete newly added Lambda | ||||||
delete_output, httpResp, err := TESTAPICLIENT.AWSLogsIntegrationApi.DeleteAWSLambdaARN(TESTAUTH, testLambdaAcc) | ||||||
if err != nil || httpResp.StatusCode != 200 { | ||||||
t.Errorf("Error Deleting Lambda %v: Status: %v: %v", delete_output, httpResp.StatusCode, err) | ||||||
} | ||||||
assert.Equal(t, httpResp.StatusCode, 200) | ||||||
|
||||||
// List AWS logs integrations after deleting | ||||||
list_output_2, _, _ := TESTAPICLIENT.AWSLogsIntegrationApi.AWSLogsList(TESTAUTH) | ||||||
|
||||||
var list_of_arns_2 []datadog.AwsLogsListOutputLambdas | ||||||
x = false | ||||||
for _, Account := range list_output_2 { | ||||||
if Account.GetAccountId() == *testAWSAcc.AccountId { | ||||||
list_of_arns_2 = Account.GetLambdas() | ||||||
} | ||||||
} | ||||||
for _, lambda := range list_of_arns_2 { | ||||||
if lambda.GetArn() == testLambdaAcc.LambdaArn { | ||||||
x = true | ||||||
} | ||||||
} | ||||||
// Check that ARN no longer exists after delete | ||||||
assert.Assert(t, x != true) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} |
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,145 @@ | ||
package datadog_test | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"testing" | ||
"time" | ||
|
||
"github.com/DataDog/datadog-api-client-go/api/v1/datadog" | ||
"gotest.tools/assert" | ||
) | ||
|
||
func generateUniqueAzureAccount() (datadog.AzureAccount, datadog.AzureAccount, datadog.AzureAccount) { | ||
tenantName := fmt.Sprintf("go_test-1234-5678-9101-%s", time.Now()) | ||
var testAzureAcct = datadog.AzureAccount{ | ||
ClientId: datadog.PtrString("testc7f6-1234-5678-9101-3fcbf464test"), | ||
ClientSecret: datadog.PtrString("testingx./Sw*g/Y33t..R1cH+hScMDt"), | ||
TenantName: datadog.PtrString(tenantName), | ||
} | ||
|
||
var testUpdateAzureAcct = datadog.AzureAccount{ | ||
ClientId: testAzureAcct.ClientId, | ||
ClientSecret: testAzureAcct.ClientSecret, | ||
TenantName: testAzureAcct.TenantName, | ||
NewClientId: datadog.PtrString("testc7f6-1234-5678-9101-3fcbf4update"), | ||
NewTenantName: datadog.PtrString("testc44-1234-5678-9101-cc0073update"), | ||
HostFilters: datadog.PtrString("filter:foo,test:bar"), | ||
} | ||
|
||
var testAzureUpdateHostFilters = datadog.AzureAccount{ | ||
ClientId: testUpdateAzureAcct.NewClientId, | ||
TenantName: testUpdateAzureAcct.NewTenantName, | ||
HostFilters: datadog.PtrString("test:foo,test:bar"), | ||
} | ||
|
||
return testAzureAcct, testUpdateAzureAcct, testAzureUpdateHostFilters | ||
} | ||
|
||
func TestAzureCreate(t *testing.T) { | ||
// Setup the Client we'll use to interact with the Test account | ||
teardownTest := setupTest(t) | ||
defer teardownTest(t) | ||
testAzureAcct, _, _ := generateUniqueAzureAccount() | ||
defer uninstallAzureIntegration(testAzureAcct) | ||
|
||
_, httpResp, err := TESTAPICLIENT.AzureIntegrationApi.CreateAzureIntegration(TESTAUTH, testAzureAcct) | ||
if err != nil { | ||
t.Errorf("Error Creating Azure intg: %v", err) | ||
} | ||
assert.Equal(t, httpResp.StatusCode, 200) | ||
} | ||
|
||
func TestAzureListandDelete(t *testing.T) { | ||
// Setup the Client we'll use to interact with the Test account | ||
teardownTest := setupTest(t) | ||
defer teardownTest(t) | ||
testAzureAcct, _, testAzureUpdateHostFilters := generateUniqueAzureAccount() | ||
defer uninstallAzureIntegration(testAzureAcct) | ||
defer uninstallAzureIntegration(testAzureUpdateHostFilters) | ||
|
||
// Setup Azure Account to List | ||
TESTAPICLIENT.AzureIntegrationApi.CreateAzureIntegration(TESTAUTH, testAzureAcct) | ||
|
||
azure_list_output, _, err := TESTAPICLIENT.AzureIntegrationApi.ListAzureIntegration(TESTAUTH) | ||
if err != nil { | ||
t.Errorf("Error listing azure intgs: %v", err) | ||
} | ||
var x datadog.AzureAccount | ||
for _, Account := range azure_list_output { | ||
if Account.GetClientId() == *testAzureAcct.ClientId { | ||
x = Account | ||
} | ||
} | ||
assert.Equal(t, x.GetClientId(), *testAzureAcct.ClientId) | ||
assert.Equal(t, x.GetTenantName(), *testAzureAcct.TenantName) | ||
|
||
// Assert returned list is greater than or equal to 1 | ||
assert.Assert(t, len(azure_list_output) >= 1) | ||
|
||
// Test account deletion as well | ||
_, httpResp, err := TESTAPICLIENT.AzureIntegrationApi.DeleteAzureIntegration(TESTAUTH, testAzureAcct) | ||
if httpResp.StatusCode != 200 || err != nil { | ||
t.Errorf("Error uninstalling Azure Account: %v, Another test may have already removed this account.", testAzureAcct) | ||
} | ||
assert.Equal(t, httpResp.StatusCode, 200) | ||
} | ||
|
||
func TestUpdateAzureAccount(t *testing.T) { | ||
// Setup the Client we'll use to interact with the Test account | ||
teardownTest := setupTest(t) | ||
defer teardownTest(t) | ||
testAzureAcct, testUpdateAzureAcct, testAzureUpdateHostFilters := generateUniqueAzureAccount() | ||
defer uninstallAzureIntegration(testAzureAcct) | ||
|
||
// Setup Azure Account to Update | ||
TESTAPICLIENT.AzureIntegrationApi.CreateAzureIntegration(TESTAUTH, testAzureAcct) | ||
|
||
_, httpResp, err := TESTAPICLIENT.AzureIntegrationApi.UpdateAzureIntegration(TESTAUTH, testUpdateAzureAcct) | ||
defer uninstallAzureIntegration(testUpdateAzureAcct) | ||
if err != nil { | ||
t.Errorf("Error Updating Azure Account: %v", err) | ||
} | ||
|
||
assert.Equal(t, httpResp.StatusCode, 200) | ||
|
||
// List account to ensure update worked. | ||
azure_list_output, _, err := TESTAPICLIENT.AzureIntegrationApi.ListAzureIntegration(TESTAUTH) | ||
if err != nil { | ||
t.Errorf("Error listing Azure intgs: %v", err) | ||
} | ||
var x datadog.AzureAccount | ||
for _, Account := range azure_list_output { | ||
if Account.GetClientId() == *testUpdateAzureAcct.NewClientId { | ||
x = Account | ||
} | ||
} | ||
assert.Equal(t, x.GetClientId(), *testUpdateAzureAcct.NewClientId) | ||
assert.Equal(t, x.GetTenantName(), *testUpdateAzureAcct.NewTenantName) | ||
assert.Equal(t, x.GetHostFilters(), *testUpdateAzureAcct.HostFilters) | ||
|
||
// Test update host filters endpoint | ||
_, httpResp, err = TESTAPICLIENT.AzureIntegrationApi.AzureUpdateHostFilters(TESTAUTH, testAzureUpdateHostFilters) | ||
if err != nil { | ||
t.Errorf("Error Updating Azure Host Filters: %v", err) | ||
} | ||
assert.Equal(t, httpResp.StatusCode, 200) | ||
hf_list_output, _, err := TESTAPICLIENT.AzureIntegrationApi.ListAzureIntegration(TESTAUTH) | ||
if err != nil { | ||
t.Errorf("Error listing Azure intgs: %v", err) | ||
} | ||
var y datadog.AzureAccount | ||
for _, Account := range hf_list_output { | ||
if Account.GetClientId() == *testAzureUpdateHostFilters.ClientId { | ||
y = Account | ||
} | ||
} | ||
assert.Equal(t, y.GetHostFilters(), *testAzureUpdateHostFilters.HostFilters) | ||
} | ||
|
||
func uninstallAzureIntegration(account datadog.AzureAccount) { | ||
_, httpresp, err := TESTAPICLIENT.AzureIntegrationApi.DeleteAzureIntegration(TESTAUTH, account) | ||
if httpresp.StatusCode != 200 || err != nil { | ||
log.Printf("Error uninstalling Azure Account: %v, Another test may have already removed this account.", account) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.