open-nomad/nomad/state/iterator_test.go
hc-github-team-nomad-core 286164288d
backport of commit b6f6541f5024fb847a230ecd612a15f4a4fc05a4 (#18416)
Co-authored-by: James Rasell <jrasell@users.noreply.github.com>
2023-09-07 09:14:56 +01:00

32 lines
693 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package state
import (
"testing"
"github.com/hashicorp/nomad/ci"
"github.com/shoenig/test/must"
)
func TestSliceIterator(t *testing.T) {
ci.Parallel(t)
sliceIterator := NewSliceIterator()
must.NotNil(t, sliceIterator)
// Add something and perform our tests to ensure the expected data is
// returned.
sliceIterator.Add("random-information")
must.Len(t, 1, sliceIterator.data)
must.Zero(t, sliceIterator.idx)
must.Nil(t, sliceIterator.WatchCh())
next1 := sliceIterator.Next()
next2 := sliceIterator.Next()
must.Eq(t, "random-information", next1)
must.Nil(t, next2)
must.Eq(t, 1, sliceIterator.idx)
}