-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: refactor added cfg internal struct Signed-off-by: Bruno Bressi <[email protected]> * chore: added errors & validation Signed-off-by: Bruno Bressi <[email protected]> * refactor: intoduce general TM config Signed-off-by: Bruno Bressi <[email protected]> * chore: validate only general config Signed-off-by: Bruno Bressi <[email protected]> * chore: added licence Signed-off-by: Bruno Bressi <[email protected]> --------- Signed-off-by: Bruno Bressi <[email protected]>
- Loading branch information
Showing
7 changed files
with
191 additions
and
60 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,30 @@ | ||
// sparrow | ||
// (C) 2023, Deutsche Telekom IT GmbH | ||
// | ||
// Deutsche Telekom IT GmbH and all other contributors / | ||
// copyright owners license this file to you under the Apache | ||
// License, Version 2.0 (the "License"); you may not use this | ||
// file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package targets | ||
|
||
import "errors" | ||
|
||
// ErrInvalidCheckInterval is returned when the check interval is invalid | ||
var ErrInvalidCheckInterval = errors.New("invalid check interval") | ||
|
||
// ErrInvalidRegistrationInterval is returned when the registration interval is invalid | ||
var ErrInvalidRegistrationInterval = errors.New("invalid registration interval") | ||
|
||
// ErrInvalidUnhealthyThreshold is returned when the unhealthy threshold is invalid | ||
var ErrInvalidUnhealthyThreshold = errors.New("invalid unhealthy threshold") |
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// sparrow | ||
// (C) 2023, Deutsche Telekom IT GmbH | ||
// | ||
// Deutsche Telekom IT GmbH and all other contributors / | ||
// copyright owners license this file to you under the Apache | ||
// License, Version 2.0 (the "License"); you may not use this | ||
// file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package targets | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestTargetManagerConfig_Validate(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
cfg Config | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "empty config", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "valid config - non-zero values", | ||
cfg: Config{ | ||
UnhealthyThreshold: 1 * time.Second, | ||
CheckInterval: 1 * time.Second, | ||
RegistrationInterval: 1 * time.Second, | ||
}, | ||
}, | ||
{ | ||
name: "valid config - zero values", | ||
cfg: Config{ | ||
UnhealthyThreshold: 0, | ||
CheckInterval: 1 * time.Second, | ||
RegistrationInterval: 0, | ||
}, | ||
}, | ||
{ | ||
name: "invalid config - zero check interval", | ||
cfg: Config{ | ||
UnhealthyThreshold: 1 * time.Second, | ||
CheckInterval: 0, | ||
RegistrationInterval: 1 * time.Second, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "invalid config - negative values", | ||
cfg: Config{ | ||
UnhealthyThreshold: -1 * time.Second, | ||
CheckInterval: 1 * time.Second, | ||
RegistrationInterval: 1 * time.Second, | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := tt.cfg.Validate(); (err != nil) != tt.wantErr { | ||
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |