Skip to content

Commit

Permalink
Disallow zero prices
Browse files Browse the repository at this point in the history
  • Loading branch information
tzununbekov committed Mar 1, 2024
1 parent f04d6bf commit 1c4eb99
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions price/pricingbyservice/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ type PriceUSD struct {
}

func (p PriceUSD) Validate() error {
if p.PricePerGiB < 0 || p.PricePerHour < 0 {
return errors.New("prices should be zero or non negative")
if p.PricePerGiB <= 0 || p.PricePerHour <= 0 {
return errors.New("prices should be higher than 0")
}

return nil
Expand Down
25 changes: 25 additions & 0 deletions price/pricingbyservice/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,31 @@ func TestConfig_Validate(t *testing.T) {
},
wantErr: true,
},
{
name: "detects unset pricing",
fields: fields{
BasePrices: PriceByTypeUSD{
Residential: &PriceByServiceTypeUSD{
Wireguard: mprice,
Scraping: mprice,
DataTransfer: mprice,
DVPN: mprice,
},
Other: &PriceByServiceTypeUSD{
Scraping: mprice,
DataTransfer: mprice,
DVPN: mprice,
},
},
CountryModifiers: map[ISO3166CountryCode]Modifier{
"US": {
Residential: 1,
Other: 1,
},
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 1c4eb99

Please sign in to comment.