github.com/ali-iotechsys/cli@v20.10.0+incompatible/internal/test/builders/secret.go (about)

     1  package builders
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/docker/docker/api/types/swarm"
     7  )
     8  
     9  // Secret creates a secret with default values.
    10  // Any number of secret builder functions can be passed to augment it.
    11  func Secret(builders ...func(secret *swarm.Secret)) *swarm.Secret {
    12  	secret := &swarm.Secret{}
    13  
    14  	for _, builder := range builders {
    15  		builder(secret)
    16  	}
    17  
    18  	return secret
    19  }
    20  
    21  // SecretLabels sets the secret's labels
    22  func SecretLabels(labels map[string]string) func(secret *swarm.Secret) {
    23  	return func(secret *swarm.Secret) {
    24  		secret.Spec.Labels = labels
    25  	}
    26  }
    27  
    28  // SecretName sets the secret's name
    29  func SecretName(name string) func(secret *swarm.Secret) {
    30  	return func(secret *swarm.Secret) {
    31  		secret.Spec.Name = name
    32  	}
    33  }
    34  
    35  // SecretDriver sets the secret's driver name
    36  func SecretDriver(driver string) func(secret *swarm.Secret) {
    37  	return func(secret *swarm.Secret) {
    38  		secret.Spec.Driver = &swarm.Driver{
    39  			Name: driver,
    40  		}
    41  	}
    42  }
    43  
    44  // SecretID sets the secret's ID
    45  func SecretID(ID string) func(secret *swarm.Secret) {
    46  	return func(secret *swarm.Secret) {
    47  		secret.ID = ID
    48  	}
    49  }
    50  
    51  // SecretVersion sets the version for the secret
    52  func SecretVersion(v swarm.Version) func(*swarm.Secret) {
    53  	return func(secret *swarm.Secret) {
    54  		secret.Version = v
    55  	}
    56  }
    57  
    58  // SecretCreatedAt sets the creation time for the secret
    59  func SecretCreatedAt(t time.Time) func(*swarm.Secret) {
    60  	return func(secret *swarm.Secret) {
    61  		secret.CreatedAt = t
    62  	}
    63  }
    64  
    65  // SecretUpdatedAt sets the update time for the secret
    66  func SecretUpdatedAt(t time.Time) func(*swarm.Secret) {
    67  	return func(secret *swarm.Secret) {
    68  		secret.UpdatedAt = t
    69  	}
    70  }