-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify part of code, add tests, make struct fields exported
- Loading branch information
1 parent
7bf2aca
commit 7e22c61
Showing
3 changed files
with
121 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package metrics | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestPushConfigValidateError(t *testing.T) { | ||
f := func(config *PushConfig) { | ||
t.Helper() | ||
if err := config.Validate(); err == nil { | ||
t.Fatalf("expecting non-nil error when validating %v", config) | ||
} | ||
} | ||
|
||
f(&PushConfig{}) | ||
f(&PushConfig{PushURL: "", Interval: time.Second}) | ||
f(&PushConfig{PushURL: "https://localhost:8080", Interval: -1 * time.Second}) | ||
f(&PushConfig{PushURL: "htt://localhost:8080", Interval: time.Second}) | ||
f(&PushConfig{PushURL: "http://localhost:8080", Interval: time.Second, ExtraLabels: "a{} "}) | ||
} | ||
|
||
func TestPushConfigValidateSuccess(t *testing.T) { | ||
f := func(config *PushConfig) { | ||
t.Helper() | ||
if err := config.Validate(); err != nil { | ||
t.Fatalf("expecting nil error when validating %v; err: %s", config, err) | ||
} | ||
} | ||
|
||
f(&PushConfig{PushURL: "http://localhost:8080", Interval: time.Second}) | ||
f(&PushConfig{PushURL: "http://localhost:8080", Interval: time.Second, ExtraLabels: `foo="bar"`}) | ||
} |
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