98 lines
2.1 KiB
Go
98 lines
2.1 KiB
Go
package utils
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestQueue_Pop(t *testing.T) {
|
|
type fields struct {
|
|
elements []Task
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
want Task
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "Pop element of empty list",
|
|
fields: fields{},
|
|
want: Task{},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "Pop element of a filled list with three elements",
|
|
fields: fields{elements: []Task{
|
|
{URIPath: "https://e621.net0....", Methode: "GET", Channel: nil},
|
|
{URIPath: "https://e621.net1....", Methode: "GET", Channel: nil},
|
|
{URIPath: "https://e621.net2....", Methode: "GET", Channel: nil},
|
|
}},
|
|
want: Task{
|
|
URIPath: "https://e621.net0....",
|
|
Methode: "GET",
|
|
Channel: nil,
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
queue := &Queue{
|
|
elements: tt.fields.elements,
|
|
}
|
|
got, err := queue.Pop()
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("Pop() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("Pop() got = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestQueue_Push(t *testing.T) {
|
|
t.Run("Push tasks to empty queue", func(t *testing.T) {
|
|
queue := Queue{elements: []Task{}}
|
|
task := Task{
|
|
URIPath: "http://e621.net0....",
|
|
Methode: "GET",
|
|
Channel: nil,
|
|
}
|
|
err := queue.Push(task)
|
|
if err != nil {
|
|
t.Errorf("Push() error = %v", err)
|
|
}
|
|
if len(queue.elements) != 1 {
|
|
t.Errorf("Push() error = queue is not one")
|
|
}
|
|
if queue.elements[0] != task {
|
|
t.Errorf("Push() error = wrong queue task in queue")
|
|
}
|
|
})
|
|
t.Run("Push tasks to filled queue", func(t *testing.T) {
|
|
queue := Queue{elements: []Task{{
|
|
URIPath: "http://e621.net0....",
|
|
Methode: "GET",
|
|
Channel: nil,
|
|
}}}
|
|
task := Task{
|
|
URIPath: "http://e621.net1....",
|
|
Methode: "GET",
|
|
Channel: nil,
|
|
}
|
|
err := queue.Push(task)
|
|
if err != nil {
|
|
t.Errorf("Push() error = %v", err)
|
|
}
|
|
if len(queue.elements) != 2 {
|
|
t.Errorf("Push() error = queue is not two")
|
|
}
|
|
if queue.elements[1] != task {
|
|
t.Errorf("Push() error = wrong queue task in queue")
|
|
}
|
|
})
|
|
}
|