github.com/decred/politeia@v1.4.0/politeiad/backendv2/tstorebe/plugins/comments/testing.go (about)

     1  // Copyright (c) 2021 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package comments
     6  
     7  import (
     8  	"os"
     9  	"testing"
    10  
    11  	"github.com/decred/politeia/politeiad/plugins/comments"
    12  )
    13  
    14  // newTestCommentsPlugin returns a commentsPlugin that has been setup for
    15  // testing.
    16  func newTestCommentsPlugin(t *testing.T) (*commentsPlugin, func()) {
    17  	// Create plugin data directory
    18  	dataDir, err := os.MkdirTemp("", comments.PluginID)
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  
    23  	// Setup plugin context
    24  	c := commentsPlugin{
    25  		dataDir:          dataDir,
    26  		commentLengthMax: comments.SettingCommentLengthMax,
    27  		voteChangesMax:   comments.SettingVoteChangesMax,
    28  		allowExtraData:   comments.SettingAllowExtraData,
    29  		allowEdits:       comments.SettingAllowEdits,
    30  		editPeriod:       comments.SettingEditPeriod,
    31  	}
    32  
    33  	return &c, func() {
    34  		err = os.RemoveAll(dataDir)
    35  		if err != nil {
    36  			t.Fatal(err)
    37  		}
    38  	}
    39  }