summaryrefslogtreecommitdiff
path: root/testrig/config.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-05-27 15:46:15 +0000
committerLibravatar GitHub <noreply@github.com>2024-05-27 17:46:15 +0200
commit1e7b32490dfdccddd04f46d4b0416b48d749d51b (patch)
tree62a11365933a5a11e0800af64cbdf9172e5e6e7a /testrig/config.go
parent[chore] Small styling + link issues (#2933) (diff)
downloadgotosocial-1e7b32490dfdccddd04f46d4b0416b48d749d51b.tar.xz
[experiment] add alternative wasm sqlite3 implementation available via build-tag (#2863)
This allows for building GoToSocial with [SQLite transpiled to WASM](https://github.com/ncruces/go-sqlite3) and accessed through [Wazero](https://wazero.io/).
Diffstat (limited to 'testrig/config.go')
-rw-r--r--testrig/config.go263
1 files changed, 142 insertions, 121 deletions
diff --git a/testrig/config.go b/testrig/config.go
index 93f3c5523..30beaa910 100644
--- a/testrig/config.go
+++ b/testrig/config.go
@@ -18,8 +18,8 @@
package testrig
import (
- "cmp"
"os"
+ "strconv"
"time"
"codeberg.org/gruf/go-bytesize"
@@ -28,128 +28,149 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/language"
)
-// InitTestConfig initializes viper configuration with test defaults.
+// InitTestConfig initializes viper
+// configuration with test defaults.
func InitTestConfig() {
- config.Config(func(cfg *config.Configuration) {
- *cfg = testDefaults
- })
+ config.Defaults = testDefaults()
+ config.Reset()
}
-var testDefaults = config.Configuration{
- LogLevel: cmp.Or(os.Getenv("GTS_LOG_LEVEL"), "error"),
- LogTimestampFormat: "02/01/2006 15:04:05.000",
- LogDbQueries: true,
- ApplicationName: "gotosocial",
- LandingPageUser: "",
- ConfigPath: "",
- Host: "localhost:8080",
- AccountDomain: "localhost:8080",
- Protocol: "http",
- BindAddress: "127.0.0.1",
- Port: 8080,
- TrustedProxies: []string{"127.0.0.1/32", "::1"},
-
- DbType: "sqlite",
- DbAddress: ":memory:",
- DbPort: 5432,
- DbUser: "postgres",
- DbPassword: "postgres",
- DbDatabase: "postgres",
- DbTLSMode: "disable",
- DbTLSCACert: "",
- DbMaxOpenConnsMultiplier: 8,
- DbSqliteJournalMode: "WAL",
- DbSqliteSynchronous: "NORMAL",
- DbSqliteCacheSize: 8 * bytesize.MiB,
- DbSqliteBusyTimeout: time.Minute * 5,
-
- WebTemplateBaseDir: "./web/template/",
- WebAssetBaseDir: "./web/assets/",
-
- InstanceFederationMode: config.InstanceFederationModeDefault,
- InstanceFederationSpamFilter: true,
- InstanceExposePeers: true,
- InstanceExposeSuspended: true,
- InstanceExposeSuspendedWeb: true,
- InstanceDeliverToSharedInboxes: true,
- InstanceLanguages: language.Languages{
- {
- TagStr: "nl",
- },
- {
- TagStr: "en-gb",
+func testDefaults() config.Configuration {
+ return config.Configuration{
+ LogLevel: envStr("GTS_LOG_LEVEL", "error"),
+ LogTimestampFormat: "02/01/2006 15:04:05.000",
+ LogDbQueries: true,
+ ApplicationName: "gotosocial",
+ LandingPageUser: "",
+ ConfigPath: "",
+ Host: "localhost:8080",
+ AccountDomain: "localhost:8080",
+ Protocol: "http",
+ BindAddress: "127.0.0.1",
+ Port: 8080,
+ TrustedProxies: []string{"127.0.0.1/32", "::1"},
+ DbType: envStr("GTS_DB_TYPE", "sqlite"),
+ DbAddress: envStr("GTS_DB_ADDRESS", ":memory:"),
+ DbPort: envInt("GTS_DB_PORT", 0),
+ DbUser: envStr("GTS_DB_USER", ""),
+ DbPassword: envStr("GTS_DB_PASSWORD", ""),
+ DbDatabase: envStr("GTS_DB_DATABASE", ""),
+ DbTLSMode: envStr("GTS_DB_TLS_MODE", ""),
+ DbTLSCACert: envStr("GTS_DB_TLS_CA_CERT", ""),
+ DbMaxOpenConnsMultiplier: 8,
+ DbSqliteJournalMode: "WAL",
+ DbSqliteSynchronous: "NORMAL",
+ DbSqliteCacheSize: 8 * bytesize.MiB,
+ DbSqliteBusyTimeout: time.Minute * 5,
+
+ WebTemplateBaseDir: "./web/template/",
+ WebAssetBaseDir: "./web/assets/",
+
+ InstanceFederationMode: config.InstanceFederationModeDefault,
+ InstanceFederationSpamFilter: true,
+ InstanceExposePeers: true,
+ InstanceExposeSuspended: true,
+ InstanceExposeSuspendedWeb: true,
+ InstanceDeliverToSharedInboxes: true,
+ InstanceLanguages: language.Languages{
+ {
+ TagStr: "nl",
+ },
+ {
+ TagStr: "en-gb",
+ },
},
- },
-
- AccountsRegistrationOpen: true,
- AccountsReasonRequired: true,
- AccountsAllowCustomCSS: true,
- AccountsCustomCSSLength: 10000,
-
- MediaImageMaxSize: 10485760, // 10MiB
- MediaVideoMaxSize: 41943040, // 40MiB
- MediaDescriptionMinChars: 0,
- MediaDescriptionMaxChars: 500,
- MediaRemoteCacheDays: 7,
- MediaEmojiLocalMaxSize: 51200, // 50KiB
- MediaEmojiRemoteMaxSize: 102400, // 100KiB
- MediaCleanupFrom: "00:00", // midnight.
- MediaCleanupEvery: 24 * time.Hour, // 1/day.
-
- // the testrig only uses in-memory storage, so we can
- // safely set this value to 'test' to avoid running storage
- // migrations, and other silly things like that
- StorageBackend: "test",
- StorageLocalBasePath: "",
-
- StatusesMaxChars: 5000,
- StatusesPollMaxOptions: 6,
- StatusesPollOptionMaxChars: 50,
- StatusesMediaMaxFiles: 6,
-
- LetsEncryptEnabled: false,
- LetsEncryptPort: 0,
- LetsEncryptCertDir: "",
- LetsEncryptEmailAddress: "",
-
- OIDCEnabled: false,
- OIDCIdpName: "",
- OIDCSkipVerification: false,
- OIDCIssuer: "",
- OIDCClientID: "",
- OIDCClientSecret: "",
- OIDCScopes: []string{oidc.ScopeOpenID, "profile", "email", "groups"},
- OIDCLinkExisting: false,
- OIDCAdminGroups: []string{"adminRole"},
- OIDCAllowedGroups: []string{"allowedRole"},
-
- SMTPHost: "",
- SMTPPort: 0,
- SMTPUsername: "",
- SMTPPassword: "",
- SMTPFrom: "GoToSocial",
- SMTPDiscloseRecipients: false,
-
- TracingEnabled: false,
- TracingEndpoint: "localhost:4317",
- TracingTransport: "grpc",
- TracingInsecureTransport: true,
-
- MetricsEnabled: false,
- MetricsAuthEnabled: false,
-
- SyslogEnabled: false,
- SyslogProtocol: "udp",
- SyslogAddress: "localhost:514",
-
- AdvancedCookiesSamesite: "lax",
- AdvancedRateLimitRequests: 0, // disabled
- AdvancedThrottlingMultiplier: 0, // disabled
- AdvancedSenderMultiplier: 0, // 1 sender only, regardless of CPU
- AdvancedHeaderFilterMode: config.RequestHeaderFilterModeBlock,
-
- SoftwareVersion: "0.0.0-testrig",
-
- // simply use cache defaults.
- Cache: config.Defaults.Cache,
+
+ AccountsRegistrationOpen: true,
+ AccountsReasonRequired: true,
+ AccountsAllowCustomCSS: true,
+ AccountsCustomCSSLength: 10000,
+
+ MediaImageMaxSize: 10485760, // 10MiB
+ MediaVideoMaxSize: 41943040, // 40MiB
+ MediaDescriptionMinChars: 0,
+ MediaDescriptionMaxChars: 500,
+ MediaRemoteCacheDays: 7,
+ MediaEmojiLocalMaxSize: 51200, // 50KiB
+ MediaEmojiRemoteMaxSize: 102400, // 100KiB
+ MediaCleanupFrom: "00:00", // midnight.
+ MediaCleanupEvery: 24 * time.Hour, // 1/day.
+
+ // the testrig only uses in-memory storage, so we can
+ // safely set this value to 'test' to avoid running storage
+ // migrations, and other silly things like that
+ StorageBackend: "test",
+ StorageLocalBasePath: "",
+
+ StatusesMaxChars: 5000,
+ StatusesPollMaxOptions: 6,
+ StatusesPollOptionMaxChars: 50,
+ StatusesMediaMaxFiles: 6,
+
+ LetsEncryptEnabled: false,
+ LetsEncryptPort: 0,
+ LetsEncryptCertDir: "",
+ LetsEncryptEmailAddress: "",
+
+ OIDCEnabled: false,
+ OIDCIdpName: "",
+ OIDCSkipVerification: false,
+ OIDCIssuer: "",
+ OIDCClientID: "",
+ OIDCClientSecret: "",
+ OIDCScopes: []string{oidc.ScopeOpenID, "profile", "email", "groups"},
+ OIDCLinkExisting: false,
+ OIDCAdminGroups: []string{"adminRole"},
+ OIDCAllowedGroups: []string{"allowedRole"},
+
+ SMTPHost: "",
+ SMTPPort: 0,
+ SMTPUsername: "",
+ SMTPPassword: "",
+ SMTPFrom: "GoToSocial",
+ SMTPDiscloseRecipients: false,
+
+ TracingEnabled: false,
+ TracingEndpoint: "localhost:4317",
+ TracingTransport: "grpc",
+ TracingInsecureTransport: true,
+
+ MetricsEnabled: false,
+ MetricsAuthEnabled: false,
+
+ SyslogEnabled: false,
+ SyslogProtocol: "udp",
+ SyslogAddress: "localhost:514",
+
+ AdvancedCookiesSamesite: "lax",
+ AdvancedRateLimitRequests: 0, // disabled
+ AdvancedThrottlingMultiplier: 0, // disabled
+ AdvancedSenderMultiplier: 0, // 1 sender only, regardless of CPU
+
+ SoftwareVersion: "0.0.0-testrig",
+
+ // simply use cache defaults.
+ Cache: config.Defaults.Cache,
+ }
+}
+
+func envInt(key string, _default int) int {
+ return env(key, _default, func(value string) int {
+ i, _ := strconv.Atoi(value)
+ return i
+ })
+}
+
+func envStr(key string, _default string) string {
+ return env(key, _default, func(value string) string {
+ return value
+ })
+}
+
+func env[T any](key string, _default T, parse func(string) T) T {
+ value, ok := os.LookupEnv(key)
+ if ok {
+ return parse(value)
+ }
+ return _default
}