-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new testing to log.fatal cases (#99)
Add testing across log.fatal cases, and a few edge-cases
- Loading branch information
Showing
18 changed files
with
239 additions
and
33 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,10 +1,19 @@ | ||
package cmd | ||
|
||
import "testing" | ||
import ( | ||
"rare/cmd/helpers" | ||
"testing" | ||
) | ||
|
||
func TestAnalyze(t *testing.T) { | ||
testCommandSet(t, analyzeCommand(), | ||
`-m (\d+) testdata/graph.txt`, | ||
`-x -m (\d+) testdata/graph.txt`, | ||
) | ||
} | ||
|
||
func TestAnalyzeParseFatals(t *testing.T) { | ||
catchLogFatal(t, helpers.ExitCodeInvalidUsage, func() { | ||
testCommand(analyzeCommand(), "--quantile bla testdata/graph.txt") | ||
}) | ||
} |
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,37 @@ | ||
package helpers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type mockExitState struct { | ||
batchErr, aggErr, extSum int | ||
} | ||
|
||
func (s *mockExitState) ReadErrors() int { | ||
return s.batchErr | ||
} | ||
|
||
func (s *mockExitState) ParseErrors() uint64 { | ||
return uint64(s.aggErr) | ||
} | ||
|
||
func (s *mockExitState) MatchedLines() uint64 { | ||
return uint64(s.extSum) | ||
} | ||
|
||
func TestDetermineErrorState(t *testing.T) { | ||
s := mockExitState{0, 0, 1} | ||
assert.NoError(t, DetermineErrorState(&s, &s, &s)) | ||
|
||
s = mockExitState{0, 0, 0} | ||
assert.Error(t, DetermineErrorState(&s, &s, &s)) | ||
|
||
s = mockExitState{0, 1, 1} | ||
assert.Error(t, DetermineErrorState(&s, &s, &s)) | ||
|
||
s = mockExitState{1, 0, 1} | ||
assert.Error(t, DetermineErrorState(&s, &s, &s)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package helpers | ||
|
||
import ( | ||
"rare/pkg/logger" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func testLogFatal(t *testing.T, expectsCode int, f func()) (code int) { | ||
code = -1 | ||
|
||
oldExit := logger.OsExit | ||
defer func() { | ||
logger.OsExit = oldExit | ||
}() | ||
logger.OsExit = func(v int) { | ||
code = v | ||
panic("logger.osexit") | ||
} | ||
|
||
assert.PanicsWithValue(t, "logger.osexit", f) | ||
assert.Equal(t, expectsCode, code) | ||
return | ||
} |
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.