2022-06-07 10:20:06 -05:00
|
|
|
package schedule
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-02-14 12:01:32 -06:00
|
|
|
models "github.com/grafana/grafana/pkg/services/ngalert/models"
|
2022-06-07 10:20:06 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHashUIDs(t *testing.T) {
|
2022-07-26 08:40:06 -05:00
|
|
|
r := []*models.AlertRule{{UID: "foo"}, {UID: "bar"}}
|
2022-06-07 10:20:06 -05:00
|
|
|
assert.Equal(t, uint64(0xade76f55c76a1c48), hashUIDs(r))
|
|
|
|
// expect the same hash irrespective of order
|
2022-07-26 08:40:06 -05:00
|
|
|
r = []*models.AlertRule{{UID: "bar"}, {UID: "foo"}}
|
2022-06-07 10:20:06 -05:00
|
|
|
assert.Equal(t, uint64(0xade76f55c76a1c48), hashUIDs(r))
|
|
|
|
// expect a different hash
|
2022-07-26 08:40:06 -05:00
|
|
|
r = []*models.AlertRule{{UID: "bar"}}
|
2022-06-07 10:20:06 -05:00
|
|
|
assert.Equal(t, uint64(0xd8d9a5186bad3880), hashUIDs(r))
|
|
|
|
// slice with no items
|
2022-07-26 08:40:06 -05:00
|
|
|
r = []*models.AlertRule{}
|
2022-06-07 10:20:06 -05:00
|
|
|
assert.Equal(t, uint64(0xcbf29ce484222325), hashUIDs(r))
|
|
|
|
// a different slice with no items should have the same hash
|
2022-07-26 08:40:06 -05:00
|
|
|
r = []*models.AlertRule{}
|
2022-06-07 10:20:06 -05:00
|
|
|
assert.Equal(t, uint64(0xcbf29ce484222325), hashUIDs(r))
|
|
|
|
}
|