package monitor

import (
	"testing"
	"time"
)

func initQueue() {
	initItem()
}

func TestQueue(t *testing.T) {
	initQueue()

	q, _ := newQueue()

	if i := q.Peek(); i != nil {
		t.Error(i)
	}

	i := &Item{Key: "k"}
	q.Push(i)

	if i := q.Peek(); i.Key != "k" {
		t.Error(i)
	} else if j := q.Pop(); i != j {
		t.Error(j)
	} else if j.Key != "k" {
		t.Error(j)
	}
}

func TestQueuePriority(t *testing.T) {
	initQueue()

	q, _ := newQueue()

	i, _ := NewItem("iQueuePriority", time.Second)
	j, _ := NewItem("jQueuePriority", time.Hour)
	q.Push(i)
	q.Push(j)
	if k := q.Peek(); k.Key != "jQueuePriority" {
		t.Errorf("compare is backwards")
	}

	if q.Len() != 2 {
		t.Error(q.Len())
	}
}
