Skip to content

Commit

Permalink
use Variables in TestRequest structs, part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbloss committed Oct 4, 2023
1 parent e2fccd4 commit 1aea5ac
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 757 deletions.
157 changes: 58 additions & 99 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,108 +9,67 @@ import (

func TestCache(t *testing.T) {
// Arrange
id := ol.ID("Z2lkOi8vMTIzNDU2Nzg5OTg3NjU0MzIx")
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}},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" }} ] }}}}`,
}
testRequestTen := TestRequest{}

requests := []TestRequest{
{
Request: `{"query": "query TierList{account{tiers{alias,description,id,index,name}}}",
"variables":{}}`,
Response: `{"data":{"account":{
"tiers":[{{ template "tier_1" }}]
}}}`,
},
{
Request: `{"query": "query LifecycleList{account{lifecycles{alias,description,id,index,name}}}",
"variables":{}}`,
Response: `{"data":{"account":{
"lifecycles":[{{ template "lifecycle_1" }}]
}}}`,
},
{
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":{
"after": "",
"first": 100
}}`,
Response: `{"data":{"account":{
"teams":{
"nodes":[{{ template "team_1" }}]
}
}}}`,
},
{
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":{
"after": "",
"first": 100
}}`,
Response: `{"data":{"account":{"rubric":{
"categories":{
"nodes":[{{ template "category_1" }}]
}
}}}}`,
},
{
Request: `{"query": "{account{rubric{levels{nodes{alias,description,id,index,name},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}",
"variables":{}}`,
Response: `{"data":{"account":{"rubric":{
"levels":{
"nodes":[{{ template "level_1" }}]
}
}}}}`,
},
{
Request: `{"query": "query FilterList($after:String!$first:Int!){account{filters(after: $after, first: $first){nodes{connective,htmlUrl,id,name,predicates{key,keyData,type,value}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}",
"variables":{
"after": "",
"first": 100
}}`,
Response: `{"data":{"account":{
"filters":{
"nodes":[{{ template "filter_1" }}]
}
}}}`,
},
{
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":{
"after": "",
"first": 100
}}`,
Response: `{"data":{"account":{
"integrations":{
"nodes":[{{ template "integration_1" }}]
}
}}}`,
},
{
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":{
"after": "",
"first": 100
}}`,
Response: `{"data":{"account":{
"repositories":{
"hiddenCount": 0,
"nodes":[{{ template "repository_1" }}]
}
}}}`,
},
{
Request: `{"query": "query IntegrationList($after:String!$first:Int!){account{infrastructureResourceSchemas(after: $after, first: $first){nodes{type,schema},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor}}}}",
"variables":{
"after": "",
"first": 100
}}`,
Response: `{"data":{"account":{
"infrastructureResourceSchemas":{
"nodes":[
{{ template "infra_schema_1" }}
]
}
}}}`,
},
testRequestOne,
testRequestTwo,
testRequestThree,
testRequestFour,
testRequestFive,
testRequestSix,
testRequestSeven,
testRequestEight,
testRequestNine,
testRequestTen,
}

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

Expand Down
51 changes: 11 additions & 40 deletions category_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,47 +81,18 @@ func TestGetMissingRubricCategory(t *testing.T) {

func TestListRubricCategories(t *testing.T) {
// Arrange
requests := []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}}}}",
{{ template "pagination_initial_query_variables" }}
}`,
Response: `{
"data": {
"account": {
"rubric": {
"categories": {
"nodes": [
{
{{ template "rubric_categories_response1" }}
},
{
{{ template "rubric_categories_response2" }}
}
],
{{ template "pagination_initial_pageInfo_response" }},
"totalCount": 2
}}}}}`,
},
{
Request: `{"query": "query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{id,name},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}",
{{ template "pagination_second_query_variables" }}
}`,
Response: `{
"data": {
"account": {
"rubric": {
"categories": {
"nodes": [
{
{{ template "rubric_categories_response3" }}
}
],
{{ template "pagination_second_pageInfo_response" }},
"totalCount": 1
}}}}}`,
},
testRequestOne := 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: `{{ template "pagination_initial_query_variables" }}`,
Response: `{ "data": { "account": { "rubric": { "categories": { "nodes": [ { {{ template "rubric_categories_response1" }} }, { {{ template "rubric_categories_response2" }} } ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}}`,
}
testRequestTwo := 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: `{{ template "pagination_second_query_variables" }}`,
Response: `{ "data": { "account": { "rubric": { "categories": { "nodes": [ { {{ template "rubric_categories_response3" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}}`,
}
requests := []TestRequest{testRequestOne, testRequestTwo}

client := TmpPaginatedTestClient(t, "rubric/category_list", requests...)
// Act
response, err := client.ListCategories(nil)
Expand Down
49 changes: 11 additions & 38 deletions filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,45 +147,18 @@ func TestGetMissingFilter(t *testing.T) {

func TestListFilters(t *testing.T) {
// Arrange
requests := []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}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}",
{{ template "pagination_initial_query_variables" }}
}`,
Response: `{
"data": {
"account": {
"filters": {
"nodes": [
{
{{ template "filter_kubernetes_response" }}
},
{
{{ template "filter_tier1service_response" }}
}
],
{{ template "pagination_initial_pageInfo_response" }},
"totalCount": 2
}}}}`,
},
{
Request: `{"query": "query FilterList($after:String!$first:Int!){account{filters(after: $after, first: $first){nodes{connective,htmlUrl,id,name,predicates{key,keyData,type,value}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}",
{{ template "pagination_second_query_variables" }}
}`,
Response: `{
"data": {
"account": {
"filters": {
"nodes": [
{
{{ template "filter_complex_kubernetes_response" }}
}
],
{{ template "pagination_second_pageInfo_response" }},
"totalCount": 1
}}}}`,
},
testRequestOne := 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}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"`,
Variables: `{{ template "pagination_initial_query_variables" }}`,
Response: `{"data": { "account": { "filters": { "nodes": [ { {{ template "filter_kubernetes_response" }} }, { {{ template "filter_tier1service_response" }} } ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}`,
}
testRequestTwo := 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}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"`,
Variables: `{{ template "pagination_second_query_variables" }}`,
Response: `{"data": { "account": { "filters": { "nodes": [ { {{ template "filter_complex_kubernetes_response" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}`,
}
requests := []TestRequest{testRequestOne, testRequestTwo}

client := TmpPaginatedTestClient(t, "filter/list", requests...)
// Act
response, err := client.ListFilters(nil)
Expand Down
41 changes: 15 additions & 26 deletions group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,10 @@ func TestGetGroupWithAlias(t *testing.T) {

func TestListGroups(t *testing.T) {
// Arrange
requests := []TestRequest{
{
Request: `{"query": "query ($after:String!$first:Int!){account{groups(after: $after, first: $first){nodes{alias,id,description,htmlUrl,name,parent{alias,id}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}",
{{ template "pagination_initial_query_variables" }}
}`,
Response: `{
"data": {
testRequestOne := TestRequest{
Request: `"query": "query ($after:String!$first:Int!){account{groups(after: $after, first: $first){nodes{alias,id,description,htmlUrl,name,parent{alias,id}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"`,
Variables: `{{ template "pagination_initial_query_variables" }}`,
Response: `{ "data": {
"account": {
"groups": {
"nodes": [
Expand All @@ -265,20 +262,14 @@ func TestListGroups(t *testing.T) {
"parent": null
}
],
{{ template "pagination_initial_pageInfo_response" }},
{{ template "pagination_initial_pageInfo_response" }},
"totalCount": 2
}
}
}
}`,
},
{
Request: `{
"query": "query ($after:String!$first:Int!){account{groups(after: $after, first: $first){nodes{alias,id,description,htmlUrl,name,parent{alias,id}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}",
{{ template "pagination_second_query_variables" }}
}`,
Response: `{
"data": {
}}}}`,
}
testRequestTwo := TestRequest{
Request: `"query": "query ($after:String!$first:Int!){account{groups(after: $after, first: $first){nodes{alias,id,description,htmlUrl,name,parent{alias,id}},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"`,
Variables: `{{ template "pagination_second_query_variables" }}`,
Response: `{"data": {
"account": {
"groups": {
"nodes": [
Expand All @@ -294,14 +285,12 @@ func TestListGroups(t *testing.T) {
}
}
],
{{ template "pagination_second_pageInfo_response" }},
{{ template "pagination_second_pageInfo_response" }},
"totalCount": 1
}
}
}
}`,
},
}}}}`,
}
requests := []TestRequest{testRequestOne, testRequestTwo}

client := TmpPaginatedTestClient(t, "group/list", requests...)
// Act
response, err := client.ListGroups(nil)
Expand Down
Loading

0 comments on commit 1aea5ac

Please sign in to comment.