Skip to content

Commit

Permalink
CR feedback: reorder/scoping/comments
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantv committed Sep 12, 2022
1 parent 67069df commit ffd9b49
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
12 changes: 6 additions & 6 deletions sink.go
Expand Up @@ -43,12 +43,6 @@ type Sink interface {
io.Closer
}

type sinkRegistry struct {
mu sync.Mutex
factories map[string]func(*url.URL) (Sink, error) // keyed by scheme
openFile func(string, int, os.FileMode) (*os.File, error)
}

type errSinkNotFound struct {
scheme string
}
Expand All @@ -61,6 +55,12 @@ type nopCloserSink struct{ zapcore.WriteSyncer }

func (nopCloserSink) Close() error { return nil }

type sinkRegistry struct {
mu sync.Mutex
factories map[string]func(*url.URL) (Sink, error) // keyed by scheme
openFile func(string, int, os.FileMode) (*os.File, error) // type matches os.OpenFile
}

func newSinkRegistry() *sinkRegistry {
sr := &sinkRegistry{
factories: make(map[string]func(*url.URL) (Sink, error)),
Expand Down
2 changes: 1 addition & 1 deletion sink_test.go
Expand Up @@ -98,9 +98,9 @@ func TestRegisterSinkErrors(t *testing.T) {
{"http*", "not a valid scheme"},
}

r := newSinkRegistry()
for _, tt := range tests {
t.Run("scheme-"+tt.scheme, func(t *testing.T) {
r := newSinkRegistry()
err := r.RegisterSink(tt.scheme, nopFactory)
assert.ErrorContains(t, err, tt.err)
})
Expand Down
16 changes: 7 additions & 9 deletions sink_windows_test.go
Expand Up @@ -30,14 +30,6 @@ import (
)

func TestWindowsPaths(t *testing.T) {
sr := newSinkRegistry()

var openFilename string
sr.openFile = func(filename string, _ int, _ os.FileMode) (*os.File, error) {
openFilename = filename
return nil, assert.AnError
}

// See https://docs.microsoft.com/en-us/dotnet/standard/io/file-path-formats
tests := []struct {
msg string
Expand All @@ -63,7 +55,13 @@ func TestWindowsPaths(t *testing.T) {

for _, tt := range tests {
t.Run(tt.msg, func(t *testing.T) {
openFilename = "<not called>"
sr := newSinkRegistry()

openFilename := "<not called>"
sr.openFile = func(filename string, _ int, _ os.FileMode) (*os.File, error) {
openFilename = filename
return nil, assert.AnError
}

_, err := sr.newSink(tt.path)
assert.Equal(t, assert.AnError, err, "expect stub error from OpenFile")
Expand Down

0 comments on commit ffd9b49

Please sign in to comment.