54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
![]() |
package controller
|
||
|
|
||
|
import (
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"penahub.gitlab.yandexcloud.net/backend/templategen_feedback/internal/models"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestFeedbackQueue_Enqueue(t *testing.T) {
|
||
|
args := models.NewFeedback("host", "contact", "whoami")
|
||
|
|
||
|
queue := NewFeedbackQueue()
|
||
|
got := queue.Enqueue(args)
|
||
|
|
||
|
assert.True(t, got)
|
||
|
}
|
||
|
|
||
|
func TestFeedbackQueue_EnqueueFilled(t *testing.T) {
|
||
|
args := models.NewFeedback("host", "contact", "whoami")
|
||
|
|
||
|
queue := NewFeedbackQueue()
|
||
|
for i := 0; i <= QueueSize-1; i++ {
|
||
|
queue.Enqueue(args)
|
||
|
}
|
||
|
|
||
|
got := queue.Enqueue(args)
|
||
|
|
||
|
assert.False(t, got)
|
||
|
}
|
||
|
|
||
|
func TestFeedbackQueue_Dequeue(t *testing.T) {
|
||
|
args := models.NewFeedback("host", "contact", "whoami")
|
||
|
want := args
|
||
|
|
||
|
queue := NewFeedbackQueue()
|
||
|
|
||
|
if assert.True(t, queue.Enqueue(args)) {
|
||
|
got := queue.Dequeue()
|
||
|
assert.Equal(t, want, got)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestFeedbackQueue_Len(t *testing.T) {
|
||
|
args := models.NewFeedback("host", "contact", "whoami")
|
||
|
want := 1
|
||
|
|
||
|
queue := NewFeedbackQueue()
|
||
|
if assert.True(t, queue.Enqueue(args)) {
|
||
|
got := queue.Len()
|
||
|
assert.Equal(t, want, got)
|
||
|
}
|
||
|
|
||
|
}
|