Skip to content

Commit

Permalink
fix: missing for granularity validation
Browse files Browse the repository at this point in the history
  • Loading branch information
tukaelu committed Oct 15, 2023
1 parent 87162ef commit 863db4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func ValidateMetricRetantionPeriod(from, to int64) error {

// ValidateGranularity ...
func ValidateGranularity(s string) error {
valid := []string{"1m", "5m", "30m", "4h", "1d", "1w"}
valid := []string{"1m", "5m", "10m", "1h", "2h", "4h", "1d"}
if !slices.Contains(valid, s) {
return fmt.Errorf("unsupported granularity pattern %s has been set", s)
}
Expand Down
12 changes: 12 additions & 0 deletions internal/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ func TestValidateMetricRetantionPeriod(t *testing.T) {
"specified for a metric retention period of one day beyond that specified.",
)
}

func TestValidateGranularity(t *testing.T) {
expectedErr := fmt.Errorf("unsupported granularity pattern 1w has been set")
assert.Equal(t, nil, ValidateGranularity("1m"), "The specified granularity that is supported.")
assert.Equal(t, nil, ValidateGranularity("5m"), "The specified granularity that is supported.")
assert.Equal(t, nil, ValidateGranularity("10m"), "The specified granularity that is supported.")
assert.Equal(t, nil, ValidateGranularity("1h"), "The specified granularity that is supported.")
assert.Equal(t, nil, ValidateGranularity("2h"), "The specified granularity that is supported.")
assert.Equal(t, nil, ValidateGranularity("4h"), "The specified granularity that is supported.")
assert.Equal(t, nil, ValidateGranularity("1d"), "The specified granularity that is supported.")
assert.Equal(t, expectedErr, ValidateGranularity("1w"), "Unsupported granularity was specified.")
}

0 comments on commit 863db4f

Please sign in to comment.