-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge master into fix/trigger-schedule-fill
- Loading branch information
Showing
21 changed files
with
1,400 additions
and
93 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
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
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 |
---|---|---|
@@ -1,13 +1,20 @@ | ||
package remote | ||
|
||
import "time" | ||
import ( | ||
"time" | ||
|
||
"github.com/moira-alert/moira/metric_source/retries" | ||
) | ||
|
||
// Config represents config from remote storage. | ||
type Config struct { | ||
URL string | ||
CheckInterval time.Duration | ||
MetricsTTL time.Duration | ||
Timeout time.Duration | ||
User string | ||
Password string | ||
URL string `validate:"required,url"` | ||
CheckInterval time.Duration | ||
MetricsTTL time.Duration | ||
Timeout time.Duration `validate:"required,gt=0s"` | ||
User string | ||
Password string | ||
HealthcheckTimeout time.Duration `validate:"required,gt=0s"` | ||
Retries retries.Config | ||
HealthcheckRetries retries.Config | ||
} |
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,96 @@ | ||
package remote | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/go-playground/validator/v10" | ||
"github.com/moira-alert/moira" | ||
|
||
"github.com/moira-alert/moira/metric_source/retries" | ||
|
||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
func TestConfigWithValidateStruct(t *testing.T) { | ||
Convey("Test validating retries config", t, func() { | ||
type testcase struct { | ||
caseDesc string | ||
conf Config | ||
errIsNil bool | ||
} | ||
|
||
var ( | ||
testInitialInterval = time.Second * 5 | ||
testMaxInterval = time.Second * 10 | ||
testRetriesCount uint64 = 10 | ||
validatorErr = validator.ValidationErrors{} | ||
) | ||
|
||
testRetriesConf := retries.Config{ | ||
InitialInterval: testInitialInterval, | ||
MaxInterval: testMaxInterval, | ||
MaxRetriesCount: testRetriesCount, | ||
} | ||
|
||
cases := []testcase{ | ||
{ | ||
caseDesc: "with empty config", | ||
conf: Config{}, | ||
errIsNil: false, | ||
}, | ||
{ | ||
caseDesc: "with retries config set", | ||
conf: Config{ | ||
Retries: testRetriesConf, | ||
HealthcheckRetries: testRetriesConf, | ||
}, | ||
errIsNil: false, | ||
}, | ||
{ | ||
caseDesc: "with retries config set and some url", | ||
conf: Config{ | ||
URL: "http://test-graphite", | ||
Retries: testRetriesConf, | ||
HealthcheckRetries: testRetriesConf, | ||
}, | ||
errIsNil: false, | ||
}, | ||
{ | ||
caseDesc: "with retries config set, some url, timeout", | ||
conf: Config{ | ||
Timeout: time.Second, | ||
URL: "http://test-graphite", | ||
Retries: testRetriesConf, | ||
HealthcheckRetries: testRetriesConf, | ||
}, | ||
errIsNil: false, | ||
}, | ||
{ | ||
caseDesc: "with valid config", | ||
conf: Config{ | ||
Timeout: time.Second, | ||
HealthcheckTimeout: time.Millisecond, | ||
URL: "http://test-graphite", | ||
Retries: testRetriesConf, | ||
HealthcheckRetries: testRetriesConf, | ||
}, | ||
errIsNil: true, // nil, | ||
}, | ||
} | ||
|
||
for i := range cases { | ||
Convey(fmt.Sprintf("Case %d: %s", i+1, cases[i].caseDesc), func() { | ||
err := moira.ValidateStruct(cases[i].conf) | ||
|
||
if cases[i].errIsNil { | ||
So(err, ShouldBeNil) | ||
} else { | ||
So(errors.As(err, &validatorErr), ShouldBeTrue) | ||
} | ||
}) | ||
} | ||
}) | ||
} |
Oops, something went wrong.