TestUpdateRedis tests a message insertion into cache
(t *testing.T)
| 15 | |
| 16 | // TestUpdateRedis tests a message insertion into cache |
| 17 | func TestUpdateRedis(t *testing.T) { |
| 18 | s, err := miniredis.Run() |
| 19 | if err != nil { |
| 20 | t.Fatalf("miniredis connection: %s", err) |
| 21 | } |
| 22 | defer s.Close() |
| 23 | |
| 24 | c := redis.NewClient(&redis.Options{Addr: s.Addr()}) |
| 25 | |
| 26 | now := time.Now().UnixMilli() |
| 27 | var tests = []struct { |
| 28 | message string |
| 29 | source string |
| 30 | time int64 |
| 31 | }{ |
| 32 | {"Hello", "back", now}, |
| 33 | {"Another test!", "back", now}, |
| 34 | {"1", "front", now}, |
| 35 | {" ", "back", now - 60*60*1000}, |
| 36 | } |
| 37 | for _, test := range tests { |
| 38 | d := testArguments(t, test.message, test.source, test.time) |
| 39 | updateRedis(*d, c) |
| 40 | } |
| 41 | |
| 42 | if got, err := s.Get("total"); err != nil || got != strconv.Itoa(len(tests)) { |
| 43 | t.Error("'total' has the wrong value") |
| 44 | } |
| 45 | |
| 46 | list, err := s.List("messages") |
| 47 | if err != nil { |
| 48 | t.Errorf("list 'messages': %s", err) |
| 49 | } |
| 50 | |
| 51 | if len(list) != len(tests) { |
| 52 | t.Error("'messages' has wrong length") |
| 53 | } |
| 54 | |
| 55 | // TODO: compare each message |
| 56 | } |
| 57 | |
| 58 | // testArguments produces arguments for the function being tested |
| 59 | func testArguments(t *testing.T, message, source string, time int64) *amqp.Delivery { |
nothing calls this directly
no test coverage detected