|
| 1 | +// Copyright (c) 2022 Gitpod GmbH. All rights reserved. |
| 2 | +// Licensed under the GNU Affero General Public License (AGPL). |
| 3 | +// See License-AGPL.txt in the project root for license information. |
| 4 | + |
| 5 | +package contentservice |
| 6 | + |
| 7 | +import ( |
| 8 | + "github.com/gitpod-io/gitpod/usage/pkg/db" |
| 9 | + "github.com/gitpod-io/gitpod/usage/pkg/db/dbtest" |
| 10 | + "github.com/google/uuid" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | + "testing" |
| 13 | + "time" |
| 14 | +) |
| 15 | + |
| 16 | +func TestUsageReport_GetUsageRecordsForAttributionID(t *testing.T) { |
| 17 | + attributionID_A, attributionID_B := db.NewTeamAttributionID(uuid.New().String()), db.NewTeamAttributionID(uuid.New().String()) |
| 18 | + |
| 19 | + report := UsageReport{ |
| 20 | + GenerationTime: time.Now(), |
| 21 | + From: time.Now(), |
| 22 | + To: time.Now(), |
| 23 | + UsageRecords: []db.WorkspaceInstanceUsage{ |
| 24 | + dbtest.NewWorkspaceInstanceUsage(t, db.WorkspaceInstanceUsage{ |
| 25 | + AttributionID: attributionID_A, |
| 26 | + }), |
| 27 | + dbtest.NewWorkspaceInstanceUsage(t, db.WorkspaceInstanceUsage{ |
| 28 | + AttributionID: attributionID_A, |
| 29 | + }), |
| 30 | + dbtest.NewWorkspaceInstanceUsage(t, db.WorkspaceInstanceUsage{ |
| 31 | + AttributionID: attributionID_B, |
| 32 | + }), |
| 33 | + }, |
| 34 | + } |
| 35 | + |
| 36 | + filteredToAttributionA := report.GetUsageRecordsForAttributionID(attributionID_A) |
| 37 | + require.Equal(t, []db.WorkspaceInstanceUsage{report.UsageRecords[0], report.UsageRecords[1]}, filteredToAttributionA) |
| 38 | + |
| 39 | + filteredToAttributionB := report.GetUsageRecordsForAttributionID(attributionID_B) |
| 40 | + require.Equal(t, []db.WorkspaceInstanceUsage{report.UsageRecords[2]}, filteredToAttributionB) |
| 41 | + |
| 42 | + filteredToAbsentAttribution := report.GetUsageRecordsForAttributionID(db.NewTeamAttributionID(uuid.New().String())) |
| 43 | + require.Len(t, filteredToAbsentAttribution, 0) |
| 44 | +} |
0 commit comments