| 12 | var _ = tmock.Anything |
| 13 | |
| 14 | func TestConfigData(t *testing.T, s Server) { |
| 15 | key := ari.NewKey("config", ari.ConfigID("c1", "o1", "id1")) |
| 16 | |
| 17 | runTest("ok", t, s, func(t *testing.T, m *mock, cl ari.Client) { |
| 18 | var expected ari.ConfigData |
| 19 | expected.Class = "c1" |
| 20 | expected.Key = key |
| 21 | expected.Type = "o1" |
| 22 | expected.Fields = []ari.ConfigTuple{ |
| 23 | ari.ConfigTuple{ |
| 24 | Value: "v1", |
| 25 | Attribute: "a1", |
| 26 | }, |
| 27 | } |
| 28 | |
| 29 | cfg := arimocks.Config{} |
| 30 | m.Asterisk.On("Config").Return(&cfg) |
| 31 | cfg.On("Data", key).Return(&expected, nil) |
| 32 | |
| 33 | data, err := cl.Asterisk().Config().Data(key) |
| 34 | if err != nil { |
| 35 | t.Errorf("Unexpected error in remove config data call: %s", err) |
| 36 | } |
| 37 | if data == nil { |
| 38 | t.Errorf("Expected non-nil data") |
| 39 | } else { |
| 40 | failed := false |
| 41 | failed = failed || data.Class != expected.Class |
| 42 | failed = failed || data.ID() != expected.ID() |
| 43 | failed = failed || data.Type != expected.Type |
| 44 | failed = failed || len(data.Fields) != len(expected.Fields) |
| 45 | for idx := range data.Fields { |
| 46 | failed = failed || data.Fields[idx].Attribute != expected.Fields[idx].Attribute |
| 47 | failed = failed || data.Fields[idx].Value != expected.Fields[idx].Value |
| 48 | } |
| 49 | if failed { |
| 50 | t.Errorf("Expected config data '%v', got '%v'", expected, data) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | m.Asterisk.AssertCalled(t, "Config") |
| 55 | cfg.AssertCalled(t, "Data", key) |
| 56 | }) |
| 57 | |
| 58 | runTest("err", t, s, func(t *testing.T, m *mock, cl ari.Client) { |
| 59 | cfg := arimocks.Config{} |
| 60 | m.Asterisk.On("Config").Return(&cfg) |
| 61 | cfg.On("Data", key).Return(nil, errors.New("error")) |
| 62 | |
| 63 | data, err := cl.Asterisk().Config().Data(key) |
| 64 | if err == nil { |
| 65 | t.Errorf("Expected error in remove config data call") |
| 66 | } |
| 67 | if data != nil { |
| 68 | t.Errorf("Expected nil data") |
| 69 | } |
| 70 | |
| 71 | m.Asterisk.AssertCalled(t, "Config") |