2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-25 23:32:17 +08:00
asynq/asynq_test.go

43 lines
919 B
Go
Raw Normal View History

2020-01-03 10:13:16 +08:00
// Copyright 2020 Kentaro Hibino. All rights reserved.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.
2019-11-30 12:53:29 +08:00
package asynq
import (
"sort"
"testing"
2019-12-04 13:01:26 +08:00
"github.com/go-redis/redis/v7"
2019-11-30 12:53:29 +08:00
"github.com/google/go-cmp/cmp"
h "github.com/hibiken/asynq/internal/asynqtest"
2019-11-30 12:53:29 +08:00
)
// This file defines test helper functions used by
// other test files.
2020-01-19 02:17:39 +08:00
// redis used for package testing.
const (
redisAddr = "localhost:6379"
redisDB = 14
)
2020-01-01 04:36:46 +08:00
func setup(tb testing.TB) *redis.Client {
tb.Helper()
2019-12-04 13:01:26 +08:00
r := redis.NewClient(&redis.Options{
2020-01-19 02:17:39 +08:00
Addr: redisAddr,
DB: redisDB,
2019-11-30 12:53:29 +08:00
})
2019-12-04 13:01:26 +08:00
// Start each test with a clean slate.
2020-01-01 04:36:46 +08:00
h.FlushDB(tb, r)
2019-12-04 13:01:26 +08:00
return r
}
2019-11-30 12:53:29 +08:00
var sortTaskOpt = cmp.Transformer("SortMsg", func(in []*Task) []*Task {
out := append([]*Task(nil), in...) // Copy input to avoid mutating it
sort.Slice(out, func(i, j int) bool {
return out[i].Type < out[j].Type
})
return out
})