-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces a time range for the source/target links of a tenant.
- Loading branch information
1 parent
cc2c7c7
commit 562ae0e
Showing
5 changed files
with
231 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package invoice_test | ||
|
||
import ( | ||
"database/sql" | ||
"time" | ||
|
||
"github.com/appuio/appuio-cloud-reporting/pkg/db" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func (s *InvoiceGoldenSuite) TestInvoiceGolden_Tenants() { | ||
t := s.T() | ||
tdb := s.DB() | ||
|
||
_, err := db.CreateTenant(tdb, db.Tenant{ | ||
Source: "tricell", | ||
Target: sql.NullString{Valid: true, String: "98757"}, | ||
During: timerange(t, "-", "2022-01-20"), | ||
}) | ||
require.NoError(t, err) | ||
|
||
_, err = db.CreateTenant(tdb, db.Tenant{ | ||
Source: "tricell", | ||
Target: sql.NullString{Valid: true, String: "98942"}, | ||
During: timerange(t, "2022-01-20", "-"), | ||
}) | ||
require.NoError(t, err) | ||
|
||
_, err = db.CreateTenant(tdb, db.Tenant{ | ||
Source: "umbrellacorp", | ||
Target: sql.NullString{Valid: true, String: "96432"}, | ||
During: db.InfiniteRange(), | ||
}) | ||
require.NoError(t, err) | ||
|
||
_, err = db.CreateTenant(tdb, db.Tenant{ | ||
Source: "megacorp", | ||
Target: sql.NullString{Valid: true, String: "83492"}, | ||
During: db.InfiniteRange(), | ||
}) | ||
require.NoError(t, err) | ||
|
||
_, err = db.CreateProduct(tdb, db.Product{ | ||
Source: "my-product", | ||
Amount: 1, | ||
During: db.InfiniteRange(), | ||
}) | ||
require.NoError(t, err) | ||
|
||
_, err = db.CreateDiscount(tdb, db.Discount{ | ||
Source: "my-product", | ||
During: db.InfiniteRange(), | ||
}) | ||
require.NoError(t, err) | ||
|
||
query, err := db.CreateQuery(tdb, db.Query{ | ||
Name: "test", | ||
Description: "test description", | ||
Query: "test", | ||
Unit: "tps", | ||
During: db.InfiniteRange(), | ||
}) | ||
require.NoError(t, err) | ||
|
||
s.prom.queries[query.Query] = fakeQueryResults{ | ||
"my-product:my-cluster:tricell:my-namespace": fakeQuerySample{Value: 42}, // split over two tenant targets | ||
"my-product:my-cluster:megacorp:my-namespace": fakeQuerySample{Value: 42}, // same value to verify that the sum of both tricell tenant targets is correct | ||
"my-product:my-cluster:umbrellacorp:my-namespace": fakeQuerySample{Value: 14}, | ||
} | ||
|
||
runReport(t, tdb, s.prom, query.Query, "2022-01-01", "2022-01-30") | ||
invoiceEqualsGolden(t, "tenants", | ||
generateInvoice(t, tdb, 2022, time.January), | ||
*updateGolden) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
[ | ||
{ | ||
"Tenant": { | ||
"Source": "megacorp", | ||
"Target": "83492" | ||
}, | ||
"PeriodStart": "2022-01-01T00:00:00Z", | ||
"PeriodEnd": "2022-01-31T00:00:00Z", | ||
"Categories": [ | ||
{ | ||
"Source": "my-cluster:my-namespace", | ||
"Target": "", | ||
"Items": [ | ||
{ | ||
"Description": "test description", | ||
"QueryName": "test", | ||
"Source": "my-product", | ||
"Target": "", | ||
"Quantity": 29232, | ||
"QuantityMin": 42, | ||
"QuantityAvg": 42, | ||
"QuantityMax": 42, | ||
"Unit": "tps", | ||
"PricePerUnit": 1, | ||
"Discount": 0, | ||
"Total": 29232, | ||
"SubItems": {} | ||
} | ||
], | ||
"Total": 29232 | ||
} | ||
], | ||
"Total": 29232 | ||
}, | ||
{ | ||
"Tenant": { | ||
"Source": "tricell", | ||
"Target": "98757" | ||
}, | ||
"PeriodStart": "2022-01-01T00:00:00Z", | ||
"PeriodEnd": "2022-01-31T00:00:00Z", | ||
"Categories": [ | ||
{ | ||
"Source": "my-cluster:my-namespace", | ||
"Target": "", | ||
"Items": [ | ||
{ | ||
"Description": "test description", | ||
"QueryName": "test", | ||
"Source": "my-product", | ||
"Target": "", | ||
"Quantity": 19152, | ||
"QuantityMin": 42, | ||
"QuantityAvg": 42, | ||
"QuantityMax": 42, | ||
"Unit": "tps", | ||
"PricePerUnit": 1, | ||
"Discount": 0, | ||
"Total": 19152, | ||
"SubItems": {} | ||
} | ||
], | ||
"Total": 19152 | ||
} | ||
], | ||
"Total": 19152 | ||
}, | ||
{ | ||
"Tenant": { | ||
"Source": "tricell", | ||
"Target": "98942" | ||
}, | ||
"PeriodStart": "2022-01-01T00:00:00Z", | ||
"PeriodEnd": "2022-01-31T00:00:00Z", | ||
"Categories": [ | ||
{ | ||
"Source": "my-cluster:my-namespace", | ||
"Target": "", | ||
"Items": [ | ||
{ | ||
"Description": "test description", | ||
"QueryName": "test", | ||
"Source": "my-product", | ||
"Target": "", | ||
"Quantity": 10080, | ||
"QuantityMin": 42, | ||
"QuantityAvg": 42, | ||
"QuantityMax": 42, | ||
"Unit": "tps", | ||
"PricePerUnit": 1, | ||
"Discount": 0, | ||
"Total": 10080, | ||
"SubItems": {} | ||
} | ||
], | ||
"Total": 10080 | ||
} | ||
], | ||
"Total": 10080 | ||
}, | ||
{ | ||
"Tenant": { | ||
"Source": "umbrellacorp", | ||
"Target": "96432" | ||
}, | ||
"PeriodStart": "2022-01-01T00:00:00Z", | ||
"PeriodEnd": "2022-01-31T00:00:00Z", | ||
"Categories": [ | ||
{ | ||
"Source": "my-cluster:my-namespace", | ||
"Target": "", | ||
"Items": [ | ||
{ | ||
"Description": "test description", | ||
"QueryName": "test", | ||
"Source": "my-product", | ||
"Target": "", | ||
"Quantity": 9744, | ||
"QuantityMin": 14, | ||
"QuantityAvg": 14, | ||
"QuantityMax": 14, | ||
"Unit": "tps", | ||
"PricePerUnit": 1, | ||
"Discount": 0, | ||
"Total": 9744, | ||
"SubItems": {} | ||
} | ||
], | ||
"Total": 9744 | ||
} | ||
], | ||
"Total": 9744 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters