<commit_before>package docker

import (
	"io/ioutil"
	"testing"
)

// mkTestContext generates a build context from the contents of the provided dockerfile.
// This context is suitable for use as an argument to BuildFile.Build()
func mkTestContext(dockerfile string, files [][2]string, t *testing.T) Archive {
	context, err := mkBuildContext(dockerfile, files)
	if err != nil {
		t.Fatal(err)
	}
	return context
}

// A testContextTemplate describes a build context and how to test it
type testContextTemplate struct {
	// Contents of the Dockerfile
	dockerfile string
	// Additional files in the context, eg [][2]string{"./passwd", "gordon"}
	files [][2]string
	// Test commands to run in the resulting image
	tests []testCommand
}

// A testCommand describes a command to run in a container, and the exact output required to pass the test
type testCommand struct {
	// The command to run, eg. []string{"echo", "hello", "world"}
	cmd []string
	// The exact output expected, eg. "hello world\n"
	output string
}

// A table of all the contexts to build and test.
// A new docker runtime will be created and torn down for each context.
var testContexts []testContextTemplate = []testContextTemplate{
	{
		`
# VERSION		0.1
# DOCKER-VERSION	0.2

from   docker-ut
run    sh -c 'echo root:testpass > /tmp/passwd'
run    mkdir -p /var/run/sshd
`,
		nil,
		[]testCommand{
			{[]string{"cat", "/tmp/passwd"}, "root:testpass\n"},
			{[]string{"ls", "-d", "/var/run/sshd"}, "/var/run/sshd\n"},
		},
	},

	{
		`
# VERSION		0.1
# DOCKER-VERSION	0.2

from   docker-ut
run    sh -c 'echo root:testpass > /tmp/passwd'
run    mkdir -p /var/run/sshd`,
		nil,
		[]testCommand{
			{[]string{"cat", "/tmp/passwd"}, "root:testpass\n"},
			{[]string{"ls", "-d", "/var/run/sshd"}, "/var/run/sshd\n"},
		},
	},<commit_msg>* Builder: remove duplicate unit test<commit_after>package docker

import (
	"io/ioutil"
	"testing"
)

// mkTestContext generates a build context from the contents of the provided dockerfile.
// This context is suitable for use as an argument to BuildFile.Build()
func mkTestContext(dockerfile string, files [][2]string, t *testing.T) Archive {
	context, err := mkBuildContext(dockerfile, files)
	if err != nil {
		t.Fatal(err)
	}
	return context
}

// A testContextTemplate describes a build context and how to test it
type testContextTemplate struct {
	// Contents of the Dockerfile
	dockerfile string
	// Additional files in the context, eg [][2]string{"./passwd", "gordon"}
	files [][2]string
	// Test commands to run in the resulting image
	tests []testCommand
}

// A testCommand describes a command to run in a container, and the exact output required to pass the test
type testCommand struct {
	// The command to run, eg. []string{"echo", "hello", "world"}
	cmd []string
	// The exact output expected, eg. "hello world\n"
	output string
}

// A table of all the contexts to build and test.
// A new docker runtime will be created and torn down for each context.
var testContexts []testContextTemplate = []testContextTemplate{
	{
		`
# VERSION		0.1
# DOCKER-VERSION	0.2

from   docker-ut
run    sh -c 'echo root:testpass > /tmp/passwd'
run    mkdir -p /var/run/sshd
`,
		nil,
		[]testCommand{
			{[]string{"cat", "/tmp/passwd"}, "root:testpass\n"},
			{[]string{"ls", "-d", "/var/run/sshd"}, "/var/run/sshd\n"},
		},
	},
{'fraction_non_alphanumeric': 0.1365824308062575, 'fraction_numerical': 0.005415162454873646, 'mean_word_length': 3.6373779637377965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '5727921', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1092, 'n_words': 388}