|
| 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 | + "database/sql" |
| 9 | + "github.com/gitpod-io/gitpod/usage/pkg/db" |
| 10 | + "github.com/gitpod-io/gitpod/usage/pkg/db/dbtest" |
| 11 | + "github.com/google/uuid" |
| 12 | + "testing" |
| 13 | + "time" |
| 14 | +) |
| 15 | + |
| 16 | +func TestUsageReport_ToJSON(t *testing.T) { |
| 17 | + instanceForUsage := db.WorkspaceInstanceForUsage{ |
| 18 | + ID: uuid.New(), |
| 19 | + WorkspaceID: dbtest.GenerateWorkspaceID(), |
| 20 | + OwnerID: uuid.New(), |
| 21 | + ProjectID: sql.NullString{ |
| 22 | + String: "project-id", |
| 23 | + Valid: true, |
| 24 | + }, |
| 25 | + WorkspaceClass: "class", |
| 26 | + Type: "prebuild", |
| 27 | + UsageAttributionID: db.NewTeamAttributionID(uuid.New().String()), |
| 28 | + CreationTime: db.VarcharTime{}, |
| 29 | + StartedTime: db.VarcharTime{}, |
| 30 | + StoppingTime: db.VarcharTime{}, |
| 31 | + StoppedTime: db.VarcharTime{}, |
| 32 | + } |
| 33 | + report := UsageReport{ |
| 34 | + GenerationTime: time.Time{}, |
| 35 | + From: time.Time{}, |
| 36 | + To: time.Time{}, |
| 37 | + RawSessions: []db.WorkspaceInstanceForUsage{ |
| 38 | + { |
| 39 | + ID: nil, |
| 40 | + WorkspaceID: "", |
| 41 | + OwnerID: nil, |
| 42 | + ProjectID: sql.NullString{}, |
| 43 | + WorkspaceClass: "", |
| 44 | + Type: "", |
| 45 | + UsageAttributionID: "", |
| 46 | + CreationTime: db.VarcharTime{}, |
| 47 | + StartedTime: db.VarcharTime{}, |
| 48 | + StoppingTime: db.VarcharTime{}, |
| 49 | + StoppedTime: db.VarcharTime{}, |
| 50 | + }, |
| 51 | + }, |
| 52 | + InvalidSessions: []InvalidSession{ |
| 53 | + { |
| 54 | + Reason: "some-reason", |
| 55 | + Session: db.WorkspaceInstanceForUsage{}, |
| 56 | + }, |
| 57 | + }, |
| 58 | + UsageRecords: []db.WorkspaceInstanceUsage{ |
| 59 | + dbtest.NewWorkspaceInstanceUsage(t, db.WorkspaceInstanceUsage{}), |
| 60 | + }, |
| 61 | + } |
| 62 | +} |
0 commit comments