github.com/jxgolibs/go-oauth2-server@v1.0.1/session/suite_test.go (about)

     1  package session_test
     2  
     3  import (
     4  	"net/http"
     5  	"net/http/httptest"
     6  	"testing"
     7  
     8  	"github.com/RichardKnop/go-oauth2-server/config"
     9  	"github.com/RichardKnop/go-oauth2-server/session"
    10  	"github.com/gorilla/sessions"
    11  	"github.com/stretchr/testify/assert"
    12  	"github.com/stretchr/testify/suite"
    13  )
    14  
    15  // SessionTestSuite needs to be exported so the tests run
    16  type SessionTestSuite struct {
    17  	suite.Suite
    18  	cnf     *config.Config
    19  	service *session.Service
    20  }
    21  
    22  // The SetupSuite method will be run by testify once, at the very
    23  // start of the testing suite, before any tests are run.
    24  func (suite *SessionTestSuite) SetupSuite() {
    25  	suite.cnf = config.NewConfig(false, false, "etcd")
    26  
    27  	// Overwrite internal vars so we don't affect existing session
    28  	session.StorageSessionName = "test_session"
    29  	session.UserSessionKey = "test_user"
    30  
    31  	// Initialise the service
    32  	r, err := http.NewRequest("GET", "http://1.2.3.4/foo/bar", nil)
    33  	assert.NoError(suite.T(), err, "Request setup should not get an error")
    34  	w := httptest.NewRecorder()
    35  
    36  	suite.service = session.NewService(suite.cnf, sessions.NewCookieStore([]byte(suite.cnf.Session.Secret)))
    37  	suite.service.SetSessionService(r, w)
    38  }
    39  
    40  // The TearDownSuite method will be run by testify once, at the very
    41  // end of the testing suite, after all tests have been run.
    42  func (suite *SessionTestSuite) TearDownSuite() {
    43  	//
    44  }
    45  
    46  // The SetupTest method will be run before every test in the suite.
    47  func (suite *SessionTestSuite) SetupTest() {
    48  	//
    49  }
    50  
    51  // The TearDownTest method will be run after every test in the suite.
    52  func (suite *SessionTestSuite) TearDownTest() {
    53  	//
    54  }
    55  
    56  // TesSessionTestSuite ...
    57  // In order for 'go test' to run this suite, we need to create
    58  // a normal test function and pass our suite to suite.Run
    59  func TesSessionTestSuite(t *testing.T) {
    60  	suite.Run(t, new(SessionTestSuite))
    61  }