fiddling about
This commit is contained in:
@ -55,39 +55,10 @@ func (suite *MediaCreateTestSuite) SetupSuite() {
|
||||
suite.log = log
|
||||
|
||||
// Direct config to local postgres instance
|
||||
c := config.Empty()
|
||||
c.Protocol = "http"
|
||||
c.Host = "localhost"
|
||||
c.DBConfig = &config.DBConfig{
|
||||
Type: "postgres",
|
||||
Address: "localhost",
|
||||
Port: 5432,
|
||||
User: "postgres",
|
||||
Password: "postgres",
|
||||
Database: "postgres",
|
||||
ApplicationName: "gotosocial",
|
||||
}
|
||||
c.MediaConfig = &config.MediaConfig{
|
||||
MaxImageSize: 2 << 20,
|
||||
}
|
||||
c.StorageConfig = &config.StorageConfig{
|
||||
Backend: "local",
|
||||
BasePath: "/tmp",
|
||||
ServeProtocol: "http",
|
||||
ServeHost: "localhost",
|
||||
ServeBasePath: "/fileserver/media",
|
||||
}
|
||||
c.StatusesConfig = &config.StatusesConfig{
|
||||
MaxChars: 500,
|
||||
CWMaxChars: 50,
|
||||
PollMaxOptions: 4,
|
||||
PollOptionMaxChars: 50,
|
||||
MaxMediaFiles: 4,
|
||||
}
|
||||
suite.config = c
|
||||
suite.config = testrig.NewTestConfig()
|
||||
|
||||
// use an actual database for this, because it's just easier than mocking one out
|
||||
database, err := db.New(context.Background(), c, log)
|
||||
database, err := db.New(context.Background(), suite.config, log)
|
||||
if err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
@ -108,21 +79,17 @@ func (suite *MediaCreateTestSuite) TearDownSuite() {
|
||||
}
|
||||
|
||||
func (suite *MediaCreateTestSuite) SetupTest() {
|
||||
if err := testrig.StandardDBSetup(suite.db); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
suite.testTokens = testrig.TestTokens()
|
||||
suite.testClients = testrig.TestClients()
|
||||
suite.testApplications = testrig.TestApplications()
|
||||
suite.testUsers = testrig.TestUsers()
|
||||
suite.testAccounts = testrig.TestAccounts()
|
||||
testrig.StandardDBSetup(suite.db)
|
||||
suite.testTokens = testrig.NewTestTokens()
|
||||
suite.testClients = testrig.NewTestClients()
|
||||
suite.testApplications = testrig.NewTestApplications()
|
||||
suite.testUsers = testrig.NewTestUsers()
|
||||
suite.testAccounts = testrig.NewTestAccounts()
|
||||
}
|
||||
|
||||
// TearDownTest drops tables to make sure there's no data in the db
|
||||
func (suite *MediaCreateTestSuite) TearDownTest() {
|
||||
if err := testrig.StandardDBTeardown(suite.db); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
testrig.StandardDBTeardown(suite.db)
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -129,21 +129,17 @@ func (suite *StatusCreateTestSuite) TearDownSuite() {
|
||||
}
|
||||
|
||||
func (suite *StatusCreateTestSuite) SetupTest() {
|
||||
if err := testrig.StandardDBSetup(suite.db); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
suite.testTokens = testrig.TestTokens()
|
||||
suite.testClients = testrig.TestClients()
|
||||
suite.testApplications = testrig.TestApplications()
|
||||
suite.testUsers = testrig.TestUsers()
|
||||
suite.testAccounts = testrig.TestAccounts()
|
||||
testrig.StandardDBSetup(suite.db)
|
||||
suite.testTokens = testrig.NewTestTokens()
|
||||
suite.testClients = testrig.NewTestClients()
|
||||
suite.testApplications = testrig.NewTestApplications()
|
||||
suite.testUsers = testrig.NewTestUsers()
|
||||
suite.testAccounts = testrig.NewTestAccounts()
|
||||
}
|
||||
|
||||
// TearDownTest drops tables to make sure there's no data in the db
|
||||
func (suite *StatusCreateTestSuite) TearDownTest() {
|
||||
if err := testrig.StandardDBTeardown(suite.db); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
testrig.StandardDBTeardown(suite.db)
|
||||
}
|
||||
|
||||
/*
|
||||
@ -241,8 +237,8 @@ func (suite *StatusCreateTestSuite) TestStatusCreatePOSTHandlerReplyToLocalSucce
|
||||
ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccounts["local_account_1"])
|
||||
ctx.Request = httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://localhost:8080/%s", basePath), nil) // the endpoint we're hitting
|
||||
ctx.Request.Form = url.Values{
|
||||
"status": {fmt.Sprintf("hello @%s this reply should work!", testrig.TestAccounts()["local_account_2"].Username)},
|
||||
"in_reply_to_id": {testrig.TestStatuses()["local_account_2_status_1"].ID},
|
||||
"status": {fmt.Sprintf("hello @%s this reply should work!", testrig.NewTestAccounts()["local_account_2"].Username)},
|
||||
"in_reply_to_id": {testrig.NewTestStatuses()["local_account_2_status_1"].ID},
|
||||
}
|
||||
suite.statusModule.statusCreatePOSTHandler(ctx)
|
||||
|
||||
@ -259,11 +255,11 @@ func (suite *StatusCreateTestSuite) TestStatusCreatePOSTHandlerReplyToLocalSucce
|
||||
assert.NoError(suite.T(), err)
|
||||
|
||||
assert.Equal(suite.T(), "", statusReply.SpoilerText)
|
||||
assert.Equal(suite.T(), fmt.Sprintf("hello @%s this reply should work!", testrig.TestAccounts()["local_account_2"].Username), statusReply.Content)
|
||||
assert.Equal(suite.T(), fmt.Sprintf("hello @%s this reply should work!", testrig.NewTestAccounts()["local_account_2"].Username), statusReply.Content)
|
||||
assert.False(suite.T(), statusReply.Sensitive)
|
||||
assert.Equal(suite.T(), mastomodel.VisibilityPublic, statusReply.Visibility)
|
||||
assert.Equal(suite.T(), testrig.TestStatuses()["local_account_2_status_1"].ID, statusReply.InReplyToID)
|
||||
assert.Equal(suite.T(), testrig.TestAccounts()["local_account_2"].ID, statusReply.InReplyToAccountID)
|
||||
assert.Equal(suite.T(), testrig.NewTestStatuses()["local_account_2_status_1"].ID, statusReply.InReplyToID)
|
||||
assert.Equal(suite.T(), testrig.NewTestAccounts()["local_account_2"].ID, statusReply.InReplyToAccountID)
|
||||
assert.Len(suite.T(), statusReply.Mentions, 1)
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ func FromFile(path string) (*Config, error) {
|
||||
return Empty(), nil
|
||||
}
|
||||
|
||||
// Empty just returns an empty config
|
||||
// Empty just returns a new empty config
|
||||
func Empty() *Config {
|
||||
return &Config{
|
||||
DBConfig: &DBConfig{},
|
||||
@ -63,6 +63,8 @@ func Empty() *Config {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// loadFromFile takes a path to a yaml file and attempts to load a Config object from it
|
||||
func loadFromFile(path string) (*Config, error) {
|
||||
bytes, err := os.ReadFile(path)
|
||||
@ -142,8 +144,8 @@ func (c *Config) ParseCLIFlags(f KeyedFlags) {
|
||||
c.AccountsConfig.OpenRegistration = f.Bool(fn.AccountsOpenRegistration)
|
||||
}
|
||||
|
||||
if f.IsSet(fn.AccountsRequireApproval) {
|
||||
c.AccountsConfig.RequireApproval = f.Bool(fn.AccountsRequireApproval)
|
||||
if f.IsSet(fn.AccountsApprovalRequired) {
|
||||
c.AccountsConfig.RequireApproval = f.Bool(fn.AccountsApprovalRequired)
|
||||
}
|
||||
|
||||
// media flags
|
||||
@ -230,7 +232,8 @@ type Flags struct {
|
||||
TemplateBaseDir string
|
||||
|
||||
AccountsOpenRegistration string
|
||||
AccountsRequireApproval string
|
||||
AccountsApprovalRequired string
|
||||
AccountsReasonRequired string
|
||||
|
||||
MediaMaxImageSize string
|
||||
MediaMaxVideoSize string
|
||||
@ -250,6 +253,44 @@ type Flags struct {
|
||||
StatusesMaxMediaFiles string
|
||||
}
|
||||
|
||||
type Defaults struct {
|
||||
LogLevel string
|
||||
ApplicationName string
|
||||
ConfigPath string
|
||||
Host string
|
||||
Protocol string
|
||||
|
||||
DbType string
|
||||
DbAddress string
|
||||
DbPort int
|
||||
DbUser string
|
||||
DbPassword string
|
||||
DbDatabase string
|
||||
|
||||
TemplateBaseDir string
|
||||
|
||||
AccountsOpenRegistration bool
|
||||
AccountsRequireApproval bool
|
||||
AccountsReasonRequired bool
|
||||
|
||||
MediaMaxImageSize int
|
||||
MediaMaxVideoSize int
|
||||
MediaMinDescriptionChars int
|
||||
MediaMaxDescriptionChars int
|
||||
|
||||
StorageBackend string
|
||||
StorageBasePath string
|
||||
StorageServeProtocol string
|
||||
StorageServeHost string
|
||||
StorageServeBasePath string
|
||||
|
||||
StatusesMaxChars int
|
||||
StatusesCWMaxChars int
|
||||
StatusesPollMaxOptions int
|
||||
StatusesPollOptionMaxChars int
|
||||
StatusesMaxMediaFiles int
|
||||
}
|
||||
|
||||
// GetFlagNames returns a struct containing the names of the various flags used for
|
||||
// initializing and storing urfavecli flag variables.
|
||||
func GetFlagNames() Flags {
|
||||
@ -270,7 +311,8 @@ func GetFlagNames() Flags {
|
||||
TemplateBaseDir: "template-basedir",
|
||||
|
||||
AccountsOpenRegistration: "accounts-open-registration",
|
||||
AccountsRequireApproval: "accounts-require-approval",
|
||||
AccountsApprovalRequired: "accounts-approval-required",
|
||||
AccountsReasonRequired: "accounts-reason-required",
|
||||
|
||||
MediaMaxImageSize: "media-max-image-size",
|
||||
MediaMaxVideoSize: "media-max-video-size",
|
||||
@ -311,7 +353,8 @@ func GetEnvNames() Flags {
|
||||
TemplateBaseDir: "GTS_TEMPLATE_BASEDIR",
|
||||
|
||||
AccountsOpenRegistration: "GTS_ACCOUNTS_OPEN_REGISTRATION",
|
||||
AccountsRequireApproval: "GTS_ACCOUNTS_REQUIRE_APPROVAL",
|
||||
AccountsApprovalRequired: "GTS_ACCOUNTS_APPROVAL_REQUIRED",
|
||||
AccountsReasonRequired: "GTS_ACCOUNTS_REASON_REQUIRED",
|
||||
|
||||
MediaMaxImageSize: "GTS_MEDIA_MAX_IMAGE_SIZE",
|
||||
MediaMaxVideoSize: "GTS_MEDIA_MAX_VIDEO_SIZE",
|
||||
|
||||
177
internal/config/default.go
Normal file
177
internal/config/default.go
Normal file
@ -0,0 +1,177 @@
|
||||
package config
|
||||
|
||||
// TestDefault returns a default config for testing
|
||||
func TestDefault() *Config {
|
||||
defaults := GetTestDefaults()
|
||||
return &Config{
|
||||
LogLevel: defaults.LogLevel,
|
||||
ApplicationName: defaults.ApplicationName,
|
||||
Host: defaults.Host,
|
||||
Protocol: defaults.Protocol,
|
||||
DBConfig: &DBConfig{
|
||||
Type: defaults.DbType,
|
||||
Address: defaults.DbAddress,
|
||||
Port: defaults.DbPort,
|
||||
User: defaults.DbUser,
|
||||
Password: defaults.DbPassword,
|
||||
Database: defaults.DbDatabase,
|
||||
ApplicationName: defaults.ApplicationName,
|
||||
},
|
||||
TemplateConfig: &TemplateConfig{
|
||||
BaseDir: defaults.TemplateBaseDir,
|
||||
},
|
||||
AccountsConfig: &AccountsConfig{
|
||||
OpenRegistration: defaults.AccountsOpenRegistration,
|
||||
RequireApproval: defaults.AccountsRequireApproval,
|
||||
ReasonRequired: defaults.AccountsReasonRequired,
|
||||
},
|
||||
MediaConfig: &MediaConfig{
|
||||
MaxImageSize: defaults.MediaMaxImageSize,
|
||||
MaxVideoSize: defaults.MediaMaxVideoSize,
|
||||
MinDescriptionChars: defaults.MediaMinDescriptionChars,
|
||||
MaxDescriptionChars: defaults.MediaMaxDescriptionChars,
|
||||
},
|
||||
StorageConfig: &StorageConfig{
|
||||
Backend: defaults.StorageBackend,
|
||||
BasePath: defaults.StorageBasePath,
|
||||
ServeProtocol: defaults.StorageServeProtocol,
|
||||
ServeHost: defaults.StorageServeHost,
|
||||
ServeBasePath: defaults.StorageServeBasePath,
|
||||
},
|
||||
StatusesConfig: &StatusesConfig{
|
||||
MaxChars: defaults.StatusesMaxChars,
|
||||
CWMaxChars: defaults.StatusesCWMaxChars,
|
||||
PollMaxOptions: defaults.StatusesPollMaxOptions,
|
||||
PollOptionMaxChars: defaults.StatusesPollOptionMaxChars,
|
||||
MaxMediaFiles: defaults.StatusesMaxMediaFiles,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Default returns a config with all default values set
|
||||
func Default() *Config {
|
||||
defaults := GetDefaults()
|
||||
return &Config{
|
||||
LogLevel: defaults.LogLevel,
|
||||
ApplicationName: defaults.ApplicationName,
|
||||
Host: defaults.Host,
|
||||
Protocol: defaults.Protocol,
|
||||
DBConfig: &DBConfig{
|
||||
Type: defaults.DbType,
|
||||
Address: defaults.DbAddress,
|
||||
Port: defaults.DbPort,
|
||||
User: defaults.DbUser,
|
||||
Password: defaults.DbPassword,
|
||||
Database: defaults.DbDatabase,
|
||||
ApplicationName: defaults.ApplicationName,
|
||||
},
|
||||
TemplateConfig: &TemplateConfig{
|
||||
BaseDir: defaults.TemplateBaseDir,
|
||||
},
|
||||
AccountsConfig: &AccountsConfig{
|
||||
OpenRegistration: defaults.AccountsOpenRegistration,
|
||||
RequireApproval: defaults.AccountsRequireApproval,
|
||||
ReasonRequired: defaults.AccountsReasonRequired,
|
||||
},
|
||||
MediaConfig: &MediaConfig{
|
||||
MaxImageSize: defaults.MediaMaxImageSize,
|
||||
MaxVideoSize: defaults.MediaMaxVideoSize,
|
||||
MinDescriptionChars: defaults.MediaMinDescriptionChars,
|
||||
MaxDescriptionChars: defaults.MediaMaxDescriptionChars,
|
||||
},
|
||||
StorageConfig: &StorageConfig{
|
||||
Backend: defaults.StorageBackend,
|
||||
BasePath: defaults.StorageBasePath,
|
||||
ServeProtocol: defaults.StorageServeProtocol,
|
||||
ServeHost: defaults.StorageServeHost,
|
||||
ServeBasePath: defaults.StorageServeBasePath,
|
||||
},
|
||||
StatusesConfig: &StatusesConfig{
|
||||
MaxChars: defaults.StatusesMaxChars,
|
||||
CWMaxChars: defaults.StatusesCWMaxChars,
|
||||
PollMaxOptions: defaults.StatusesPollMaxOptions,
|
||||
PollOptionMaxChars: defaults.StatusesPollOptionMaxChars,
|
||||
MaxMediaFiles: defaults.StatusesMaxMediaFiles,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func GetDefaults() Defaults {
|
||||
return Defaults{
|
||||
LogLevel: "info",
|
||||
ApplicationName: "gotosocial",
|
||||
ConfigPath: "",
|
||||
Host: "",
|
||||
Protocol: "https",
|
||||
|
||||
DbType: "postgres",
|
||||
DbAddress: "localhost",
|
||||
DbPort: 5432,
|
||||
DbUser: "postgres",
|
||||
DbPassword: "postgres",
|
||||
DbDatabase: "postgres",
|
||||
|
||||
TemplateBaseDir: "./web/template/",
|
||||
|
||||
AccountsOpenRegistration: true,
|
||||
AccountsRequireApproval: true,
|
||||
AccountsReasonRequired: true,
|
||||
|
||||
MediaMaxImageSize: 1048576, //1mb
|
||||
MediaMaxVideoSize: 5242880, //5mb
|
||||
MediaMinDescriptionChars: 0,
|
||||
MediaMaxDescriptionChars: 500,
|
||||
|
||||
StorageBackend: "local",
|
||||
StorageBasePath: "/gotosocial/storage",
|
||||
StorageServeProtocol: "https",
|
||||
StorageServeHost: "localhost",
|
||||
StorageServeBasePath: "/fileserver",
|
||||
|
||||
StatusesMaxChars: 5000,
|
||||
StatusesCWMaxChars: 100,
|
||||
StatusesPollMaxOptions: 6,
|
||||
StatusesPollOptionMaxChars: 50,
|
||||
StatusesMaxMediaFiles: 6,
|
||||
}
|
||||
}
|
||||
|
||||
func GetTestDefaults() Defaults {
|
||||
return Defaults{
|
||||
LogLevel: "trace",
|
||||
ApplicationName: "gotosocial",
|
||||
ConfigPath: "",
|
||||
Host: "localhost:8080",
|
||||
Protocol: "http",
|
||||
|
||||
DbType: "postgres",
|
||||
DbAddress: "localhost",
|
||||
DbPort: 5432,
|
||||
DbUser: "postgres",
|
||||
DbPassword: "postgres",
|
||||
DbDatabase: "postgres",
|
||||
|
||||
TemplateBaseDir: "./web/template/",
|
||||
|
||||
AccountsOpenRegistration: true,
|
||||
AccountsRequireApproval: true,
|
||||
AccountsReasonRequired: true,
|
||||
|
||||
MediaMaxImageSize: 1048576, //1mb
|
||||
MediaMaxVideoSize: 5242880, //5mb
|
||||
MediaMinDescriptionChars: 0,
|
||||
MediaMaxDescriptionChars: 500,
|
||||
|
||||
StorageBackend: "local",
|
||||
StorageBasePath: "/gotosocial/storage",
|
||||
StorageServeProtocol: "http",
|
||||
StorageServeHost: "localhost:8080",
|
||||
StorageServeBasePath: "/fileserver",
|
||||
|
||||
StatusesMaxChars: 5000,
|
||||
StatusesCWMaxChars: 100,
|
||||
StatusesPollMaxOptions: 6,
|
||||
StatusesPollOptionMaxChars: 50,
|
||||
StatusesMaxMediaFiles: 6,
|
||||
}
|
||||
}
|
||||
@ -139,7 +139,7 @@ func (suite *MediaTestSuite) TearDownTest() {
|
||||
|
||||
func (suite *MediaTestSuite) TestSetHeaderOrAvatarForAccountID() {
|
||||
// load test image
|
||||
f, err := ioutil.ReadFile("./test/test-jpeg.jpg")
|
||||
f, err := ioutil.ReadFile("../../testrig/media/test-jpeg.jpg")
|
||||
assert.Nil(suite.T(), err)
|
||||
|
||||
ma, err := suite.mediaHandler.SetHeaderOrAvatarForAccountID(f, "weeeeeee", "header")
|
||||
|
||||
Reference in New Issue
Block a user