mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-28 20:02:24 -05:00
[chore/testing] Add env vars to skip testrig setup/teardown (#4317)
Add flags to skip local testrig db setup and teardown, to allow somewhat easier testing of migrations. Documents env vars available to the testrig. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4317 Co-authored-by: tobi <tobi.smethurst@protonmail.com> Co-committed-by: tobi <tobi.smethurst@protonmail.com>
This commit is contained in:
parent
dcfc9b7885
commit
352353ce7a
8 changed files with 126 additions and 6 deletions
|
|
@ -182,6 +182,8 @@ type Configuration struct {
|
|||
AdminMediaPruneDryRun bool `name:"dry-run" usage:"perform a dry run and only log number of items eligible for pruning" ephemeral:"yes"`
|
||||
AdminMediaListLocalOnly bool `name:"local-only" usage:"list only local attachments/emojis; if specified then remote-only cannot also be true" ephemeral:"yes"`
|
||||
AdminMediaListRemoteOnly bool `name:"remote-only" usage:"list only remote attachments/emojis; if specified then local-only cannot also be true" ephemeral:"yes"`
|
||||
TestrigSkipDBSetup bool `name:"skip-db-setup" usage:"skip testrig database setup with population of test models" ephemeral:"yes"`
|
||||
TestrigSkipDBTeardown bool `name:"skip-db-teardown" usage:"skip testrig database teardown (i.e. data deletion and tables dropped)" ephemeral:"yes"`
|
||||
}
|
||||
|
||||
type HTTPClientConfiguration struct {
|
||||
|
|
|
|||
|
|
@ -84,3 +84,14 @@ func AddAdminMediaPrune(cmd *cobra.Command) {
|
|||
usage := fieldtag("AdminMediaPruneDryRun", "usage")
|
||||
cmd.Flags().Bool(name, true, usage)
|
||||
}
|
||||
|
||||
// AddTestrig attaches flags pertaining to testrig commands.
|
||||
func AddTestrig(cmd *cobra.Command) {
|
||||
skipDBSetup := TestrigSkipDBSetupFlag
|
||||
skipDBSetupUsage := fieldtag("TestrigSkipDBSetup", "usage")
|
||||
cmd.Flags().Bool(skipDBSetup, false, skipDBSetupUsage)
|
||||
|
||||
skipDBTeardown := TestrigSkipDBTeardownFlag
|
||||
skipDBTeardownUsage := fieldtag("TestrigSkipDBTeardown", "usage")
|
||||
cmd.Flags().Bool(skipDBTeardown, false, skipDBTeardownUsage)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,6 +220,8 @@ const (
|
|||
AdminMediaPruneDryRunFlag = "dry-run"
|
||||
AdminMediaListLocalOnlyFlag = "local-only"
|
||||
AdminMediaListRemoteOnlyFlag = "remote-only"
|
||||
TestrigSkipDBSetupFlag = "skip-db-setup"
|
||||
TestrigSkipDBTeardownFlag = "skip-db-teardown"
|
||||
)
|
||||
|
||||
func (cfg *Configuration) RegisterFlags(flags *pflag.FlagSet) {
|
||||
|
|
@ -410,7 +412,7 @@ func (cfg *Configuration) RegisterFlags(flags *pflag.FlagSet) {
|
|||
}
|
||||
|
||||
func (cfg *Configuration) MarshalMap() map[string]any {
|
||||
cfgmap := make(map[string]any, 191)
|
||||
cfgmap := make(map[string]any, 193)
|
||||
cfgmap["log-level"] = cfg.LogLevel
|
||||
cfgmap["log-timestamp-format"] = cfg.LogTimestampFormat
|
||||
cfgmap["log-db-queries"] = cfg.LogDbQueries
|
||||
|
|
@ -602,6 +604,8 @@ func (cfg *Configuration) MarshalMap() map[string]any {
|
|||
cfgmap["dry-run"] = cfg.AdminMediaPruneDryRun
|
||||
cfgmap["local-only"] = cfg.AdminMediaListLocalOnly
|
||||
cfgmap["remote-only"] = cfg.AdminMediaListRemoteOnly
|
||||
cfgmap["skip-db-setup"] = cfg.TestrigSkipDBSetup
|
||||
cfgmap["skip-db-teardown"] = cfg.TestrigSkipDBTeardown
|
||||
return cfgmap
|
||||
}
|
||||
|
||||
|
|
@ -2173,6 +2177,22 @@ func (cfg *Configuration) UnmarshalMap(cfgmap map[string]any) error {
|
|||
}
|
||||
}
|
||||
|
||||
if ival, ok := cfgmap["skip-db-setup"]; ok {
|
||||
var err error
|
||||
cfg.TestrigSkipDBSetup, err = cast.ToBoolE(ival)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error casting %#v -> bool for 'skip-db-setup': %w", ival, err)
|
||||
}
|
||||
}
|
||||
|
||||
if ival, ok := cfgmap["skip-db-teardown"]; ok {
|
||||
var err error
|
||||
cfg.TestrigSkipDBTeardown, err = cast.ToBoolE(ival)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error casting %#v -> bool for 'skip-db-teardown': %w", ival, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -6406,6 +6426,50 @@ func GetAdminMediaListRemoteOnly() bool { return global.GetAdminMediaListRemoteO
|
|||
// SetAdminMediaListRemoteOnly safely sets the value for global configuration 'AdminMediaListRemoteOnly' field
|
||||
func SetAdminMediaListRemoteOnly(v bool) { global.SetAdminMediaListRemoteOnly(v) }
|
||||
|
||||
// GetTestrigSkipDBSetup safely fetches the Configuration value for state's 'TestrigSkipDBSetup' field
|
||||
func (st *ConfigState) GetTestrigSkipDBSetup() (v bool) {
|
||||
st.mutex.RLock()
|
||||
v = st.config.TestrigSkipDBSetup
|
||||
st.mutex.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
// SetTestrigSkipDBSetup safely sets the Configuration value for state's 'TestrigSkipDBSetup' field
|
||||
func (st *ConfigState) SetTestrigSkipDBSetup(v bool) {
|
||||
st.mutex.Lock()
|
||||
defer st.mutex.Unlock()
|
||||
st.config.TestrigSkipDBSetup = v
|
||||
st.reloadToViper()
|
||||
}
|
||||
|
||||
// GetTestrigSkipDBSetup safely fetches the value for global configuration 'TestrigSkipDBSetup' field
|
||||
func GetTestrigSkipDBSetup() bool { return global.GetTestrigSkipDBSetup() }
|
||||
|
||||
// SetTestrigSkipDBSetup safely sets the value for global configuration 'TestrigSkipDBSetup' field
|
||||
func SetTestrigSkipDBSetup(v bool) { global.SetTestrigSkipDBSetup(v) }
|
||||
|
||||
// GetTestrigSkipDBTeardown safely fetches the Configuration value for state's 'TestrigSkipDBTeardown' field
|
||||
func (st *ConfigState) GetTestrigSkipDBTeardown() (v bool) {
|
||||
st.mutex.RLock()
|
||||
v = st.config.TestrigSkipDBTeardown
|
||||
st.mutex.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
// SetTestrigSkipDBTeardown safely sets the Configuration value for state's 'TestrigSkipDBTeardown' field
|
||||
func (st *ConfigState) SetTestrigSkipDBTeardown(v bool) {
|
||||
st.mutex.Lock()
|
||||
defer st.mutex.Unlock()
|
||||
st.config.TestrigSkipDBTeardown = v
|
||||
st.reloadToViper()
|
||||
}
|
||||
|
||||
// GetTestrigSkipDBTeardown safely fetches the value for global configuration 'TestrigSkipDBTeardown' field
|
||||
func GetTestrigSkipDBTeardown() bool { return global.GetTestrigSkipDBTeardown() }
|
||||
|
||||
// SetTestrigSkipDBTeardown safely sets the value for global configuration 'TestrigSkipDBTeardown' field
|
||||
func SetTestrigSkipDBTeardown(v bool) { global.SetTestrigSkipDBTeardown(v) }
|
||||
|
||||
// GetTotalOfMemRatios safely fetches the combined value for all the state's mem ratio fields
|
||||
func (st *ConfigState) GetTotalOfMemRatios() (total float64) {
|
||||
st.mutex.RLock()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue