-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from m-lab/sandbox-soltesz-increase-coverage
Improve test coverage and add standard flag support
- Loading branch information
Showing
6 changed files
with
437 additions
and
143 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 |
---|---|---|
@@ -1,12 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"io/ioutil" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/m-lab/go/prometheusx" | ||
"github.com/m-lab/go/prometheusx/promtest" | ||
) | ||
|
||
func TestMetrics(t *testing.T) { | ||
receiverDuration.WithLabelValues("x") | ||
promtest.LintMetrics(t) | ||
} | ||
|
||
func Test_main(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
authfile string | ||
authtoken string | ||
repo string | ||
inmemory bool | ||
}{ | ||
{ | ||
name: "okay-default", | ||
repo: "fake-repo", | ||
authtoken: "token", | ||
inmemory: false, | ||
}, | ||
{ | ||
name: "okay-inmemory", | ||
authfile: "fake-token", | ||
repo: "fake-repo", | ||
inmemory: true, | ||
}, | ||
{ | ||
name: "missing-flags-usage", | ||
}, | ||
} | ||
flag.CommandLine.SetOutput(ioutil.Discard) | ||
osExit = func(int) {} | ||
for _, tt := range tests { | ||
*authtoken = tt.authtoken | ||
authtokenFile = []byte(tt.authfile) | ||
*githubOrg = "fake-org" | ||
*githubRepo = tt.repo | ||
*enableInMemory = tt.inmemory | ||
// Guarantee no port conflicts between tests of main. | ||
*prometheusx.ListenAddress = ":0" | ||
*receiverAddr = ":0" | ||
t.Run(tt.name, func(t *testing.T) { | ||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
go func() { | ||
main() | ||
wg.Done() | ||
}() | ||
cancelCtx() | ||
wg.Wait() | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.