Skip to content

Commit

Permalink
Merge pull request #269 from OpsLevel/db/update-test-data-input
Browse files Browse the repository at this point in the history
Db/update test data input
  • Loading branch information
davidbloss authored Oct 12, 2023
2 parents 63514b6 + 7e2030b commit d0339a8
Show file tree
Hide file tree
Showing 28 changed files with 1,809 additions and 2,644 deletions.
256 changes: 114 additions & 142 deletions actions_test.go

Large diffs are not rendered by default.

142 changes: 57 additions & 85 deletions alert_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,13 @@ import (

func TestCreateAlertSourceService(t *testing.T) {
// Arrange
request := `{
"query": "mutation AlertSourceServiceCreate($input:AlertSourceServiceCreateInput!){alertSourceServiceCreate(input: $input){alertSourceService{alertSource{name,description,id,type,externalId,integration{id,name,type},url},id,service{id,aliases},status},errors{message,path}}}",
"variables":{
"input": {
"alertSourceExternalIdentifier": {
"externalId": "QWERTY",
"type": "datadog"
},
"service": {
"alias": "example"
}
}
}
}`
response := `{"data": {
"alertSourceServiceCreate": {
"alertSourceService": {
"service": {
"aliases": ["example"]
}
}
}
}}`
client := ABetterTestClient(t, "alert_source/create", request, response)
testRequest := NewTestRequest(
`"mutation AlertSourceServiceCreate($input:AlertSourceServiceCreateInput!){alertSourceServiceCreate(input: $input){alertSourceService{alertSource{name,description,id,type,externalId,integration{id,name,type},url},id,service{id,aliases},status},errors{message,path}}}"`,
`{"input": { "alertSourceExternalIdentifier": { "externalId": "QWERTY", "type": "datadog" }, "service": { "alias": "example" }}}`,
`{"data": { "alertSourceServiceCreate": { "alertSourceService": { "service": { "aliases": ["example"] }}}}}`,
)

client := BestTestClient(t, "alert_source/create", testRequest)
// Act
result, _ := client.CreateAlertSourceService(ol.AlertSourceServiceCreateInput{
Service: *ol.NewIdentifier("example"),
Expand All @@ -44,31 +27,28 @@ func TestCreateAlertSourceService(t *testing.T) {

func TestGetAlertSourceWithExternalIdentifier(t *testing.T) {
// Arrange
request := `{"query":"query AlertSourceGet($externalIdentifier:AlertSourceExternalIdentifier!){account{alertSource(externalIdentifier: $externalIdentifier){name,description,id,type,externalId,integration{id,name,type},url}}}",
"variables":{
"externalIdentifier": {
"type": "datadog",
"externalId": "12345678"
}
}}`
response := `{"data": {
"account": {
"alertSource": {
"description": "test",
"externalId": "12345678",
"id": "Z2lkOi8vb3BzbGV2ZWwvQWxlcnRTb3VyY2VzOjpQYWdlcmR1dHkvNjE",
"integration": {
"name": "test-integration",
"id": "Z2lkOi8vb3BzbGV2ZWwvSW50ZWdyYXRpb25zOjpQYWdlcmR1dHlJbnRlZ3JhdGlvbi8zMg",
"type": "datadog"
},
"name": "Example",
"type": "datadog",
"url": "https://example.com"
}
}
}}`
client := ABetterTestClient(t, "alert_source/get_with_external_identifier", request, response)
testRequest := NewTestRequest(
`"query AlertSourceGet($externalIdentifier:AlertSourceExternalIdentifier!){account{alertSource(externalIdentifier: $externalIdentifier){name,description,id,type,externalId,integration{id,name,type},url}}}"`,
`{"externalIdentifier": { "type": "datadog", "externalId": "12345678" }}`,
`{"data": {
"account": {
"alertSource": {
"description": "test",
"externalId": "12345678",
"id": "Z2lkOi8vb3BzbGV2ZWwvQWxlcnRTb3VyY2VzOjpQYWdlcmR1dHkvNjE",
"integration": {
"name": "test-integration",
"id": "Z2lkOi8vb3BzbGV2ZWwvSW50ZWdyYXRpb25zOjpQYWdlcmR1dHlJbnRlZ3JhdGlvbi8zMg",
"type": "datadog"
},
"name": "Example",
"type": "datadog",
"url": "https://example.com"
}
}}}`,
)

client := BestTestClient(t, "alert_source/get_with_external_identifier", testRequest)
// Act
result, err := client.GetAlertSourceWithExternalIdentifier(ol.AlertSourceExternalIdentifier{
Type: ol.AlertSourceTypeEnumDatadog,
Expand All @@ -83,28 +63,27 @@ func TestGetAlertSourceWithExternalIdentifier(t *testing.T) {

func TestGetAlertSource(t *testing.T) {
// Arrange
request := `{"query":"query AlertSourceGet($id:ID!){account{alertSource(id: $id){name,description,id,type,externalId,integration{id,name,type},url}}}",
"variables":{
"id": "Z2lkOi8vb3BzbGV2ZWwvQWxlcnRTb3VyY2VzOjpQYWdlcmR1dHkvNjE"
}}`
response := `{"data": {
"account": {
"alertSource": {
"description": "test",
"externalId": "12345678",
"id": "Z2lkOi8vb3BzbGV2ZWwvQWxlcnRTb3VyY2VzOjpQYWdlcmR1dHkvNjE",
"integration": {
"name": "test-integration",
"id": "Z2lkOi8vb3BzbGV2ZWwvSW50ZWdyYXRpb25zOjpQYWdlcmR1dHlJbnRlZ3JhdGlvbi8zMg",
"type": "datadog"
},
"name": "Example",
"type": "datadog",
"url": "https://example.com"
}
}
}}`
client := ABetterTestClient(t, "alert_source/get", request, response)
testRequest := NewTestRequest(
`"query AlertSourceGet($id:ID!){account{alertSource(id: $id){name,description,id,type,externalId,integration{id,name,type},url}}}"`,
`{"id": "Z2lkOi8vb3BzbGV2ZWwvQWxlcnRTb3VyY2VzOjpQYWdlcmR1dHkvNjE" }`,
`{"data": {
"account": {
"alertSource": {
"description": "test",
"externalId": "12345678",
"id": "Z2lkOi8vb3BzbGV2ZWwvQWxlcnRTb3VyY2VzOjpQYWdlcmR1dHkvNjE",
"integration": {
"name": "test-integration",
"id": "Z2lkOi8vb3BzbGV2ZWwvSW50ZWdyYXRpb25zOjpQYWdlcmR1dHlJbnRlZ3JhdGlvbi8zMg",
"type": "datadog"
},
"name": "Example",
"type": "datadog",
"url": "https://example.com"
}
}}}`,
)
client := BestTestClient(t, "alert_source/get", testRequest)
// Act
result, err := client.GetAlertSource("Z2lkOi8vb3BzbGV2ZWwvQWxlcnRTb3VyY2VzOjpQYWdlcmR1dHkvNjE")
// Assert
Expand All @@ -116,20 +95,13 @@ func TestGetAlertSource(t *testing.T) {

func TestDeleteAlertSourceService(t *testing.T) {
// Arrange
request := `{
"query": "mutation AlertSourceServiceDelete($input:AlertSourceDeleteInput!){alertSourceServiceDelete(input: $input){errors{message,path}}}",
"variables":{
"input": {
"id": "Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvODYz"
}
}
}`
response := `{"data": {
"alertSourceServiceDelete": {
"errors": []
}
}}`
client := ABetterTestClient(t, "alert_source/delete", request, response)
testRequest := NewTestRequest(
`"mutation AlertSourceServiceDelete($input:AlertSourceDeleteInput!){alertSourceServiceDelete(input: $input){errors{message,path}}}"`,
`{"input": { "id": "Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvODYz" }}`,
`{"data": { "alertSourceServiceDelete": { "errors": [] }}}`,
)

client := BestTestClient(t, "alert_source/delete", testRequest)
// Act
err := client.DeleteAlertSourceService("Z2lkOi8vb3BzbGV2ZWwvQ2F0ZWdvcnkvODYz")
// Assert
Expand Down
73 changes: 21 additions & 52 deletions aliases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,13 @@ import (

func TestCreateAliases(t *testing.T) {
// Arrange
request := `{
"query": "mutation AliasCreate($input:AliasCreateInput!){aliasCreate(input: $input){aliases,ownerId,errors{message,path}}}",
"variables":{
"input": {
"alias": "MyAwesomeAlias",
"ownerId": "Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS80MTc2"
}
}
}`
response := `{"data": {
"aliasCreate": {
"aliases": [
"MyCoolService",
"MyAwesomeAlias"
],
"ownerId": "Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS80MTc2",
"errors": []
}
}}`
client := ABetterTestClient(t, "aliases/create", request, response)
testRequest := NewTestRequest(
`"mutation AliasCreate($input:AliasCreateInput!){aliasCreate(input: $input){aliases,ownerId,errors{message,path}}}"`,
`{"input": { "alias": "MyAwesomeAlias", "ownerId": "Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS80MTc2" }}`,
`{"data": { "aliasCreate": { "aliases": [ "MyCoolService", "MyAwesomeAlias" ], "ownerId": "Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS80MTc2", "errors": [] }}}`,
)

client := BestTestClient(t, "aliases/create", testRequest)
// Act
result, err := client.CreateAliases("Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS80MTc2", []string{"MyAwesomeAlias"})
// Assert
Expand All @@ -40,22 +27,13 @@ func TestCreateAliases(t *testing.T) {

func TestDeleteServiceAlias(t *testing.T) {
// Arrange
request := `{
"query": "mutation AliasDelete($input:AliasDeleteInput!){aliasDelete(input: $input){deletedAlias,errors{message,path}}}",
"variables":{
"input": {
"alias": "MyAwesomeAlias",
"ownerType": "service"
}
}
}`
response := `{"data": {
"aliasDelete": {
"deletedAlias": "MyAwesomeAlias",
"errors": []
}
}}`
client := ABetterTestClient(t, "aliases/delete_service", request, response)
testRequest := NewTestRequest(
`"mutation AliasDelete($input:AliasDeleteInput!){aliasDelete(input: $input){deletedAlias,errors{message,path}}}"`,
`{"input": { "alias": "MyAwesomeAlias", "ownerType": "service" }}`,
`{"data": { "aliasDelete": { "deletedAlias": "MyAwesomeAlias", "errors": [] }}}`,
)

client := BestTestClient(t, "aliases/delete_service", testRequest)
// Act
err := client.DeleteServiceAlias("MyAwesomeAlias")
// Assert
Expand All @@ -64,22 +42,13 @@ func TestDeleteServiceAlias(t *testing.T) {

func TestDeleteTeamAlias(t *testing.T) {
// Arrange
request := `{
"query": "mutation AliasDelete($input:AliasDeleteInput!){aliasDelete(input: $input){deletedAlias,errors{message,path}}}",
"variables":{
"input": {
"alias": "MyAwesomeAlias",
"ownerType": "team"
}
}
}`
response := `{"data": {
"aliasDelete": {
"deletedAlias": "MyAwesomeAlias",
"errors": []
}
}}`
client := ABetterTestClient(t, "aliases/delete_team", request, response)
testRequest := NewTestRequest(
`"mutation AliasDelete($input:AliasDeleteInput!){aliasDelete(input: $input){deletedAlias,errors{message,path}}}"`,
`{"input": { "alias": "MyAwesomeAlias", "ownerType": "team" }}`,
`{"data": { "aliasDelete": { "deletedAlias": "MyAwesomeAlias", "errors": [] }}}`,
)

client := BestTestClient(t, "aliases/delete_team", testRequest)
// Act
err := client.DeleteTeamAlias("MyAwesomeAlias")
// Assert
Expand Down
94 changes: 47 additions & 47 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,51 @@ import (

func TestCache(t *testing.T) {
// Arrange
testRequestOne := TestRequest{
Request: `"query": "query TierList{account{tiers{alias,description,id,index,name}}}"`,
Variables: `"variables":{}`,
Response: `{"data":{"account":{ "tiers": [ {{ template "tier_1" }} ] }}}`,
}
testRequestTwo := TestRequest{
Request: `"query": "query LifecycleList{account{lifecycles{alias,description,id,index,name}}}"`,
Variables: `"variables":{}`,
Response: `{"data":{"account":{ "lifecycles":[{{ template "lifecycle_1" }}] }}}`,
}
testRequestThree := TestRequest{
Request: `"query": "query TeamList($after:String!$first:Int!){account{teams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},name,responsibilities,tags{nodes{id,key,value},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"`,
Variables: `"variables":{ "after": "", "first": 100 }`,
Response: `{"data":{"account":{ "teams":{ "nodes":[{{ template "team_1" }}] } }}}`,
}
testRequestFour := TestRequest{
Request: `"query": "query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{id,name},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}"`,
Variables: `"variables":{ "after": "", "first": 100 }`,
Response: `{"data":{"account":{"rubric":{ "categories":{ "nodes":[{{ template "category_1" }}] } }}}}`,
}
testRequestFive := TestRequest{
Request: `"query": "{account{rubric{levels{nodes{alias,description,id,index,name},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}"`,
Variables: `"variables":{}`,
Response: `{"data":{"account":{"rubric":{ "levels":{ "nodes":[{{ template "level_1" }}] } }}}}`,
}
testRequestSix := TestRequest{
Request: `"query": "query FilterList($after:String!$first:Int!){account{filters(after: $after, first: $first){nodes{connective,htmlUrl,id,name,predicates{key,keyData,type,value,caseSensitive}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"`,
Variables: `"variables":{ "after": "", "first": 100 }`,
Response: `{"data":{"account":{ "filters":{ "nodes":[{{ template "filter_1" }}] } }}}`,
}
testRequestSeven := TestRequest{
Request: `"query": "query IntegrationList($after:String!$first:Int!){account{integrations(after: $after, first: $first){nodes{id,name,type,createdAt,installedAt,... on AwsIntegration{iamRole,externalId,awsTagsOverrideOwnership,ownershipTagKeys},... on NewRelicIntegration{baseUrl,accountKey}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"`,
Variables: `"variables":{ "after": "", "first": 100 }`,
Response: `{"data":{"account":{ "integrations":{ "nodes":[{{ template "integration_1" }}] } }}}`,
}
testRequestEight := TestRequest{
Request: `"query": "query RepositoryList($after:String!$first:Int!){account{repositories(after: $after, first: $first){hiddenCount,nodes{archivedAt,createdOn,defaultAlias,defaultBranch,description,forked,htmlUrl,id,languages{name,usage},lastOwnerChangedAt,name,organization,owner{alias,id},private,repoKey,services{edges{atRoot,node{id,aliases},paths{href,path},serviceRepositories{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},tags{nodes{id,key,value},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},tier{alias,description,id,index,name},type,url,visible},organizationCount,ownedCount,pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount,visibleCount}}}"`,
Variables: `"variables":{ "after": "", "first": 100 }`,
Response: `{"data":{"account":{ "repositories":{ "hiddenCount": 0, "nodes":[{{ template "repository_1" }}] } }}}`,
}
testRequestNine := TestRequest{
Request: `"query": "query IntegrationList($after:String!$first:Int!){account{infrastructureResourceSchemas(after: $after, first: $first){nodes{type,schema},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor}}}}"`,
Variables: `"variables":{ "after": "", "first": 100 }`,
Response: `{"data":{"account":{ "infrastructureResourceSchemas":{ "nodes":[ {{ template "infra_schema_1" }} ] }}}}`,
}
testRequestOne := NewTestRequest(
`"query TierList{account{tiers{alias,description,id,index,name}}}"`,
`{}`,
`{"data":{"account":{ "tiers": [ {{ template "tier_1" }} ] }}}`,
)
testRequestTwo := NewTestRequest(
`"query LifecycleList{account{lifecycles{alias,description,id,index,name}}}"`,
`{}`,
`{"data":{"account":{ "lifecycles":[{{ template "lifecycle_1" }}] }}}`,
)
testRequestThree := NewTestRequest(
`"query TeamList($after:String!$first:Int!){account{teams(after: $after, first: $first){nodes{alias,id,aliases,contacts{address,displayName,id,type},group{alias,id},htmlUrl,manager{id,email,htmlUrl,name,role},members{nodes{id,email,htmlUrl,name,role},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},name,responsibilities,tags{nodes{id,key,value},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{ "teams":{ "nodes":[{{ template "team_1" }}] } }}}`,
)
testRequestFour := NewTestRequest(
`"query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{id,name},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}"`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{"rubric":{ "categories":{ "nodes":[{{ template "category_1" }}] } }}}}`,
)
testRequestFive := NewTestRequest(
`"{account{rubric{levels{nodes{alias,description,id,index,name},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}"`,
`{}`,
`{"data":{"account":{"rubric":{ "levels":{ "nodes":[{{ template "level_1" }}] } }}}}`,
)
testRequestSix := NewTestRequest(
`"query FilterList($after:String!$first:Int!){account{filters(after: $after, first: $first){nodes{connective,htmlUrl,id,name,predicates{key,keyData,type,value,caseSensitive}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{ "filters":{ "nodes":[{{ template "filter_1" }}] } }}}`,
)
testRequestSeven := NewTestRequest(
`"query IntegrationList($after:String!$first:Int!){account{integrations(after: $after, first: $first){nodes{id,name,type,createdAt,installedAt,... on AwsIntegration{iamRole,externalId,awsTagsOverrideOwnership,ownershipTagKeys},... on NewRelicIntegration{baseUrl,accountKey}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{ "integrations":{ "nodes":[{{ template "integration_1" }}] } }}}`,
)
testRequestEight := NewTestRequest(
`"query RepositoryList($after:String!$first:Int!){account{repositories(after: $after, first: $first){hiddenCount,nodes{archivedAt,createdOn,defaultAlias,defaultBranch,description,forked,htmlUrl,id,languages{name,usage},lastOwnerChangedAt,name,organization,owner{alias,id},private,repoKey,services{edges{atRoot,node{id,aliases},paths{href,path},serviceRepositories{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},tags{nodes{id,key,value},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount},tier{alias,description,id,index,name},type,url,visible},organizationCount,ownedCount,pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount,visibleCount}}}"`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{ "repositories":{ "hiddenCount": 0, "nodes":[{{ template "repository_1" }}] } }}}`,
)
testRequestNine := NewTestRequest(
`"query IntegrationList($after:String!$first:Int!){account{infrastructureResourceSchemas(after: $after, first: $first){nodes{type,schema},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor}}}}"`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{ "infrastructureResourceSchemas":{ "nodes":[ {{ template "infra_schema_1" }} ] }}}}`,
)
testRequestTen := TestRequest{}

requests := []TestRequest{
Expand All @@ -70,8 +70,8 @@ func TestCache(t *testing.T) {
}

id := ol.ID("Z2lkOi8vMTIzNDU2Nzg5OTg3NjU0MzIx")
client1 := TmpPaginatedTestClient(t, "cache1", requests...)
client2 := TmpPaginatedTestClient(t, "cache2", requests...)
client1 := BestTestClient(t, "cache1", requests...)
client2 := BestTestClient(t, "cache2", requests...)

// Act
ol.Cache.CacheAll(client1)
Expand Down
Loading

0 comments on commit d0339a8

Please sign in to comment.