github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/integration/internal/network/network.go (about)

     1  package network
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/docker/docker/client"
     9  	"gotest.tools/v3/assert"
    10  )
    11  
    12  func createNetwork(ctx context.Context, client client.APIClient, name string, ops ...func(*types.NetworkCreate)) (string, error) {
    13  	config := types.NetworkCreate{}
    14  
    15  	for _, op := range ops {
    16  		op(&config)
    17  	}
    18  
    19  	n, err := client.NetworkCreate(ctx, name, config)
    20  	return n.ID, err
    21  }
    22  
    23  // Create creates a network with the specified options
    24  func Create(ctx context.Context, client client.APIClient, name string, ops ...func(*types.NetworkCreate)) (string, error) {
    25  	return createNetwork(ctx, client, name, ops...)
    26  }
    27  
    28  // CreateNoError creates a network with the specified options and verifies there were no errors
    29  func CreateNoError(ctx context.Context, t *testing.T, client client.APIClient, name string, ops ...func(*types.NetworkCreate)) string { // nolint: golint
    30  	t.Helper()
    31  
    32  	name, err := createNetwork(ctx, client, name, ops...)
    33  	assert.NilError(t, err)
    34  	return name
    35  }