add params config, more param tests
This commit is contained in:
+13
-5
@@ -30,7 +30,7 @@ import (
|
||||
type Opts struct {
|
||||
BoltPath string `long:"bolt" env:"BOLTDB_PATH" default:"./var" description:"parent dir for bolt files"`
|
||||
Sites []string `long:"site" env:"SITE" default:"remark" description:"site names" env-delim:","`
|
||||
RemarkURL string `long:"url" env:"REMARK_URL" default:"https://remark42.com" description:"url to remark"`
|
||||
RemarkURL string `long:"url" env:"REMARK_URL" required:"true" description:"url to remark"`
|
||||
Admins []string `long:"admin" env:"ADMIN" description:"admin(s) names" env-delim:","`
|
||||
AdminEmail string `long:"admin-email" env:"ADMIN_EMAIL" default:"" description:"admin email"`
|
||||
DevPasswd string `long:"dev-passwd" env:"DEV_PASSWD" default:"" description:"development mode password"`
|
||||
@@ -111,8 +111,16 @@ func New(opts Opts) (*Application, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(opts.RemarkURL, "http://") && !strings.HasPrefix(opts.RemarkURL, "https://") {
|
||||
return nil, errors.Errorf("invalid remark42 url %s", opts.RemarkURL)
|
||||
}
|
||||
|
||||
boltStore, err := makeBoltStore(opts.Sites, opts.BoltPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dataService := service.DataStore{
|
||||
Interface: makeBoltStore(opts.Sites, opts.BoltPath),
|
||||
Interface: boltStore,
|
||||
EditDuration: 5 * time.Minute,
|
||||
Secret: opts.SecretKey,
|
||||
MaxCommentSize: opts.MaxCommentSize,
|
||||
@@ -213,16 +221,16 @@ func (a *Application) activateBackup(ctx context.Context) {
|
||||
}
|
||||
|
||||
// makeBoltStore creates store for all sites
|
||||
func makeBoltStore(siteNames []string, path string) engine.Interface {
|
||||
func makeBoltStore(siteNames []string, path string) (engine.Interface, error) {
|
||||
sites := []engine.BoltSite{}
|
||||
for _, site := range siteNames {
|
||||
sites = append(sites, engine.BoltSite{SiteID: site, FileName: fmt.Sprintf("%s/%s.db", path, site)})
|
||||
}
|
||||
result, err := engine.NewBoltDB(bolt.Options{Timeout: 30 * time.Second}, sites...)
|
||||
if err != nil {
|
||||
log.Fatalf("[ERROR] can't initialize data store, %+v", err)
|
||||
return nil, errors.Wrap(err, "can't initialize data store")
|
||||
}
|
||||
return result
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// mkdir -p for all dirs
|
||||
|
||||
+21
-1
@@ -44,6 +44,24 @@ func TestApplication(t *testing.T) {
|
||||
app.Wait()
|
||||
}
|
||||
|
||||
func TestApplicationFailed(t *testing.T) {
|
||||
opts := Opts{}
|
||||
p := flags.NewParser(&opts, flags.Default)
|
||||
|
||||
// RO bolt location
|
||||
p.ParseArgs([]string{"--secret=123456", "--url=https://demo.remark42.com", "--bolt=/dev/null"})
|
||||
_, err := New(opts)
|
||||
assert.EqualError(t, err, "can't initialize data store: failed to make boltdb for /dev/null/remark.db: "+
|
||||
"open /dev/null/remark.db: not a directory")
|
||||
t.Log(err)
|
||||
|
||||
//p.ParseArgs([]string{"--secret=123456", "--url=https://demo.remark42.com", "--bolt=/tmp", "--backup=/not-writable"})
|
||||
//_, err = New(opts)
|
||||
//assert.EqualError(t, err, "can't initialize data store: failed to make boltdb for /dev/null/remark.db: "+
|
||||
// "open /dev/null/remark.db: not a directory")
|
||||
//t.Log(err)
|
||||
}
|
||||
|
||||
func TestApplicationShutdown(t *testing.T) {
|
||||
app, ctx := prepApp(t, 18090, 500*time.Millisecond)
|
||||
st := time.Now()
|
||||
@@ -53,7 +71,9 @@ func TestApplicationShutdown(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestApplicationMainSignal(t *testing.T) {
|
||||
os.Args = []string{"test", "--secret=123456", "--bolt=/tmp/xyz", "--backup=/tmp", "--avatars=/tmp", "--port=18100"}
|
||||
os.Args = []string{"test", "--secret=123456", "--bolt=/tmp/xyz", "--backup=/tmp", "--avatars=/tmp",
|
||||
"--port=18100", "--url=https://demo.remark42.com"}
|
||||
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
|
||||
|
||||
Reference in New Issue
Block a user