<commit_before>package docker

import (
	"bytes"
	"fmt"
	"io"
	"log"
	"net"
	"net/url"
	"os"
	"path/filepath"
	"runtime"
	"strconv"
	"strings"
	"syscall"
	"testing"
	"time"

	"github.com/docker/docker/daemon"
	"github.com/docker/docker/engine"
	"github.com/docker/docker/image"
	"github.com/docker/docker/nat"
	"github.com/docker/docker/runconfig"
	"github.com/docker/docker/sysinit"
	"github.com/docker/docker/utils"
)

const (
	unitTestImageName        = "docker-test-image"
	unitTestImageID          = "83599e29c455eb719f77d799bc7c51521b9551972f5a850d7ad265bc1b5292f6" // 1.0
	unitTestImageIDShort     = "83599e29c455"
	unitTestNetworkBridge    = "testdockbr0"
	unitTestStoreBase        = "/var/lib/docker/unit-tests"
	testDaemonAddr           = "127.0.0.1:4270"
	testDaemonProto          = "tcp"
	testDaemonHttpsProto     = "tcp"
	testDaemonHttpsAddr      = "localhost:4271"
	testDaemonRogueHttpsAddr = "localhost:4272"
)

var (
	// FIXME: globalDaemon is deprecated by globalEngine. All tests should be converted.
	globalDaemon           *daemon.Daemon
	globalEngine           *engine.Engine
	globalHttpsEngine      *engine.Engine
	globalRogueHttpsEngine *engine.Engine
	startFds               int
	startGoroutines        int
)

// FIXME: nuke() is deprecated by Daemon.Nuke()
func nuke(daemon *daemon.Daemon) error {
	return daemon.Nuke()
}

// FIXME: cleanup and nuke are redundant.
func cleanup(eng *engine.Engine, t *testing.T) error {
	daemon := mkDaemonFromEngine(eng, t)
	for _, container := range daemon.List() {
		container.Kill()
		daemon.Destroy(container)
	}
	job := eng.Job("images")
	images, err := job.Stdout.AddTable()
	if err != nil {
		t.Fatal(err)
	}
	if err := job.Run(); err != nil {
		t.Fatal(err)
	}
	for _, image := range images.Data {
		if image.Get("Id") != unitTestImageID {
			eng.Job("image_delete", image.Get("Id")).Run()
		}
	}
	return nil
}

func layerArchive(tarfile string) (io.Reader, error) {
	// FIXME: need to close f somewhere
	f, err := os.Open(tarfile)
	if err != nil {
		return nil, err
	}
	return f, nil
}

func init() {
	// Always use the same driver (vfs) for all integration tests.
	// To test other drivers, we need a dedicated driver validation suite.
	os.Setenv("DOCKER_DRIVER", "vfs")
	os.Setenv("TEST", "1")

	// Hack to run sys init during unit testing
	if selfPath := utils.SelfPath(); strings.Contains(selfPath, ".dockerinit") {
		sysinit.SysInit()
		return
	}

	if uid := syscall.Geteuid(); uid != 0 {<commit_msg>Fix integration tests by adding DOCKER_TMPDIR env in the test init function<commit_after>package docker

import (
	"bytes"
	"fmt"
	"io"
	"log"
	"net"
	"net/url"
	"os"
	"path/filepath"
	"runtime"
	"strconv"
	"strings"
	"syscall"
	"testing"
	"time"

	"github.com/docker/docker/daemon"
	"github.com/docker/docker/engine"
	"github.com/docker/docker/image"
	"github.com/docker/docker/nat"
	"github.com/docker/docker/runconfig"
	"github.com/docker/docker/sysinit"
	"github.com/docker/docker/utils"
)

const (
	unitTestImageName        = "docker-test-image"
	unitTestImageID          = "83599e29c455eb719f77d799bc7c51521b9551972f5a850d7ad265bc1b5292f6" // 1.0
	unitTestImageIDShort     = "83599e29c455"
	unitTestNetworkBridge    = "testdockbr0"
	unitTestStoreBase        = "/var/lib/docker/unit-tests"
	unitTestDockerTmpdir     = "/var/lib/docker/tmp"
	testDaemonAddr           = "127.0.0.1:4270"
	testDaemonProto          = "tcp"
	testDaemonHttpsProto     = "tcp"
	testDaemonHttpsAddr      = "localhost:4271"
	testDaemonRogueHttpsAddr = "localhost:4272"
)

var (
	// FIXME: globalDaemon is deprecated by globalEngine. All tests should be converted.
	globalDaemon           *daemon.Daemon
	globalEngine           *engine.Engine
	globalHttpsEngine      *engine.Engine
	globalRogueHttpsEngine *engine.Engine
	startFds               int
	startGoroutines        int
)

// FIXME: nuke() is deprecated by Daemon.Nuke()
func nuke(daemon *daemon.Daemon) error {
	return daemon.Nuke()
}

// FIXME: cleanup and nuke are redundant.
func cleanup(eng *engine.Engine, t *testing.T) error {
	daemon := mkDaemonFromEngine(eng, t)
	for _, container := range daemon.List() {
		container.Kill()
		daemon.Destroy(container)
	}
	job := eng.Job("images")
	images, err := job.Stdout.AddTable()
	if err != nil {
		t.Fatal(err)
	}
	if err := job.Run(); err != nil {
		t.Fatal(err)
	}
	for _, image := range images.Data {
		if image.Get("Id") != unitTestImageID {
			eng.Job("image_delete", image.Get("Id")).Run()
		}
	}
	return nil
}

func layerArchive(tarfile string) (io.Reader, error) {
	// FIXME: need to close f somewhere
	f, err := os.Open(tarfile)
	if err != nil {
		return nil, err
	}
	return f, nil
}

func init() {
	// Always use the same driver (vfs) for all integration tests.
	// To test other drivers, we need a dedicated driver validation suite.
	os.Setenv("DOCKER_DRIVER", "vfs")
	os.Setenv("TEST", "1")
	os.Setenv("DOCKER_TMPDIR", unitTestDockerTmpdir)

	// Hack to run sys init during unit testing
	if selfPath := utils.SelfPath(); strings.Contains(selfPath, ".dockerinit") {
		sysinit.SysInit()
		return
	}

	if uid := syscall.Geteuid(); uid != 0 {
{'fraction_non_alphanumeric': 0.13253719655442442, 'fraction_numerical': 0.030540328895849646, 'mean_word_length': 3.505291005291005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7559691', 'n_tokens_mistral': 2068, 'n_tokens_neox': 1906, 'n_words': 413}