Skip to content

Commit

Permalink
Make InvalidFileDescriptor public
Browse files Browse the repository at this point in the history
* Change log_writer tests to run sequentially - In a number of tests, we adjust the color settings of the terminal, which adjusts it globally. There are edge cases, therefore, where our adjusting color in one test could adjust it for another test and cause odd failures

Signed-off-by: David Freilich <[email protected]>
  • Loading branch information
dfreilich committed Feb 9, 2021
1 parent 098fca9 commit 0443e9e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/logging/log_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (tw *LogWriter) Fd() uintptr {
return file.Fd()
}

return invalidFileDescriptor
return InvalidFileDescriptor
}

// Remove all ANSI color information.
Expand Down
6 changes: 3 additions & 3 deletions internal/logging/log_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
)

func TestLogWriter(t *testing.T) {
spec.Run(t, "LogWriter", testLogWriter, spec.Parallel(), spec.Report(report.Terminal{}))
spec.Run(t, "LogWriter", testLogWriter, spec.Sequential(), spec.Report(report.Terminal{}))
}

func testLogWriter(t *testing.T, when spec.G, it spec.S) {
Expand Down Expand Up @@ -66,10 +66,10 @@ func testLogWriter(t *testing.T, when spec.G, it spec.S) {
})

when("out is just a Writer", func() {
it("returns 0", func() {
it("returns the invalid file descriptor", func() {
var out *bytes.Buffer
writer = ilogging.NewLogWriter(out, clockFunc, true)
h.AssertEq(t, int(writer.Fd()), -1)
h.AssertEq(t, writer.Fd(), ilogging.InvalidFileDescriptor)
})
})
})
Expand Down
7 changes: 4 additions & 3 deletions internal/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ const (
// log level to use when debug is true
verboseLevel = log.DebugLevel
// time format the out logging uses
timeFmt = "2006/01/02 15:04:05.000000"
invalidFileDescriptor = ^(uintptr(0))
timeFmt = "2006/01/02 15:04:05.000000"
// InvalidFileDescriptor based on https://golang.org/src/os/file_unix.go?s=2183:2210#L57
InvalidFileDescriptor = ^(uintptr(0))
)

// LogWithWriters is a logger used with the pack CLI, allowing users to print logs for various levels, including Info, Debug and Error
Expand Down Expand Up @@ -133,7 +134,7 @@ func IsTerminal(w io.Writer) (uintptr, bool) {
return termFd, isTerm
}

return invalidFileDescriptor, false
return InvalidFileDescriptor, false
}

func formatLevel(ll log.Level) string {
Expand Down

0 comments on commit 0443e9e

Please sign in to comment.