Browse Source

clist: add a few basic clist tests (#6727)

pull/6736/head
William Banfield 3 years ago
committed by GitHub
parent
commit
21309ccb7b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 48 additions and 0 deletions
  1. +48
    -0
      internal/libs/clist/clist_test.go

+ 48
- 0
internal/libs/clist/clist_test.go View File

@ -8,6 +8,7 @@ import (
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPanicOnMaxLength(t *testing.T) {
@ -334,3 +335,50 @@ FOR_LOOP2:
t.Fatalf("number of pushed items (%d) not equal to number of seen items (%d)", pushed, seen)
}
}
func TestRemoved(t *testing.T) {
l := New()
el1 := l.PushBack(1)
el2 := l.PushBack(2)
l.Remove(el1)
require.True(t, el1.Removed())
require.False(t, el2.Removed())
}
func TestNextWaitChan(t *testing.T) {
l := New()
el1 := l.PushBack(1)
t.Run("tail element should not have a closed nextWaitChan", func(t *testing.T) {
select {
case <-el1.NextWaitChan():
t.Fatal("nextWaitChan should not have been closed")
default:
}
})
el2 := l.PushBack(2)
t.Run("adding element should close tail nextWaitChan", func(t *testing.T) {
select {
case <-el1.NextWaitChan():
require.NotNil(t, el1.Next())
default:
t.Fatal("nextWaitChan should have been closed")
}
select {
case <-el2.NextWaitChan():
t.Fatal("nextWaitChan should not have been closed")
default:
}
})
t.Run("removing element should close its nextWaitChan", func(t *testing.T) {
l.Remove(el2)
select {
case <-el2.NextWaitChan():
require.Nil(t, el2.Next())
default:
t.Fatal("nextWaitChan should have been closed")
}
})
}

Loading…
Cancel
Save