...

Source file src/github.com/gin-contrib/sessions/mongo/mongodriver/mongodriver_test.go

Documentation: github.com/gin-contrib/sessions/mongo/mongodriver

     1  package mongodriver
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/gin-contrib/sessions"
     9  	"github.com/gin-contrib/sessions/tester"
    10  	"go.mongodb.org/mongo-driver/mongo"
    11  	"go.mongodb.org/mongo-driver/mongo/options"
    12  )
    13  
    14  const mongoTestServer = "mongodb://localhost:27017"
    15  
    16  var newStore = func(_ *testing.T) sessions.Store {
    17  	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
    18  	defer cancel()
    19  	client, err := mongo.NewClient(options.Client().ApplyURI(mongoTestServer))
    20  	if err != nil {
    21  		panic(err)
    22  	}
    23  
    24  	if err := client.Connect(ctx); err != nil {
    25  		panic(err)
    26  	}
    27  
    28  	c := client.Database("test").Collection("sessions")
    29  	return NewStore(c, 3600, true, []byte("secret"))
    30  }
    31  
    32  func TestMongoDriver_SessionGetSet(t *testing.T) {
    33  	tester.GetSet(t, newStore)
    34  }
    35  
    36  func TestMongoDriver_SessionDeleteKey(t *testing.T) {
    37  	tester.DeleteKey(t, newStore)
    38  }
    39  
    40  func TestMongoDriver_SessionFlashes(t *testing.T) {
    41  	tester.Flashes(t, newStore)
    42  }
    43  
    44  func TestMongoDriver_SessionClear(t *testing.T) {
    45  	tester.Clear(t, newStore)
    46  }
    47  
    48  func TestMongoDriver_SessionOptions(t *testing.T) {
    49  	tester.Options(t, newStore)
    50  }
    51  
    52  func TestMongoDriver_SessionMany(t *testing.T) {
    53  	tester.Many(t, newStore)
    54  }
    55  

View as plain text