github.com/etecs-ru/gnomock@v0.13.2/preset/postgres/options.go (about)

     1  package postgres
     2  
     3  // Option is an optional configuration of this Gnomock preset. Use available
     4  // Options to configure the container.
     5  type Option func(*P)
     6  
     7  // WithUser creates a new superuser with the provided credentials in the
     8  // container.
     9  func WithUser(user, password string) Option {
    10  	return func(p *P) {
    11  		p.User = user
    12  		p.Password = password
    13  	}
    14  }
    15  
    16  // WithDatabase creates a database with the provided name in the container.
    17  // WithQueries, if provided, runs against the new database.
    18  func WithDatabase(db string) Option {
    19  	return func(p *P) {
    20  		p.DB = db
    21  	}
    22  }
    23  
    24  // WithQueries executes the provided queries against the database created with
    25  // WithDatabase, or against default postgres database.
    26  func WithQueries(queries ...string) Option {
    27  	return func(p *P) {
    28  		p.Queries = append(p.Queries, queries...)
    29  	}
    30  }
    31  
    32  // WithQueriesFile sets a file name to read initial queries from. Queries from
    33  // this file are executed before any other queries provided in WithQueries.
    34  func WithQueriesFile(file string) Option {
    35  	return func(p *P) {
    36  		p.QueriesFiles = append(p.QueriesFiles, file)
    37  	}
    38  }
    39  
    40  // WithVersion sets image version.
    41  func WithVersion(version string) Option {
    42  	return func(o *P) {
    43  		o.Version = version
    44  	}
    45  }