diff options
| author | 2025-07-09 17:25:45 +0200 | |
|---|---|---|
| committer | 2025-07-09 17:25:45 +0200 | |
| commit | 352353ce7a33c3ac26fbecd597ab24ae2f9c9864 (patch) | |
| tree | eeea288eea02162ff25e54c9052eaffd705cb5ad /internal | |
| parent | [feature] Use `hidesToPublicFromUnauthedWeb` and `hidesCcPublicFromUnauthedWe... (diff) | |
| download | gotosocial-352353ce7a33c3ac26fbecd597ab24ae2f9c9864.tar.xz | |
[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>
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/config/config.go | 2 | ||||
| -rw-r--r-- | internal/config/flags.go | 11 | ||||
| -rw-r--r-- | internal/config/helpers.gen.go | 66 |
3 files changed, 78 insertions, 1 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 8139770e0..95d74342e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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 { diff --git a/internal/config/flags.go b/internal/config/flags.go index 3c94b5799..eb862fc9a 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -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) +} diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go index 36dd927f8..4aea742c1 100644 --- a/internal/config/helpers.gen.go +++ b/internal/config/helpers.gen.go @@ -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() |
