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

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