github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/base/bobjectstorage/bobjectstorage_test.go (about)

     1  package bobjectstorage
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  type mock struct {
    10  }
    11  
    12  func (t mock) Test() string {
    13  	return "test"
    14  }
    15  
    16  func TestSet(t *testing.T) {
    17  	mc := mock{}
    18  	Set("key1", "string")
    19  	Set("key2", 1)
    20  	Set("key3", mc)
    21  	Set("key4", &mc)
    22  	assert.Equal(t, Get[string]("key1"), "string")
    23  	assert.Equal(t, Get[int]("key2"), 1)
    24  	assert.Equal(t, Get[mock]("key3"), mock{})
    25  	assert.Equal(t, Get[*mock]("key4"), &mc)
    26  }