github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/integration/internal/network/network.go (about)

     1  package network
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/demonoid81/moby/api/types"
     8  	"github.com/demonoid81/moby/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  }