github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/session/session_test.go (about)

     1  // Copyright 2022 zGraph Authors. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package session_test
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/assert"
    21  	"github.com/vescale/zgraph"
    22  	"github.com/vescale/zgraph/session"
    23  )
    24  
    25  func TestNew(t *testing.T) {
    26  	assert := assert.New(t)
    27  	db, err := zgraph.Open(t.TempDir(), nil)
    28  	assert.Nil(err)
    29  	assert.NotNil(db)
    30  
    31  	s := session.New(db.Store(), db.Catalog())
    32  	assert.NotNil(s)
    33  }
    34  
    35  func TestSession_OnClosed(t *testing.T) {
    36  	assert := assert.New(t)
    37  	db, err := zgraph.Open(t.TempDir(), nil)
    38  	assert.Nil(err)
    39  	assert.NotNil(db)
    40  
    41  	s := session.New(db.Store(), db.Catalog())
    42  	assert.NotNil(s)
    43  
    44  	var closed bool
    45  	s.OnClosed(func(session *session.Session) {
    46  		closed = true
    47  	})
    48  
    49  	s.Close()
    50  	assert.True(closed)
    51  }