github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/expires/id_key_map_test.go (about)

     1  // Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
     2  
     3  package expires_test
     4  
     5  import (
     6  	"github.com/TeaOSLab/EdgeNode/internal/utils/expires"
     7  	"github.com/iwind/TeaGo/assert"
     8  	"github.com/iwind/TeaGo/logs"
     9  	"testing"
    10  )
    11  
    12  func TestNewIdKeyMap(t *testing.T) {
    13  	var a = assert.NewAssertion(t)
    14  
    15  	var m = expires.NewIdKeyMap()
    16  	m.Add(1, "1")
    17  	m.Add(1, "2")
    18  	m.Add(100, "100")
    19  	logs.PrintAsJSON(m.IdKeys(), t)
    20  	logs.PrintAsJSON(m.KeyIds(), t)
    21  
    22  	{
    23  		k, ok := m.Key(1)
    24  		a.IsTrue(ok)
    25  		a.IsTrue(k == "2")
    26  	}
    27  
    28  	{
    29  		_, ok := m.Key(2)
    30  		a.IsFalse(ok)
    31  	}
    32  
    33  	m.DeleteKey("2")
    34  
    35  	{
    36  		_, ok := m.Key(1)
    37  		a.IsFalse(ok)
    38  	}
    39  
    40  	logs.PrintAsJSON(m.IdKeys(), t)
    41  	logs.PrintAsJSON(m.KeyIds(), t)
    42  
    43  	m.DeleteId(100)
    44  
    45  	logs.PrintAsJSON(m.IdKeys(), t)
    46  	logs.PrintAsJSON(m.KeyIds(), t)
    47  }