mirror of https://github.com/docker/compose.git
Merge pull request #138 from chris-crone/refactor-e2e-suite
Refactor e2e suite code
This commit is contained in:
commit
3c3b84f542
|
@ -3,18 +3,16 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/resources/mgmt/resources"
|
"github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/resources/mgmt/resources"
|
||||||
"github.com/Azure/go-autorest/autorest/to"
|
|
||||||
|
|
||||||
azure_storage "github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/storage/mgmt/storage"
|
azure_storage "github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/storage/mgmt/storage"
|
||||||
"github.com/Azure/azure-storage-file-go/azfile"
|
"github.com/Azure/azure-storage-file-go/azfile"
|
||||||
|
"github.com/Azure/go-autorest/autorest/to"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/docker/api/azure"
|
"github.com/docker/api/azure"
|
||||||
|
|
|
@ -1,3 +1,30 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2020 Docker Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without
|
||||||
|
restriction, including without limitation the rights to use, copy,
|
||||||
|
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
|
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -1,21 +1,42 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2020 Docker Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without
|
||||||
|
restriction, including without limitation the rights to use, copy,
|
||||||
|
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
|
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
package framework
|
package framework
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/onsi/gomega"
|
"github.com/onsi/gomega"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/stretchr/testify/suite"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (b CmdContext) makeCmd() *exec.Cmd {
|
func (b CmdContext) makeCmd() *exec.Cmd {
|
||||||
|
@ -40,81 +61,6 @@ type RetriesContext struct {
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suite is used to store context information for e2e tests
|
|
||||||
type Suite struct {
|
|
||||||
suite.Suite
|
|
||||||
ConfigDir string
|
|
||||||
BinDir string
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetupSuite is run before running any tests
|
|
||||||
func (s *Suite) SetupSuite() {
|
|
||||||
d, _ := ioutil.TempDir("", "")
|
|
||||||
s.BinDir = d
|
|
||||||
gomega.RegisterFailHandler(func(message string, callerSkip ...int) {
|
|
||||||
log.Error(message)
|
|
||||||
cp := filepath.Join(s.ConfigDir, "config.json")
|
|
||||||
d, _ := ioutil.ReadFile(cp)
|
|
||||||
fmt.Printf("Contents of %s:\n%s\n\nContents of config dir:\n", cp, string(d))
|
|
||||||
out, _ := s.NewCommand("find", s.ConfigDir).Exec()
|
|
||||||
fmt.Println(out)
|
|
||||||
s.T().Fail()
|
|
||||||
})
|
|
||||||
s.linkClassicDocker()
|
|
||||||
}
|
|
||||||
|
|
||||||
// TearDownSuite is run after all tests
|
|
||||||
func (s *Suite) TearDownSuite() {
|
|
||||||
_ = os.RemoveAll(s.BinDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Suite) linkClassicDocker() {
|
|
||||||
p, err := exec.LookPath("docker")
|
|
||||||
gomega.Expect(err).To(gomega.BeNil())
|
|
||||||
err = os.Symlink(p, filepath.Join(s.BinDir, "docker-classic"))
|
|
||||||
gomega.Expect(err).To(gomega.BeNil())
|
|
||||||
err = os.Setenv("PATH", fmt.Sprintf("%s:%s", s.BinDir, os.Getenv("PATH")))
|
|
||||||
gomega.Expect(err).To(gomega.BeNil())
|
|
||||||
}
|
|
||||||
|
|
||||||
// BeforeTest is run before each test
|
|
||||||
func (s *Suite) BeforeTest(suite, test string) {
|
|
||||||
d, _ := ioutil.TempDir("", "")
|
|
||||||
s.ConfigDir = d
|
|
||||||
}
|
|
||||||
|
|
||||||
// AfterTest is run after each test
|
|
||||||
func (s *Suite) AfterTest(suite, test string) {
|
|
||||||
err := os.RemoveAll(s.ConfigDir)
|
|
||||||
require.NoError(s.T(), err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewCommand creates a command context.
|
|
||||||
func (s *Suite) NewCommand(command string, args ...string) *CmdContext {
|
|
||||||
var envs []string
|
|
||||||
if s.ConfigDir != "" {
|
|
||||||
envs = append(os.Environ(), fmt.Sprintf("DOCKER_CONFIG=%s", s.ConfigDir))
|
|
||||||
}
|
|
||||||
return &CmdContext{
|
|
||||||
command: command,
|
|
||||||
args: args,
|
|
||||||
envs: envs,
|
|
||||||
retries: RetriesContext{interval: time.Second},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func dockerExecutable() string {
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
return "../../bin/docker.exe"
|
|
||||||
}
|
|
||||||
return "../../bin/docker"
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDockerCommand creates a docker builder.
|
|
||||||
func (s *Suite) NewDockerCommand(args ...string) *CmdContext {
|
|
||||||
return s.NewCommand(dockerExecutable(), args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithinDirectory tells Docker the cwd.
|
// WithinDirectory tells Docker the cwd.
|
||||||
func (b *CmdContext) WithinDirectory(path string) *CmdContext {
|
func (b *CmdContext) WithinDirectory(path string) *CmdContext {
|
||||||
b.dir = path
|
b.dir = path
|
||||||
|
|
|
@ -1,22 +1,49 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2020 Docker Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without
|
||||||
|
restriction, including without limitation the rights to use, copy,
|
||||||
|
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
|
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
package framework
|
package framework
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/robpike/filter"
|
"github.com/robpike/filter"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func nonEmptyString(s string) bool {
|
func nonEmptyString(s string) bool {
|
||||||
return strings.TrimSpace(s) != ""
|
return strings.TrimSpace(s) != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
//Lines get lines from a raw string
|
// Lines get lines from a raw string
|
||||||
func Lines(output string) []string {
|
func Lines(output string) []string {
|
||||||
return filter.Choose(strings.Split(output, "\n"), nonEmptyString).([]string)
|
return filter.Choose(strings.Split(output, "\n"), nonEmptyString).([]string)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Columns get columns from a line
|
// Columns get columns from a line
|
||||||
func Columns(line string) []string {
|
func Columns(line string) []string {
|
||||||
return filter.Choose(strings.Split(line, " "), nonEmptyString).([]string)
|
return filter.Choose(strings.Split(line, " "), nonEmptyString).([]string)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,118 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2020 Docker Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without
|
||||||
|
restriction, including without limitation the rights to use, copy,
|
||||||
|
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
|
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package framework
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/onsi/gomega"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Suite is used to store context information for e2e tests
|
||||||
|
type Suite struct {
|
||||||
|
suite.Suite
|
||||||
|
ConfigDir string
|
||||||
|
BinDir string
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupSuite is run before running any tests
|
||||||
|
func (s *Suite) SetupSuite() {
|
||||||
|
d, _ := ioutil.TempDir("", "")
|
||||||
|
s.BinDir = d
|
||||||
|
gomega.RegisterFailHandler(func(message string, callerSkip ...int) {
|
||||||
|
log.Error(message)
|
||||||
|
cp := filepath.Join(s.ConfigDir, "config.json")
|
||||||
|
d, _ := ioutil.ReadFile(cp)
|
||||||
|
fmt.Printf("Contents of %s:\n%s\n\nContents of config dir:\n", cp, string(d))
|
||||||
|
out, _ := s.NewCommand("find", s.ConfigDir).Exec()
|
||||||
|
fmt.Println(out)
|
||||||
|
s.T().Fail()
|
||||||
|
})
|
||||||
|
s.linkClassicDocker()
|
||||||
|
}
|
||||||
|
|
||||||
|
// TearDownSuite is run after all tests
|
||||||
|
func (s *Suite) TearDownSuite() {
|
||||||
|
_ = os.RemoveAll(s.BinDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Suite) linkClassicDocker() {
|
||||||
|
p, err := exec.LookPath("docker")
|
||||||
|
gomega.Expect(err).To(gomega.BeNil())
|
||||||
|
err = os.Symlink(p, filepath.Join(s.BinDir, "docker-classic"))
|
||||||
|
gomega.Expect(err).To(gomega.BeNil())
|
||||||
|
err = os.Setenv("PATH", fmt.Sprintf("%s:%s", s.BinDir, os.Getenv("PATH")))
|
||||||
|
gomega.Expect(err).To(gomega.BeNil())
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeforeTest is run before each test
|
||||||
|
func (s *Suite) BeforeTest(suite, test string) {
|
||||||
|
d, _ := ioutil.TempDir("", "")
|
||||||
|
s.ConfigDir = d
|
||||||
|
}
|
||||||
|
|
||||||
|
// AfterTest is run after each test
|
||||||
|
func (s *Suite) AfterTest(suite, test string) {
|
||||||
|
err := os.RemoveAll(s.ConfigDir)
|
||||||
|
require.NoError(s.T(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCommand creates a command context.
|
||||||
|
func (s *Suite) NewCommand(command string, args ...string) *CmdContext {
|
||||||
|
var envs []string
|
||||||
|
if s.ConfigDir != "" {
|
||||||
|
envs = append(os.Environ(), fmt.Sprintf("DOCKER_CONFIG=%s", s.ConfigDir))
|
||||||
|
}
|
||||||
|
return &CmdContext{
|
||||||
|
command: command,
|
||||||
|
args: args,
|
||||||
|
envs: envs,
|
||||||
|
retries: RetriesContext{interval: time.Second},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func dockerExecutable() string {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return "../../bin/docker.exe"
|
||||||
|
}
|
||||||
|
return "../../bin/docker"
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDockerCommand creates a docker builder.
|
||||||
|
func (s *Suite) NewDockerCommand(args ...string) *CmdContext {
|
||||||
|
return s.NewCommand(dockerExecutable(), args...)
|
||||||
|
}
|
Loading…
Reference in New Issue