Skip to content

Commit

Permalink
test(runReport): quota accumulated
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokisan committed Nov 14, 2022
1 parent d8c84bd commit 75f4d38
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ga4datatest/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,12 @@ func RunReportResponseBodyWithRowCount(count int64) func(*analyticsdata.RunRepor
res.RowCount = count
}
}

// RunReportResponseBodyWithQuota :
func RunReportResponseBodyWithQuota(
quota analyticsdata.PropertyQuota,
) func(*analyticsdata.RunReportResponse) {
return func(res *analyticsdata.RunReportResponse) {
res.PropertyQuota = &quota
}
}
53 changes: 53 additions & 0 deletions run_report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,57 @@ func TestRunReport(t *testing.T) {

assert.Equal(t, wantRequestedCount, resp.RequestedCount)
})
t.Run("quota consumed will be accumulated", func(t *testing.T) {
wantRequestedCount := 2
propertyQuota := analyticsdata.PropertyQuota{
ConcurrentRequests: &analyticsdata.QuotaStatus{
Consumed: 0,
Remaining: 10,
},
PotentiallyThresholdedRequestsPerHour: &analyticsdata.QuotaStatus{
Consumed: 0,
Remaining: 120,
},
ServerErrorsPerProjectPerHour: &analyticsdata.QuotaStatus{
Consumed: 0,
Remaining: 10,
},
TokensPerDay: &analyticsdata.QuotaStatus{
Consumed: 3,
Remaining: 24997,
},
TokensPerHour: &analyticsdata.QuotaStatus{
Consumed: 3,
Remaining: 4997,
},
TokensPerProjectPerHour: &analyticsdata.QuotaStatus{
Consumed: 3,
Remaining: 1247,
},
}
resBody := ga4datatest.RunReportResponseBody(
ga4datatest.RunReportResponseBodyWithRowCount(int64(wantRequestedCount)*RunReportMaxRowsLimit),
ga4datatest.RunReportResponseBodyWithQuota(propertyQuota),
)
testClient := ga4datatest.NewTestClient(resBody)

service, err := analyticsdata.NewService(ctx, option.WithHTTPClient(testClient))
require.NoError(t, err)

request := CreateRunReportRequest(analyticsdata.DateRange{
StartDate: "2022-10-01",
EndDate: "2022-10-01",
},
RunReportRequestWithPropertyQuota(),
)

resp, err := RunReport(ctx, service, "test", request)
require.NoError(t, err)

require.Equal(t, wantRequestedCount, resp.RequestedCount)

assert.Equal(t, propertyQuota.TokensPerDay.Consumed*int64(wantRequestedCount), resp.PropertyQuota.TokensPerDay.Consumed)
assert.Equal(t, propertyQuota.TokensPerHour.Consumed*int64(wantRequestedCount), resp.PropertyQuota.TokensPerHour.Consumed)
assert.Equal(t, propertyQuota.TokensPerProjectPerHour.Consumed*int64(wantRequestedCount), resp.PropertyQuota.TokensPerProjectPerHour.Consumed)
})
}

0 comments on commit 75f4d38

Please sign in to comment.