returnnil,fmt.Errorf("Cannot provide both WithConfigFile and WithConfigText")
}
returnopts.tcOptions,nil
}
typeoptionstruct{
tcOptions*controller.TestControllerOpts
setWithConfigFilebool
setWithConfigTextbool
setDisableDatabaseCreationbool
setDefaultOrgIdbool
}
typeOptionfunc(*option)error
// WithConfigFile provides the given ConfigFile to the built TestController. This option can not be used if WithConfigText is used.
funcWithConfigFile(fstring)Option{
returnfunc(c*option)error{
ifc.setWithConfigFile{
returnfmt.Errorf("WithConfigFile provided more than once.")
}
c.setWithConfigFile=true
cfg,err:=config.LoadFile(f)
iferr!=nil{
returnerr
}
c.tcOptions.Config=cfg
returnnil
}
}
// WithConfigText configures the TestController sets up the Controller using the provided config text. This option cannot be used if WithConfigFile is used.
funcWithConfigText(ctstring)Option{
returnfunc(c*option)error{
ifc.setWithConfigText{
returnfmt.Errorf("WithConfigText provided more than once.")
}
c.setWithConfigText=true
cfg,err:=config.Parse(ct)
iferr!=nil{
returnerr
}
c.tcOptions.Config=cfg
returnnil
}
}
// DisableDatabaseCreation skips creating a database in docker and allows one to be provided through a tcOptions.
funcDisableDatabaseCreation()Option{
returnfunc(c*option)error{
ifc.setDisableDatabaseCreation{
returnfmt.Errorf("DisableDatabaseCreation provided more than once.")
}
c.setDisableDatabaseCreation=true
c.tcOptions.DisableDatabaseCreation=true
returnnil
}
}
// WithDefaultOrgId sets the org id to the one provided here.
funcWithDefaultOrgId(idstring)Option{
returnfunc(c*option)error{
ifc.setDefaultOrgId{
returnfmt.Errorf("WithDefaultOrgId provided more than once.")
}
c.setDefaultOrgId=true
c.tcOptions.DefaultOrgId=id
returnnil
}
}
// NewTestController blocks until a new TestController is created, returns the url for the TestController and a function
// that can be called to tear down the controller after it has been used for testing.