mirror of
https://github.com/gopasspw/gopass.git
synced 2025-12-08 19:24:54 +00:00
* [chore] Migrate to golangci-lint v2 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issue Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Add more package comments. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix golangci-lint config and the remaining checks Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Use Go 1.24 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix container builds Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix more failing tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix test failure Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix another len assertion Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Move location tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix most remaining lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Only run XDG specific tests on linux Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Attempt to address on source of flaky failures Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> --------- Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
86 lines
1.4 KiB
Go
86 lines
1.4 KiB
Go
package queue
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestQueue_Add(t *testing.T) {
|
|
ctx := t.Context()
|
|
q := New(ctx)
|
|
|
|
task := func(ctx context.Context) (context.Context, error) {
|
|
return ctx, nil
|
|
}
|
|
|
|
q.Add(task)
|
|
|
|
if len(q.work) != 1 {
|
|
t.Errorf("expected 1 task in queue, got %d", len(q.work))
|
|
}
|
|
}
|
|
|
|
func TestQueue_Close(t *testing.T) {
|
|
ctx := t.Context()
|
|
q := New(ctx)
|
|
|
|
task := func(ctx context.Context) (context.Context, error) {
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
return ctx, nil
|
|
}
|
|
|
|
q.Add(task)
|
|
q.Add(task)
|
|
|
|
err := q.Close(ctx)
|
|
if err != nil {
|
|
t.Errorf("expected no error, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestQueue_Idle(t *testing.T) {
|
|
ctx := t.Context()
|
|
q := New(ctx)
|
|
|
|
task := func(ctx context.Context) (context.Context, error) {
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
return ctx, nil
|
|
}
|
|
|
|
q.Add(task)
|
|
|
|
err := q.Idle(200 * time.Millisecond)
|
|
if err != nil {
|
|
t.Errorf("expected no error, got %v", err)
|
|
}
|
|
|
|
q.Add(task)
|
|
|
|
err = q.Idle(50 * time.Millisecond)
|
|
if err == nil {
|
|
t.Errorf("expected timeout error, got nil")
|
|
}
|
|
}
|
|
|
|
func TestWithQueue(t *testing.T) {
|
|
ctx := t.Context()
|
|
q := New(ctx)
|
|
|
|
ctxWithQueue := WithQueue(ctx, q)
|
|
if GetQueue(ctxWithQueue) != q {
|
|
t.Errorf("expected queue to be set in context")
|
|
}
|
|
}
|
|
|
|
func TestGetQueue(t *testing.T) {
|
|
ctx := t.Context()
|
|
|
|
q := GetQueue(ctx)
|
|
if _, ok := q.(*noop); !ok {
|
|
t.Errorf("expected noop queue, got %T", q)
|
|
}
|
|
}
|