-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust the rules for deciding to quote a string value
- Loading branch information
Showing
3 changed files
with
113 additions
and
47 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,59 @@ | ||
package hclog | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// This file contains tests that are sensitive to their location in the file, | ||
// because they contain line numbers. They're basically "quarantined" from the | ||
// other tests because they break all the time when new tests are added. | ||
|
||
func TestLoggerLoc(t *testing.T) { | ||
t.Run("includes the caller location", func(t *testing.T) { | ||
var buf bytes.Buffer | ||
|
||
logger := New(&LoggerOptions{ | ||
Name: "test", | ||
Output: &buf, | ||
IncludeLocation: true, | ||
}) | ||
|
||
logger.Info("this is test", "who", "programmer", "why", "testing is fun") | ||
|
||
str := buf.String() | ||
dataIdx := strings.IndexByte(str, ' ') | ||
rest := str[dataIdx+1:] | ||
|
||
// This test will break if you move this around, it's line dependent, just fyi | ||
assert.Equal(t, "[INFO] go-hclog/logger_loc_test.go:25: test: this is test: who=programmer why=\"testing is fun\"\n", rest) | ||
}) | ||
|
||
t.Run("includes the caller location excluding helper functions", func(t *testing.T) { | ||
var buf bytes.Buffer | ||
|
||
logMe := func(l Logger) { | ||
l.Info("this is test", "who", "programmer", "why", "testing is fun") | ||
} | ||
|
||
logger := New(&LoggerOptions{ | ||
Name: "test", | ||
Output: &buf, | ||
IncludeLocation: true, | ||
AdditionalLocationOffset: 1, | ||
}) | ||
|
||
logMe(logger) | ||
|
||
str := buf.String() | ||
dataIdx := strings.IndexByte(str, ' ') | ||
rest := str[dataIdx+1:] | ||
|
||
// This test will break if you move this around, it's line dependent, just fyi | ||
assert.Equal(t, "[INFO] go-hclog/logger_loc_test.go:49: test: this is test: who=programmer why=\"testing is fun\"\n", rest) | ||
}) | ||
|
||
} |
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