Skip to content

Commit

Permalink
Fixed previous attempt at refactoring test API
Browse files Browse the repository at this point in the history
  • Loading branch information
fclairamb committed Mar 2, 2024
1 parent 805523b commit 13c3248
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"
"time"

log "github.com/fclairamb/go-log"
"github.com/fclairamb/go-log/gokit"
gklog "github.com/go-kit/log"
"github.com/spf13/afero"
Expand Down Expand Up @@ -41,7 +42,6 @@ func NewTestServer(t *testing.T, debug bool) *FtpServer {
return NewTestServerWithTestDriver(t, &TestServerDriver{Debug: debug})
}

// NewTestServerWithTestDriver provides a server instantiated with some settings
func NewTestServerWithTestDriver(t *testing.T, driver *TestServerDriver) *FtpServer {
t.Parallel()

Expand All @@ -64,14 +64,28 @@ func NewTestServerWithTestDriver(t *testing.T, driver *TestServerDriver) *FtpSer
driver.fs = afero.NewBasePathFs(afero.NewOsFs(), dir)
}

s := NewFtpServer(driver)

// If we are in debug mode, we should log things
var logger log.Logger
if driver.Debug {
s.Logger = gokit.NewWrap(gklog.NewLogfmtLogger(gklog.NewSyncWriter(os.Stdout))).With(
logger = gokit.NewWrap(gklog.NewLogfmtLogger(gklog.NewSyncWriter(os.Stdout))).With(
"ts", gokit.GKDefaultTimestampUTC,
"caller", gokit.GKDefaultCaller,
)
} else {
logger = nil
}

s := NewTestServerWithDriverAndLogger(t, driver, logger)

return s
}

// NewTestServerWithTestDriver provides a server instantiated with some settings
func NewTestServerWithDriverAndLogger(t *testing.T, driver MainDriver, logger log.Logger) *FtpServer {
s := NewFtpServer(driver)

if logger != nil {
s.Logger = logger
}

if err := s.Listen(); err != nil {
Expand All @@ -91,6 +105,10 @@ func NewTestServerWithTestDriver(t *testing.T, driver *TestServerDriver) *FtpSer
return s
}

func NewTestServerWithDriver(t *testing.T, driver MainDriver) *FtpServer {
return NewTestServerWithDriverAndLogger(t, driver, nil)
}

// TestServerDriver defines a minimal serverftp server driver
type TestServerDriver struct {
Debug bool // To display connection logs information
Expand Down

0 comments on commit 13c3248

Please sign in to comment.