зеркало из https://github.com/microsoft/docker.git
Merge pull request #8409 from unclejack/integcli_lint
integcli: lint fixes
This commit is contained in:
Коммит
a650ab7f29
|
@ -25,11 +25,11 @@ func TestInspectApiContainerResponse(t *testing.T) {
|
|||
}
|
||||
body, err := sockRequest("GET", endpoint)
|
||||
if err != nil {
|
||||
t.Fatal("sockRequest failed for %s version: %v", testVersion, err)
|
||||
t.Fatalf("sockRequest failed for %s version: %v", testVersion, err)
|
||||
}
|
||||
|
||||
var inspect_json map[string]interface{}
|
||||
if err = json.Unmarshal(body, &inspect_json); err != nil {
|
||||
var inspectJSON map[string]interface{}
|
||||
if err = json.Unmarshal(body, &inspectJSON); err != nil {
|
||||
t.Fatalf("unable to unmarshal body for %s version: %v", testVersion, err)
|
||||
}
|
||||
|
||||
|
@ -42,12 +42,12 @@ func TestInspectApiContainerResponse(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, key := range keys {
|
||||
if _, ok := inspect_json[key]; !ok {
|
||||
if _, ok := inspectJSON[key]; !ok {
|
||||
t.Fatalf("%s does not exist in reponse for %s version", key, testVersion)
|
||||
}
|
||||
}
|
||||
//Issue #6830: type not properly converted to JSON/back
|
||||
if _, ok := inspect_json["Path"].(bool); ok {
|
||||
if _, ok := inspectJSON["Path"].(bool); ok {
|
||||
t.Fatalf("Path of `true` should not be converted to boolean `true` via JSON marshalling")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -265,7 +265,7 @@ func TestBuildCopyWildcard(t *testing.T) {
|
|||
}
|
||||
|
||||
if id1 != id2 {
|
||||
t.Fatal(fmt.Errorf("Didn't use the cache"))
|
||||
t.Fatal("didn't use the cache")
|
||||
}
|
||||
|
||||
logDone("build - copy wild card")
|
||||
|
@ -284,7 +284,7 @@ func TestBuildCopyWildcardNoFind(t *testing.T) {
|
|||
|
||||
_, err = buildImageFromContext(name, ctx, true)
|
||||
if err == nil {
|
||||
t.Fatal(fmt.Errorf("Should have failed to find a file"))
|
||||
t.Fatal("should have failed to find a file")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "No source files were specified") {
|
||||
t.Fatalf("Wrong error %v, must be about no source files", err)
|
||||
|
@ -322,7 +322,7 @@ func TestBuildCopyWildcardCache(t *testing.T) {
|
|||
}
|
||||
|
||||
if id1 != id2 {
|
||||
t.Fatal(fmt.Errorf("Didn't use the cache"))
|
||||
t.Fatal("didn't use the cache")
|
||||
}
|
||||
|
||||
logDone("build - copy wild card cache")
|
||||
|
@ -568,11 +568,11 @@ func TestBuildCopyWholeDirToRoot(t *testing.T) {
|
|||
}
|
||||
|
||||
buildDirectory = filepath.Join(buildDirectory, testDirName)
|
||||
test_dir := filepath.Join(buildDirectory, "test_dir")
|
||||
if err := os.MkdirAll(test_dir, 0755); err != nil {
|
||||
testDir := filepath.Join(buildDirectory, "test_dir")
|
||||
if err := os.MkdirAll(testDir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f, err := os.OpenFile(filepath.Join(test_dir, "test_file"), os.O_CREATE, 0644)
|
||||
f, err := os.OpenFile(filepath.Join(testDir, "test_file"), os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -68,13 +68,13 @@ func TestCommitNewFile(t *testing.T) {
|
|||
}
|
||||
|
||||
cmd = exec.Command(dockerBinary, "commit", "commiter")
|
||||
imageId, _, err := runCommandWithOutput(cmd)
|
||||
imageID, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
imageId = strings.Trim(imageId, "\r\n")
|
||||
imageID = strings.Trim(imageID, "\r\n")
|
||||
|
||||
cmd = exec.Command(dockerBinary, "run", imageId, "cat", "/foo")
|
||||
cmd = exec.Command(dockerBinary, "run", imageID, "cat", "/foo")
|
||||
|
||||
out, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
|
@ -85,7 +85,7 @@ func TestCommitNewFile(t *testing.T) {
|
|||
}
|
||||
|
||||
deleteAllContainers()
|
||||
deleteImages(imageId)
|
||||
deleteImages(imageID)
|
||||
|
||||
logDone("commit - commit file and read")
|
||||
}
|
||||
|
@ -98,11 +98,11 @@ func TestCommitTTY(t *testing.T) {
|
|||
}
|
||||
|
||||
cmd = exec.Command(dockerBinary, "commit", "tty", "ttytest")
|
||||
imageId, _, err := runCommandWithOutput(cmd)
|
||||
imageID, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
imageId = strings.Trim(imageId, "\r\n")
|
||||
imageID = strings.Trim(imageID, "\r\n")
|
||||
|
||||
cmd = exec.Command(dockerBinary, "run", "ttytest", "/bin/ls")
|
||||
|
||||
|
@ -120,11 +120,11 @@ func TestCommitWithHostBindMount(t *testing.T) {
|
|||
}
|
||||
|
||||
cmd = exec.Command(dockerBinary, "commit", "bind-commit", "bindtest")
|
||||
imageId, _, err := runCommandWithOutput(cmd)
|
||||
imageID, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(imageId, err)
|
||||
t.Fatal(imageID, err)
|
||||
}
|
||||
imageId = strings.Trim(imageId, "\r\n")
|
||||
imageID = strings.Trim(imageID, "\r\n")
|
||||
|
||||
cmd = exec.Command(dockerBinary, "run", "bindtest", "true")
|
||||
|
||||
|
@ -133,7 +133,7 @@ func TestCommitWithHostBindMount(t *testing.T) {
|
|||
}
|
||||
|
||||
deleteAllContainers()
|
||||
deleteImages(imageId)
|
||||
deleteImages(imageID)
|
||||
|
||||
logDone("commit - commit bind mounted file")
|
||||
}
|
||||
|
|
|
@ -25,11 +25,11 @@ func TestEventsUntag(t *testing.T) {
|
|||
eventsCmd := exec.Command("timeout", "0.2", dockerBinary, "events", "--since=1")
|
||||
out, _, _ = runCommandWithOutput(eventsCmd)
|
||||
events := strings.Split(out, "\n")
|
||||
n_events := len(events)
|
||||
nEvents := len(events)
|
||||
// The last element after the split above will be an empty string, so we
|
||||
// get the two elements before the last, which are the untags we're
|
||||
// looking for.
|
||||
for _, v := range events[n_events-3 : n_events-1] {
|
||||
for _, v := range events[nEvents-3 : nEvents-1] {
|
||||
if !strings.Contains(v, "untag") {
|
||||
t.Fatalf("event should be untag, not %#v", v)
|
||||
}
|
||||
|
@ -99,9 +99,9 @@ func TestEventsLimit(t *testing.T) {
|
|||
eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", time.Now().Unix()))
|
||||
out, _, _ := runCommandWithOutput(eventsCmd)
|
||||
events := strings.Split(out, "\n")
|
||||
n_events := len(events) - 1
|
||||
if n_events != 64 {
|
||||
t.Fatalf("events should be limited to 64, but received %d", n_events)
|
||||
nEvents := len(events) - 1
|
||||
if nEvents != 64 {
|
||||
t.Fatalf("events should be limited to 64, but received %d", nEvents)
|
||||
}
|
||||
logDone("events - limited to 64 entries")
|
||||
}
|
||||
|
|
|
@ -51,15 +51,15 @@ RUN echo "Z"`,
|
|||
t.Fatal("failed to get image history")
|
||||
}
|
||||
|
||||
actual_values := strings.Split(out, "\n")[1:27]
|
||||
expected_values := [26]string{"Z", "Y", "X", "W", "V", "U", "T", "S", "R", "Q", "P", "O", "N", "M", "L", "K", "J", "I", "H", "G", "F", "E", "D", "C", "B", "A"}
|
||||
actualValues := strings.Split(out, "\n")[1:27]
|
||||
expectedValues := [26]string{"Z", "Y", "X", "W", "V", "U", "T", "S", "R", "Q", "P", "O", "N", "M", "L", "K", "J", "I", "H", "G", "F", "E", "D", "C", "B", "A"}
|
||||
|
||||
for i := 0; i < 26; i++ {
|
||||
echo_value := fmt.Sprintf("echo \"%s\"", expected_values[i])
|
||||
actual_value := actual_values[i]
|
||||
echoValue := fmt.Sprintf("echo \"%s\"", expectedValues[i])
|
||||
actualValue := actualValues[i]
|
||||
|
||||
if !strings.Contains(actual_value, echo_value) {
|
||||
t.Fatalf("Expected layer \"%s\", but was: %s", expected_values[i], actual_value)
|
||||
if !strings.Contains(actualValue, echoValue) {
|
||||
t.Fatalf("Expected layer \"%s\", but was: %s", expectedValues[i], actualValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ func TestImportDisplay(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
defer server.Close()
|
||||
fileUrl := fmt.Sprintf("%s/cirros.tar.gz", server.URL)
|
||||
importCmd := exec.Command(dockerBinary, "import", fileUrl)
|
||||
fileURL := fmt.Sprintf("%s/cirros.tar.gz", server.URL)
|
||||
importCmd := exec.Command(dockerBinary, "import", fileURL)
|
||||
out, _, err := runCommandWithOutput(importCmd)
|
||||
if err != nil {
|
||||
t.Errorf("import failed with errors: %v, output: %q", err, out)
|
||||
|
|
|
@ -8,15 +8,15 @@ import (
|
|||
|
||||
func TestInspectImage(t *testing.T) {
|
||||
imageTest := "scratch"
|
||||
imageTestId := "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158"
|
||||
imageTestID := "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158"
|
||||
imagesCmd := exec.Command(dockerBinary, "inspect", "--format='{{.Id}}'", imageTest)
|
||||
|
||||
out, exitCode, err := runCommandWithOutput(imagesCmd)
|
||||
if exitCode != 0 || err != nil {
|
||||
t.Fatalf("failed to inspect image")
|
||||
}
|
||||
if id := strings.TrimSuffix(out, "\n"); id != imageTestId {
|
||||
t.Fatalf("Expected id: %s for image: %s but received id: %s", imageTestId, imageTest, id)
|
||||
if id := strings.TrimSuffix(out, "\n"); id != imageTestID {
|
||||
t.Fatalf("Expected id: %s for image: %s but received id: %s", imageTestID, imageTest, id)
|
||||
}
|
||||
logDone("inspect - inspect an image")
|
||||
}
|
||||
|
|
|
@ -75,11 +75,11 @@ func TestLinksIpTablesRulesWhenLinkAndUnlink(t *testing.T) {
|
|||
cmd(t, "run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "sleep", "10")
|
||||
cmd(t, "run", "-d", "--name", "parent", "--link", "child:http", "busybox", "sleep", "10")
|
||||
|
||||
childIp := findContainerIp(t, "child")
|
||||
parentIp := findContainerIp(t, "parent")
|
||||
childIP := findContainerIP(t, "child")
|
||||
parentIP := findContainerIP(t, "parent")
|
||||
|
||||
sourceRule := []string{"FORWARD", "-i", "docker0", "-o", "docker0", "-p", "tcp", "-s", childIp, "--sport", "80", "-d", parentIp, "-j", "ACCEPT"}
|
||||
destinationRule := []string{"FORWARD", "-i", "docker0", "-o", "docker0", "-p", "tcp", "-s", parentIp, "--dport", "80", "-d", childIp, "-j", "ACCEPT"}
|
||||
sourceRule := []string{"FORWARD", "-i", "docker0", "-o", "docker0", "-p", "tcp", "-s", childIP, "--sport", "80", "-d", parentIP, "-j", "ACCEPT"}
|
||||
destinationRule := []string{"FORWARD", "-i", "docker0", "-o", "docker0", "-p", "tcp", "-s", parentIP, "--dport", "80", "-d", childIP, "-j", "ACCEPT"}
|
||||
if !iptables.Exists(sourceRule...) || !iptables.Exists(destinationRule...) {
|
||||
t.Fatal("Iptables rules not found")
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ func TestNetworkNat(t *testing.T) {
|
|||
t.Fatalf("Error retrieving addresses for eth0: %v (%d addresses)", err, len(ifaceAddrs))
|
||||
}
|
||||
|
||||
ifaceIp, _, err := net.ParseCIDR(ifaceAddrs[0].String())
|
||||
ifaceIP, _, err := net.ParseCIDR(ifaceAddrs[0].String())
|
||||
if err != nil {
|
||||
t.Fatalf("Error retrieving the up for eth0: %s", err)
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ func TestNetworkNat(t *testing.T) {
|
|||
|
||||
cleanedContainerID := stripTrailingCharacters(out)
|
||||
|
||||
runCmd = exec.Command(dockerBinary, "run", "busybox", "sh", "-c", fmt.Sprintf("echo hello world | nc -w 30 %s 8080", ifaceIp))
|
||||
runCmd = exec.Command(dockerBinary, "run", "busybox", "sh", "-c", fmt.Sprintf("echo hello world | nc -w 30 %s 8080", ifaceIP))
|
||||
out, _, err = runCommandWithOutput(runCmd)
|
||||
errorOut(err, t, fmt.Sprintf("run2 failed with errors: %v (%s)", err, out))
|
||||
|
||||
|
@ -40,7 +40,7 @@ func TestNetworkNat(t *testing.T) {
|
|||
out = strings.Trim(out, "\r\n")
|
||||
|
||||
if expected := "hello world"; out != expected {
|
||||
t.Fatalf("Unexpected output. Expected: %q, received: %q for iface %s", expected, out, ifaceIp)
|
||||
t.Fatalf("Unexpected output. Expected: %q, received: %q for iface %s", expected, out, ifaceIP)
|
||||
}
|
||||
|
||||
killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
|
||||
|
|
|
@ -190,9 +190,9 @@ func assertContainerList(out string, expected []string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
containerIdIndex := strings.Index(lines[0], "CONTAINER ID")
|
||||
containerIDIndex := strings.Index(lines[0], "CONTAINER ID")
|
||||
for i := 0; i < len(expected); i++ {
|
||||
foundID := lines[i+1][containerIdIndex : containerIdIndex+12]
|
||||
foundID := lines[i+1][containerIDIndex : containerIDIndex+12]
|
||||
if foundID != expected[i][:12] {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -2038,7 +2038,7 @@ func TestRunNetworkNotInitializedNoneMode(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
if res != "" {
|
||||
t.Fatal("For 'none' mode network must not be initialized, but container got IP: %s", res)
|
||||
t.Fatalf("For 'none' mode network must not be initialized, but container got IP: %s", res)
|
||||
}
|
||||
deleteAllContainers()
|
||||
logDone("run - network must not be initialized in 'none' mode")
|
||||
|
|
|
@ -44,11 +44,11 @@ func NewDaemon(t *testing.T) *Daemon {
|
|||
dir := filepath.Join(dest, fmt.Sprintf("daemon%d", time.Now().Unix()))
|
||||
daemonFolder, err := filepath.Abs(dir)
|
||||
if err != nil {
|
||||
t.Fatal("Could not make '%s' an absolute path: %v", dir, err)
|
||||
t.Fatalf("Could not make '%s' an absolute path: %v", dir, err)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Join(daemonFolder, "graph"), 0600); err != nil {
|
||||
t.Fatal("Could not create %s/graph directory", daemonFolder)
|
||||
t.Fatalf("Could not create %s/graph directory", daemonFolder)
|
||||
}
|
||||
|
||||
return &Daemon{
|
||||
|
@ -92,7 +92,7 @@ func (d *Daemon) Start(arg ...string) error {
|
|||
d.cmd.Stderr = d.logFile
|
||||
|
||||
if err := d.cmd.Start(); err != nil {
|
||||
return fmt.Errorf("Could not start daemon container: %v", err)
|
||||
return fmt.Errorf("could not start daemon container: %v", err)
|
||||
}
|
||||
|
||||
wait := make(chan error)
|
||||
|
@ -172,7 +172,7 @@ func (d *Daemon) StartWithBusybox(arg ...string) error {
|
|||
// instantiate a new one with NewDaemon.
|
||||
func (d *Daemon) Stop() error {
|
||||
if d.cmd == nil || d.wait == nil {
|
||||
return errors.New("Daemon not started")
|
||||
return errors.New("daemon not started")
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
@ -184,7 +184,7 @@ func (d *Daemon) Stop() error {
|
|||
tick := time.Tick(time.Second)
|
||||
|
||||
if err := d.cmd.Process.Signal(os.Interrupt); err != nil {
|
||||
return fmt.Errorf("Could not send signal: %v", err)
|
||||
return fmt.Errorf("could not send signal: %v", err)
|
||||
}
|
||||
out:
|
||||
for {
|
||||
|
@ -197,7 +197,7 @@ out:
|
|||
case <-tick:
|
||||
d.t.Logf("Attempt #%d: daemon is still running with pid %d", i+1, d.cmd.Process.Pid)
|
||||
if err := d.cmd.Process.Signal(os.Interrupt); err != nil {
|
||||
return fmt.Errorf("Could not send signal: %v", err)
|
||||
return fmt.Errorf("could not send signal: %v", err)
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ func dockerCmdInDirWithTimeout(timeout time.Duration, path string, args ...strin
|
|||
return out, status, err
|
||||
}
|
||||
|
||||
func findContainerIp(t *testing.T, id string) string {
|
||||
func findContainerIP(t *testing.T, id string) string {
|
||||
cmd := exec.Command(dockerBinary, "inspect", "--format='{{ .NetworkSettings.IPAddress }}'", id)
|
||||
out, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
|
@ -625,17 +625,17 @@ func fakeGIT(name string, files map[string]string) (*FakeGIT, error) {
|
|||
defer os.Chdir(curdir)
|
||||
|
||||
if output, err := exec.Command("git", "init", ctx.Dir).CombinedOutput(); err != nil {
|
||||
return nil, fmt.Errorf("Error trying to init repo: %s (%s)", err, output)
|
||||
return nil, fmt.Errorf("error trying to init repo: %s (%s)", err, output)
|
||||
}
|
||||
err = os.Chdir(ctx.Dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if output, err := exec.Command("git", "add", "*").CombinedOutput(); err != nil {
|
||||
return nil, fmt.Errorf("Error trying to add files to repo: %s (%s)", err, output)
|
||||
return nil, fmt.Errorf("error trying to add files to repo: %s (%s)", err, output)
|
||||
}
|
||||
if output, err := exec.Command("git", "commit", "-a", "-m", "Initial commit").CombinedOutput(); err != nil {
|
||||
return nil, fmt.Errorf("Error trying to commit to repo: %s (%s)", err, output)
|
||||
return nil, fmt.Errorf("error trying to commit to repo: %s (%s)", err, output)
|
||||
}
|
||||
|
||||
root, err := ioutil.TempDir("", "docker-test-git-repo")
|
||||
|
@ -645,7 +645,7 @@ func fakeGIT(name string, files map[string]string) (*FakeGIT, error) {
|
|||
repoPath := filepath.Join(root, name+".git")
|
||||
if output, err := exec.Command("git", "clone", "--bare", ctx.Dir, repoPath).CombinedOutput(); err != nil {
|
||||
os.RemoveAll(root)
|
||||
return nil, fmt.Errorf("Error trying to clone --bare: %s (%s)", err, output)
|
||||
return nil, fmt.Errorf("error trying to clone --bare: %s (%s)", err, output)
|
||||
}
|
||||
err = os.Chdir(repoPath)
|
||||
if err != nil {
|
||||
|
@ -654,7 +654,7 @@ func fakeGIT(name string, files map[string]string) (*FakeGIT, error) {
|
|||
}
|
||||
if output, err := exec.Command("git", "update-server-info").CombinedOutput(); err != nil {
|
||||
os.RemoveAll(root)
|
||||
return nil, fmt.Errorf("Error trying to git update-server-info: %s (%s)", err, output)
|
||||
return nil, fmt.Errorf("error trying to git update-server-info: %s (%s)", err, output)
|
||||
}
|
||||
err = os.Chdir(curdir)
|
||||
if err != nil {
|
||||
|
|
|
@ -149,25 +149,25 @@ func convertSliceOfStringsToMap(input []string) map[string]struct{} {
|
|||
return output
|
||||
}
|
||||
|
||||
func waitForContainer(contId string, args ...string) error {
|
||||
args = append([]string{"run", "--name", contId}, args...)
|
||||
func waitForContainer(contID string, args ...string) error {
|
||||
args = append([]string{"run", "--name", contID}, args...)
|
||||
cmd := exec.Command(dockerBinary, args...)
|
||||
if _, err := runCommand(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := waitRun(contId); err != nil {
|
||||
if err := waitRun(contID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func waitRun(contId string) error {
|
||||
func waitRun(contID string) error {
|
||||
after := time.After(5 * time.Second)
|
||||
|
||||
for {
|
||||
cmd := exec.Command(dockerBinary, "inspect", "-f", "{{.State.Running}}", contId)
|
||||
cmd := exec.Command(dockerBinary, "inspect", "-f", "{{.State.Running}}", contID)
|
||||
out, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error executing docker inspect: %v", err)
|
||||
|
|
Загрузка…
Ссылка в новой задаче