mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-02 12:17:39 -06:00
6fe2703665
* Remove `make updatedeps` from Travis build. We'll follow up with more specific plans around dependency updating in subsequent PRs. * Update all `make` targets to set `GO15VENDOREXPERIMENT=1` and to filter out `/vendor/` from `./...` where appropriate. * Temporarily remove `vet` from the `make test` target until we can figure out how to get it to not vet `vendor/`. (Initial experimentation failed to yield the proper incantation.) Everything is pinned to current master, with the exception of: * Azure/azure-sdk-for-go which is pinned before the breaking change today * aws/aws-sdk-go which is pinned to the most recent tag The documentation still needs to be updated, which we can do in a follow up PR. The goal here is to unblock release.
95 lines
2.2 KiB
Go
95 lines
2.2 KiB
Go
// Copyright 2015 go-dockerclient authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build docker_integration
|
|
|
|
package docker
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
var dockerEndpoint string
|
|
|
|
func init() {
|
|
dockerEndpoint = os.Getenv("DOCKER_HOST")
|
|
if dockerEndpoint == "" {
|
|
dockerEndpoint = "unix:///var/run/docker.sock"
|
|
}
|
|
}
|
|
|
|
func TestIntegrationPullCreateStartLogs(t *testing.T) {
|
|
imageName := pullImage(t)
|
|
client := getClient()
|
|
hostConfig := HostConfig{PublishAllPorts: true}
|
|
createOpts := CreateContainerOptions{
|
|
Config: &Config{
|
|
Image: imageName,
|
|
Cmd: []string{"cat", "/home/gopher/file.txt"},
|
|
User: "gopher",
|
|
},
|
|
HostConfig: &hostConfig,
|
|
}
|
|
container, err := client.CreateContainer(createOpts)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = client.StartContainer(container.ID, &hostConfig)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
status, err := client.WaitContainer(container.ID)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if status != 0 {
|
|
t.Error("WaitContainer(%q): wrong status. Want 0. Got %d", container.ID, status)
|
|
}
|
|
var stdout, stderr bytes.Buffer
|
|
logsOpts := LogsOptions{
|
|
Container: container.ID,
|
|
OutputStream: &stdout,
|
|
ErrorStream: &stderr,
|
|
Stdout: true,
|
|
Stderr: true,
|
|
}
|
|
err = client.Logs(logsOpts)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if stderr.String() != "" {
|
|
t.Errorf("Got unexpected stderr from logs: %q", stderr.String())
|
|
}
|
|
expected := `Welcome to reality, wake up and rejoice
|
|
Welcome to reality, you've made the right choice
|
|
Welcome to reality, and let them hear your voice, shout it out!
|
|
`
|
|
if stdout.String() != expected {
|
|
t.Errorf("Got wrong stdout from logs.\nWant:\n%#v.\n\nGot:\n%#v.", expected, stdout.String())
|
|
}
|
|
}
|
|
|
|
func pullImage(t *testing.T) string {
|
|
imageName := "fsouza/go-dockerclient-integration"
|
|
var buf bytes.Buffer
|
|
pullOpts := PullImageOptions{
|
|
Repository: imageName,
|
|
OutputStream: &buf,
|
|
}
|
|
client := getClient()
|
|
err := client.PullImage(pullOpts, AuthConfiguration{})
|
|
if err != nil {
|
|
t.Logf("Pull output: %s", buf.String())
|
|
t.Fatal(err)
|
|
}
|
|
return imageName
|
|
}
|
|
|
|
func getClient() *Client {
|
|
client, _ := NewClient(dockerEndpoint)
|
|
return client
|
|
}
|