| 8 | ) |
| 9 | |
| 10 | func TestLoggingList(t *testing.T, s Server) { |
| 11 | runTest("ok", t, s, func(t *testing.T, m *mock, cl ari.Client) { |
| 12 | expected := []*ari.Key{ |
| 13 | ari.NewKey(ari.LoggingKey, "n1"), |
| 14 | } |
| 15 | |
| 16 | m.Logging.On("List", (*ari.Key)(nil)).Return(expected, nil) |
| 17 | |
| 18 | ld, err := cl.Asterisk().Logging().List(nil) |
| 19 | if err != nil { |
| 20 | t.Errorf("Unexpected error in logging list: %s", err) |
| 21 | } |
| 22 | if len(ld) != len(expected) { |
| 23 | t.Errorf("Expected return of length %d, got %d", len(expected), len(ld)) |
| 24 | } else { |
| 25 | for idx := range ld { |
| 26 | failed := false |
| 27 | failed = failed || ld[idx].ID != expected[idx].ID |
| 28 | |
| 29 | if failed { |
| 30 | t.Errorf("Expected item '%d' to be '%v', got '%v", |
| 31 | idx, expected[idx], ld[idx]) |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | m.Logging.AssertCalled(t, "List", (*ari.Key)(nil)) |
| 37 | }) |
| 38 | |
| 39 | runTest("err", t, s, func(t *testing.T, m *mock, cl ari.Client) { |
| 40 | var expected []*ari.Key |
| 41 | |
| 42 | m.Logging.On("List", (*ari.Key)(nil)).Return(expected, errors.New("error")) |
| 43 | |
| 44 | ld, err := cl.Asterisk().Logging().List(nil) |
| 45 | if err == nil { |
| 46 | t.Errorf("Expected error in logging list") |
| 47 | } |
| 48 | if len(ld) != len(expected) { |
| 49 | t.Errorf("Expected return of length %d, got %d", len(expected), len(ld)) |
| 50 | } else { |
| 51 | for idx := range ld { |
| 52 | failed := false |
| 53 | failed = failed || ld[idx].ID != expected[idx].ID // nolint |
| 54 | |
| 55 | if failed { |
| 56 | t.Errorf("Expected item '%d' to be '%v', got '%v", |
| 57 | idx, expected[idx], ld[idx]) // nolint |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | m.Logging.AssertCalled(t, "List", (*ari.Key)(nil)) |
| 63 | }) |
| 64 | } |
| 65 | |
| 66 | func TestLoggingCreate(t *testing.T, s Server) { |
| 67 | key := ari.NewKey(ari.LoggingKey, "n1") |