Move internal/test package out of cli.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin
2017-08-21 16:30:09 -04:00
parent 8da1daeefa
commit b3f843afe2
75 changed files with 97 additions and 82 deletions

View File

@ -5,7 +5,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"

View File

@ -4,7 +4,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"

View File

@ -4,7 +4,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"

View File

@ -7,7 +7,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/testutil"

View File

@ -6,11 +6,11 @@ import (
"testing"
"time"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"

View File

@ -6,12 +6,12 @@ import (
"time"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"

View File

@ -5,7 +5,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"

View File

@ -4,7 +4,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"

View File

@ -4,7 +4,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"

View File

@ -5,7 +5,7 @@ import (
"github.com/docker/docker/api/types/swarm"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"

View File

@ -10,7 +10,7 @@ import (
"testing"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/archive"
"github.com/stretchr/testify/assert"

View File

@ -6,7 +6,7 @@ import (
"testing"
"time"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"

View File

@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"

View File

@ -5,7 +5,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"

View File

@ -6,7 +6,7 @@ import (
"testing"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"

View File

@ -7,7 +7,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"

View File

@ -5,7 +5,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/pkg/testutil"

View File

@ -5,7 +5,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"

View File

@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"

View File

@ -5,7 +5,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"

View File

@ -7,7 +7,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"

View File

@ -4,7 +4,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/pkg/testutil"
"github.com/stretchr/testify/assert"
)

View File

@ -4,7 +4,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"

View File

@ -5,7 +5,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/pkg/testutil"

View File

@ -4,7 +4,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"
"golang.org/x/net/context"

View File

@ -4,11 +4,11 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil"
"github.com/stretchr/testify/assert"
)

View File

@ -5,12 +5,12 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"

View File

@ -5,13 +5,13 @@ import (
"testing"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/stretchr/testify/assert"
)

View File

@ -4,11 +4,11 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil"
"github.com/stretchr/testify/assert"
)

View File

@ -6,12 +6,12 @@ import (
"testing"
"time"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
)

View File

@ -4,7 +4,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"

View File

@ -4,11 +4,11 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil"
"github.com/stretchr/testify/assert"
)

View File

@ -7,9 +7,9 @@ import (
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
// Prevents a circular import with "github.com/docker/cli/cli/internal/test"
// Prevents a circular import with "github.com/docker/cli/internal/test"
. "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
)

View File

@ -7,7 +7,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/testutil"

View File

@ -6,11 +6,11 @@ import (
"testing"
"time"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"

View File

@ -7,12 +7,12 @@ import (
"time"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"

View File

@ -5,7 +5,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"

View File

@ -6,7 +6,7 @@ import (
"github.com/docker/docker/client"
"golang.org/x/net/context"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
)
type fakeClient struct {

View File

@ -3,7 +3,7 @@ package service
import (
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/golden"

View File

@ -3,7 +3,7 @@ package service
import (
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"

View File

@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/testutil"

View File

@ -5,7 +5,7 @@ import (
"path/filepath"
"testing"
"github.com/docker/cli/cli/internal/test/network"
"github.com/docker/cli/internal/test/network"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/fs"

View File

@ -4,7 +4,7 @@ import (
"testing"
"github.com/docker/cli/cli/compose/convert"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/stretchr/testify/assert"

View File

@ -4,9 +4,9 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/testutil"

View File

@ -6,9 +6,9 @@ import (
"time"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/testutil"

View File

@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/stretchr/testify/assert"
)

View File

@ -5,9 +5,9 @@ import (
"testing"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/testutil"

View File

@ -7,7 +7,7 @@ import (
"testing"
"time"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/testutil"
"github.com/stretchr/testify/assert"

View File

@ -5,7 +5,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/golden"

View File

@ -5,7 +5,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/testutil"

View File

@ -5,12 +5,12 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"

View File

@ -5,7 +5,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"

View File

@ -5,12 +5,12 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"

View File

@ -6,7 +6,7 @@ import (
"testing"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/testutil"

View File

@ -6,12 +6,12 @@ import (
"testing"
"time"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"

View File

@ -3,7 +3,7 @@ package system
import (
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/stretchr/testify/assert"
)

View File

@ -6,10 +6,10 @@ import (
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/command/idresolver"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"golang.org/x/net/context"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/golden"

View File

@ -6,7 +6,7 @@ import (
"strings"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/pkg/testutil"

View File

@ -5,11 +5,11 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"

View File

@ -5,13 +5,13 @@ import (
"testing"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/pkg/errors"
// Import builders to get the builder function as package function
. "github.com/docker/cli/cli/internal/test/builders"
. "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"

View File

@ -8,7 +8,7 @@ import (
"testing"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/pkg/testutil"

View File

@ -4,7 +4,7 @@ import (
"io/ioutil"
"testing"
"github.com/docker/cli/cli/internal/test"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/pkg/testutil"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"

View File

@ -1,68 +0,0 @@
package builders
import (
"time"
"github.com/docker/docker/api/types/swarm"
)
// Config creates a config with default values.
// Any number of config builder functions can be passed to augment it.
func Config(builders ...func(config *swarm.Config)) *swarm.Config {
config := &swarm.Config{}
for _, builder := range builders {
builder(config)
}
return config
}
// ConfigLabels sets the config's labels
func ConfigLabels(labels map[string]string) func(config *swarm.Config) {
return func(config *swarm.Config) {
config.Spec.Labels = labels
}
}
// ConfigName sets the config's name
func ConfigName(name string) func(config *swarm.Config) {
return func(config *swarm.Config) {
config.Spec.Name = name
}
}
// ConfigID sets the config's ID
func ConfigID(ID string) func(config *swarm.Config) {
return func(config *swarm.Config) {
config.ID = ID
}
}
// ConfigVersion sets the version for the config
func ConfigVersion(v swarm.Version) func(*swarm.Config) {
return func(config *swarm.Config) {
config.Version = v
}
}
// ConfigCreatedAt sets the creation time for the config
func ConfigCreatedAt(t time.Time) func(*swarm.Config) {
return func(config *swarm.Config) {
config.CreatedAt = t
}
}
// ConfigUpdatedAt sets the update time for the config
func ConfigUpdatedAt(t time.Time) func(*swarm.Config) {
return func(config *swarm.Config) {
config.UpdatedAt = t
}
}
// ConfigData sets the config payload.
func ConfigData(data []byte) func(*swarm.Config) {
return func(config *swarm.Config) {
config.Spec.Data = data
}
}

View File

@ -1,3 +0,0 @@
// Package builders helps you create struct for your unit test while keeping them expressive.
//
package builders

View File

@ -1,127 +0,0 @@
package builders
import (
"time"
"github.com/docker/docker/api/types/swarm"
)
// Node creates a node with default values.
// Any number of node function builder can be pass to augment it.
//
// n1 := Node() // Returns a default node
// n2 := Node(NodeID("foo"), NodeHostname("bar"), Leader())
func Node(builders ...func(*swarm.Node)) *swarm.Node {
t1 := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
node := &swarm.Node{
ID: "nodeID",
Meta: swarm.Meta{
CreatedAt: t1,
},
Description: swarm.NodeDescription{
Hostname: "defaultNodeHostname",
Platform: swarm.Platform{
Architecture: "x86_64",
OS: "linux",
},
Resources: swarm.Resources{
NanoCPUs: 4,
MemoryBytes: 20 * 1024 * 1024,
},
Engine: swarm.EngineDescription{
EngineVersion: "1.13.0",
Labels: map[string]string{
"engine": "label",
},
Plugins: []swarm.PluginDescription{
{
Type: "Volume",
Name: "local",
},
{
Type: "Network",
Name: "bridge",
},
{
Type: "Network",
Name: "overlay",
},
},
},
},
Status: swarm.NodeStatus{
State: swarm.NodeStateReady,
Addr: "127.0.0.1",
},
Spec: swarm.NodeSpec{
Annotations: swarm.Annotations{
Name: "defaultNodeName",
},
Role: swarm.NodeRoleWorker,
Availability: swarm.NodeAvailabilityActive,
},
}
for _, builder := range builders {
builder(node)
}
return node
}
// NodeID sets the node id
func NodeID(id string) func(*swarm.Node) {
return func(node *swarm.Node) {
node.ID = id
}
}
// NodeName sets the node name
func NodeName(name string) func(*swarm.Node) {
return func(node *swarm.Node) {
node.Spec.Annotations.Name = name
}
}
// NodeLabels sets the node labels
func NodeLabels(labels map[string]string) func(*swarm.Node) {
return func(node *swarm.Node) {
node.Spec.Labels = labels
}
}
// Hostname sets the node hostname
func Hostname(hostname string) func(*swarm.Node) {
return func(node *swarm.Node) {
node.Description.Hostname = hostname
}
}
// Leader sets the current node as a leader
func Leader() func(*swarm.ManagerStatus) {
return func(managerStatus *swarm.ManagerStatus) {
managerStatus.Leader = true
}
}
// Manager set the current node as a manager
func Manager(managerStatusBuilders ...func(*swarm.ManagerStatus)) func(*swarm.Node) {
return func(node *swarm.Node) {
node.Spec.Role = swarm.NodeRoleManager
node.ManagerStatus = ManagerStatus(managerStatusBuilders...)
}
}
// ManagerStatus create a ManageStatus with default values.
func ManagerStatus(managerStatusBuilders ...func(*swarm.ManagerStatus)) *swarm.ManagerStatus {
managerStatus := &swarm.ManagerStatus{
Reachability: swarm.ReachabilityReachable,
Addr: "127.0.0.1",
}
for _, builder := range managerStatusBuilders {
builder(managerStatus)
}
return managerStatus
}

View File

@ -1,61 +0,0 @@
package builders
import (
"time"
"github.com/docker/docker/api/types/swarm"
)
// Secret creates a secret with default values.
// Any number of secret builder functions can be passed to augment it.
func Secret(builders ...func(secret *swarm.Secret)) *swarm.Secret {
secret := &swarm.Secret{}
for _, builder := range builders {
builder(secret)
}
return secret
}
// SecretLabels sets the secret's labels
func SecretLabels(labels map[string]string) func(secret *swarm.Secret) {
return func(secret *swarm.Secret) {
secret.Spec.Labels = labels
}
}
// SecretName sets the secret's name
func SecretName(name string) func(secret *swarm.Secret) {
return func(secret *swarm.Secret) {
secret.Spec.Name = name
}
}
// SecretID sets the secret's ID
func SecretID(ID string) func(secret *swarm.Secret) {
return func(secret *swarm.Secret) {
secret.ID = ID
}
}
// SecretVersion sets the version for the secret
func SecretVersion(v swarm.Version) func(*swarm.Secret) {
return func(secret *swarm.Secret) {
secret.Version = v
}
}
// SecretCreatedAt sets the creation time for the secret
func SecretCreatedAt(t time.Time) func(*swarm.Secret) {
return func(secret *swarm.Secret) {
secret.CreatedAt = t
}
}
// SecretUpdatedAt sets the update time for the secret
func SecretUpdatedAt(t time.Time) func(*swarm.Secret) {
return func(secret *swarm.Secret) {
secret.UpdatedAt = t
}
}

View File

@ -1,74 +0,0 @@
package builders
import (
"github.com/docker/docker/api/types/swarm"
)
// Service creates a service with default values.
// Any number of service builder functions can be passed to augment it.
// Currently, only ServiceName is implemented
func Service(builders ...func(*swarm.Service)) *swarm.Service {
service := &swarm.Service{
ID: "serviceID",
Spec: swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: "defaultServiceName",
},
EndpointSpec: &swarm.EndpointSpec{},
},
}
for _, builder := range builders {
builder(service)
}
return service
}
// ServiceID sets the service ID
func ServiceID(ID string) func(*swarm.Service) {
return func(service *swarm.Service) {
service.ID = ID
}
}
// ServiceName sets the service name
func ServiceName(name string) func(*swarm.Service) {
return func(service *swarm.Service) {
service.Spec.Annotations.Name = name
}
}
// ServiceLabels sets the service's labels
func ServiceLabels(labels map[string]string) func(*swarm.Service) {
return func(service *swarm.Service) {
service.Spec.Annotations.Labels = labels
}
}
// ReplicatedService sets the number of replicas for the service
func ReplicatedService(replicas uint64) func(*swarm.Service) {
return func(service *swarm.Service) {
service.Spec.Mode = swarm.ServiceMode{Replicated: &swarm.ReplicatedService{Replicas: &replicas}}
}
}
// ServiceImage sets the service's image
func ServiceImage(image string) func(*swarm.Service) {
return func(service *swarm.Service) {
service.Spec.TaskTemplate = swarm.TaskSpec{ContainerSpec: swarm.ContainerSpec{Image: image}}
}
}
// ServicePort sets the service's port
func ServicePort(port swarm.PortConfig) func(*swarm.Service) {
return func(service *swarm.Service) {
service.Spec.EndpointSpec.Ports = append(service.Spec.EndpointSpec.Ports, port)
assignedPort := port
if assignedPort.PublishedPort == 0 {
assignedPort.PublishedPort = 30000
}
service.Endpoint.Ports = append(service.Endpoint.Ports, assignedPort)
}
}

View File

@ -1,39 +0,0 @@
package builders
import (
"time"
"github.com/docker/docker/api/types/swarm"
)
// Swarm creates a swarm with default values.
// Any number of swarm function builder can be pass to augment it.
func Swarm(swarmBuilders ...func(*swarm.Swarm)) *swarm.Swarm {
t1 := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
swarm := &swarm.Swarm{
ClusterInfo: swarm.ClusterInfo{
ID: "swarm",
Meta: swarm.Meta{
CreatedAt: t1,
},
Spec: swarm.Spec{},
},
JoinTokens: swarm.JoinTokens{
Worker: "worker-join-token",
Manager: "manager-join-token",
},
}
for _, builder := range swarmBuilders {
builder(swarm)
}
return swarm
}
// Autolock set the swarm into autolock mode
func Autolock() func(*swarm.Swarm) {
return func(swarm *swarm.Swarm) {
swarm.Spec.EncryptionConfig.AutoLockManagers = true
}
}

View File

@ -1,160 +0,0 @@
package builders
import (
"time"
"github.com/docker/docker/api/types/swarm"
)
var (
defaultTime = time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
)
// Task creates a task with default values .
// Any number of task function builder can be pass to augment it.
func Task(taskBuilders ...func(*swarm.Task)) *swarm.Task {
task := &swarm.Task{
ID: "taskID",
Meta: swarm.Meta{
CreatedAt: defaultTime,
},
Annotations: swarm.Annotations{
Name: "defaultTaskName",
},
Spec: *TaskSpec(),
ServiceID: "rl02d5gwz6chzu7il5fhtb8be",
Slot: 1,
Status: *TaskStatus(),
DesiredState: swarm.TaskStateReady,
}
for _, builder := range taskBuilders {
builder(task)
}
return task
}
// TaskID sets the task ID
func TaskID(id string) func(*swarm.Task) {
return func(task *swarm.Task) {
task.ID = id
}
}
// TaskName sets the task name
func TaskName(name string) func(*swarm.Task) {
return func(task *swarm.Task) {
task.Annotations.Name = name
}
}
// TaskServiceID sets the task service's ID
func TaskServiceID(id string) func(*swarm.Task) {
return func(task *swarm.Task) {
task.ServiceID = id
}
}
// TaskNodeID sets the task's node id
func TaskNodeID(id string) func(*swarm.Task) {
return func(task *swarm.Task) {
task.NodeID = id
}
}
// TaskDesiredState sets the task's desired state
func TaskDesiredState(state swarm.TaskState) func(*swarm.Task) {
return func(task *swarm.Task) {
task.DesiredState = state
}
}
// TaskSlot sets the task's slot
func TaskSlot(slot int) func(*swarm.Task) {
return func(task *swarm.Task) {
task.Slot = slot
}
}
// WithStatus sets the task status
func WithStatus(statusBuilders ...func(*swarm.TaskStatus)) func(*swarm.Task) {
return func(task *swarm.Task) {
task.Status = *TaskStatus(statusBuilders...)
}
}
// TaskStatus creates a task status with default values .
// Any number of taskStatus function builder can be pass to augment it.
func TaskStatus(statusBuilders ...func(*swarm.TaskStatus)) *swarm.TaskStatus {
timestamp := defaultTime.Add(1 * time.Hour)
taskStatus := &swarm.TaskStatus{
State: swarm.TaskStateReady,
Timestamp: timestamp,
}
for _, builder := range statusBuilders {
builder(taskStatus)
}
return taskStatus
}
// Timestamp sets the task status timestamp
func Timestamp(t time.Time) func(*swarm.TaskStatus) {
return func(taskStatus *swarm.TaskStatus) {
taskStatus.Timestamp = t
}
}
// StatusErr sets the tasks status error
func StatusErr(err string) func(*swarm.TaskStatus) {
return func(taskStatus *swarm.TaskStatus) {
taskStatus.Err = err
}
}
// TaskState sets the task's current state
func TaskState(state swarm.TaskState) func(*swarm.TaskStatus) {
return func(taskStatus *swarm.TaskStatus) {
taskStatus.State = state
}
}
// PortStatus sets the tasks port config status
// FIXME(vdemeester) should be a sub builder 👼
func PortStatus(portConfigs []swarm.PortConfig) func(*swarm.TaskStatus) {
return func(taskStatus *swarm.TaskStatus) {
taskStatus.PortStatus.Ports = portConfigs
}
}
// WithTaskSpec sets the task spec
func WithTaskSpec(specBuilders ...func(*swarm.TaskSpec)) func(*swarm.Task) {
return func(task *swarm.Task) {
task.Spec = *TaskSpec(specBuilders...)
}
}
// TaskSpec creates a task spec with default values .
// Any number of taskSpec function builder can be pass to augment it.
func TaskSpec(specBuilders ...func(*swarm.TaskSpec)) *swarm.TaskSpec {
taskSpec := &swarm.TaskSpec{
ContainerSpec: swarm.ContainerSpec{
Image: "myimage:mytag",
},
}
for _, builder := range specBuilders {
builder(taskSpec)
}
return taskSpec
}
// TaskImage sets the task's image
func TaskImage(image string) func(*swarm.TaskSpec) {
return func(taskSpec *swarm.TaskSpec) {
taskSpec.ContainerSpec.Image = image
}
}

View File

@ -1,43 +0,0 @@
package builders
import (
"github.com/docker/docker/api/types"
)
// Volume creates a volume with default values.
// Any number of volume function builder can be pass to augment it.
func Volume(builders ...func(volume *types.Volume)) *types.Volume {
volume := &types.Volume{
Name: "volume",
Driver: "local",
Mountpoint: "/data/volume",
Scope: "local",
}
for _, builder := range builders {
builder(volume)
}
return volume
}
// VolumeLabels sets the volume labels
func VolumeLabels(labels map[string]string) func(volume *types.Volume) {
return func(volume *types.Volume) {
volume.Labels = labels
}
}
// VolumeName sets the volume labels
func VolumeName(name string) func(volume *types.Volume) {
return func(volume *types.Volume) {
volume.Name = name
}
}
// VolumeDriver sets the volume driver
func VolumeDriver(name string) func(volume *types.Volume) {
return func(volume *types.Volume) {
volume.Driver = name
}
}

View File

@ -1,93 +0,0 @@
package test
import (
"bytes"
"io"
"io/ioutil"
"strings"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/docker/client"
)
// FakeCli emulates the default DockerCli
type FakeCli struct {
command.DockerCli
client client.APIClient
configfile *configfile.ConfigFile
out *command.OutStream
outBuffer *bytes.Buffer
err *bytes.Buffer
in *command.InStream
server command.ServerInfo
}
// NewFakeCli returns a fake for the command.Cli interface
func NewFakeCli(client client.APIClient) *FakeCli {
outBuffer := new(bytes.Buffer)
errBuffer := new(bytes.Buffer)
return &FakeCli{
client: client,
out: command.NewOutStream(outBuffer),
outBuffer: outBuffer,
err: errBuffer,
in: command.NewInStream(ioutil.NopCloser(strings.NewReader(""))),
configfile: configfile.New("configfile"),
}
}
// SetIn sets the input of the cli to the specified ReadCloser
func (c *FakeCli) SetIn(in *command.InStream) {
c.in = in
}
// SetErr sets the stderr stream for the cli to the specified io.Writer
func (c *FakeCli) SetErr(err *bytes.Buffer) {
c.err = err
}
// SetConfigFile sets the "fake" config file
func (c *FakeCli) SetConfigFile(configfile *configfile.ConfigFile) {
c.configfile = configfile
}
// Client returns a docker API client
func (c *FakeCli) Client() client.APIClient {
return c.client
}
// Out returns the output stream (stdout) the cli should write on
func (c *FakeCli) Out() *command.OutStream {
return c.out
}
// Err returns the output stream (stderr) the cli should write on
func (c *FakeCli) Err() io.Writer {
return c.err
}
// In returns the input stream the cli will use
func (c *FakeCli) In() *command.InStream {
return c.in
}
// ConfigFile returns the cli configfile object (to get client configuration)
func (c *FakeCli) ConfigFile() *configfile.ConfigFile {
return c.configfile
}
// ServerInfo returns API server information for the server used by this client
func (c *FakeCli) ServerInfo() command.ServerInfo {
return c.server
}
// OutBuffer returns the stdout buffer
func (c *FakeCli) OutBuffer() *bytes.Buffer {
return c.outBuffer
}
// ErrBuffer Buffer returns the stderr buffer
func (c *FakeCli) ErrBuffer() *bytes.Buffer {
return c.err
}

View File

@ -1,5 +0,0 @@
// Package test is a test-only package that can be used by other cli package to write unit test.
//
// It as an internal package and cannot be used outside of github.com/docker/cli/cli package.
//
package test

View File

@ -1,56 +0,0 @@
package network
import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/network"
"golang.org/x/net/context"
)
// FakeClient is a fake NetworkAPIClient
type FakeClient struct {
NetworkInspectFunc func(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, error)
}
// NetworkConnect fakes connecting to a network
func (c *FakeClient) NetworkConnect(ctx context.Context, networkID, container string, config *network.EndpointSettings) error {
return nil
}
// NetworkCreate fakes creating a network
func (c *FakeClient) NetworkCreate(_ context.Context, _ string, options types.NetworkCreate) (types.NetworkCreateResponse, error) {
return types.NetworkCreateResponse{}, nil
}
// NetworkDisconnect fakes disconnecting from a network
func (c *FakeClient) NetworkDisconnect(ctx context.Context, networkID, container string, force bool) error {
return nil
}
// NetworkInspect fakes inspecting a network
func (c *FakeClient) NetworkInspect(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, error) {
if c.NetworkInspectFunc != nil {
return c.NetworkInspectFunc(ctx, networkID, options)
}
return types.NetworkResource{}, nil
}
// NetworkInspectWithRaw fakes inspecting a network with a raw response
func (c *FakeClient) NetworkInspectWithRaw(_ context.Context, _ string, _ types.NetworkInspectOptions) (types.NetworkResource, []byte, error) {
return types.NetworkResource{}, nil, nil
}
// NetworkList fakes listing networks
func (c *FakeClient) NetworkList(_ context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
return nil, nil
}
// NetworkRemove fakes removing networks
func (c *FakeClient) NetworkRemove(ctx context.Context, networkID string) error {
return nil
}
// NetworksPrune fakes pruning networks
func (c *FakeClient) NetworksPrune(_ context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error) {
return types.NetworksPruneReport{}, nil
}

View File

@ -1,73 +0,0 @@
package test
import (
"github.com/docker/cli/cli/config/credentials"
"github.com/docker/docker/api/types"
)
// fake store implements a credentials.Store that only acts as an in memory map
type fakeStore struct {
store map[string]types.AuthConfig
eraseFunc func(serverAddress string) error
getFunc func(serverAddress string) (types.AuthConfig, error)
getAllFunc func() (map[string]types.AuthConfig, error)
storeFunc func(authConfig types.AuthConfig) error
}
// NewFakeStore creates a new file credentials store.
func NewFakeStore() credentials.Store {
return &fakeStore{store: map[string]types.AuthConfig{}}
}
func (c *fakeStore) SetStore(store map[string]types.AuthConfig) {
c.store = store
}
func (c *fakeStore) SetEraseFunc(eraseFunc func(string) error) {
c.eraseFunc = eraseFunc
}
func (c *fakeStore) SetGetFunc(getFunc func(string) (types.AuthConfig, error)) {
c.getFunc = getFunc
}
func (c *fakeStore) SetGetAllFunc(getAllFunc func() (map[string]types.AuthConfig, error)) {
c.getAllFunc = getAllFunc
}
func (c *fakeStore) SetStoreFunc(storeFunc func(types.AuthConfig) error) {
c.storeFunc = storeFunc
}
// Erase removes the given credentials from the map store
func (c *fakeStore) Erase(serverAddress string) error {
if c.eraseFunc != nil {
return c.eraseFunc(serverAddress)
}
delete(c.store, serverAddress)
return nil
}
// Get retrieves credentials for a specific server from the map store.
func (c *fakeStore) Get(serverAddress string) (types.AuthConfig, error) {
if c.getFunc != nil {
return c.getFunc(serverAddress)
}
return c.store[serverAddress], nil
}
func (c *fakeStore) GetAll() (map[string]types.AuthConfig, error) {
if c.getAllFunc != nil {
return c.getAllFunc()
}
return c.store, nil
}
// Store saves the given credentials in the map store.
func (c *fakeStore) Store(authConfig types.AuthConfig) error {
if c.storeFunc != nil {
return c.storeFunc(authConfig)
}
c.store[authConfig.ServerAddress] = authConfig
return nil
}