Skip to content

Commit d98a8c5

Browse files
committed
testutil/daemon: fail gracefully if DEST is unset
If neither of the DOCKER_INTEGRATION_DAEMON_DEST or DEST environment variables are set, integration tests panic with a nil-dereference panic in os.(*File).Name(...). This is a very unhelpful behaviour for someone trying to run integration tests interactively. Fix up the logic to avoid dereferencing nil os.File pointers and instead fail the test immediately with an actionable error message. Signed-off-by: Cory Snider <csnider@mirantis.com>
1 parent 8995619 commit d98a8c5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

testutil/daemon/daemon.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,9 @@ func New(t testing.TB, ops ...Option) *Daemon {
216216
if dest == "" {
217217
dest = os.Getenv("DEST")
218218
}
219+
assert.Assert(t, dest != "", "Please set the DOCKER_INTEGRATION_DAEMON_DEST or the DEST environment variable")
219220
dest = filepath.Join(dest, t.Name())
220221

221-
assert.Check(t, dest != "", "Please set the DOCKER_INTEGRATION_DAEMON_DEST or the DEST environment variable")
222-
223222
if os.Getenv("DOCKER_ROOTLESS") != "" {
224223
if os.Getenv("DOCKER_REMAP_ROOT") != "" {
225224
t.Skip("DOCKER_ROOTLESS doesn't support DOCKER_REMAP_ROOT currently")
@@ -412,6 +411,9 @@ func (d *Daemon) ScanLogs(ctx context.Context, match func(s string) bool) (bool,
412411

413412
// TailLogs tails N lines from the daemon logs
414413
func (d *Daemon) TailLogs(n int) ([][]byte, error) {
414+
if d.logFile == nil {
415+
return nil, errors.New("d.logFile is nil")
416+
}
415417
logF, err := os.Open(d.logFile.Name())
416418
if err != nil {
417419
return nil, errors.Wrap(err, "error opening daemon log file after failed start")

0 commit comments

Comments
 (0)