| 827 | } |
| 828 | |
| 829 | func TestChannelRecord(t *testing.T, s Server) { |
| 830 | key := ari.NewKey(ari.ChannelKey, "c1") |
| 831 | |
| 832 | runTest("ok", t, s, func(t *testing.T, m *mock, cl ari.Client) { |
| 833 | var opts *ari.RecordingOptions |
| 834 | |
| 835 | lrkey := ari.NewKey(ari.LiveRecordingKey, "lrh1") |
| 836 | expected := ari.NewLiveRecordingHandle(lrkey, m.LiveRecording, nil) |
| 837 | |
| 838 | m.Channel.On("Record", key, "recordid", opts).Return(expected, nil) |
| 839 | |
| 840 | h, err := cl.Channel().Record(key, "recordid", nil) |
| 841 | if err != nil { |
| 842 | t.Errorf("Unexpected error in remote Record call: %s", err) |
| 843 | } |
| 844 | if h == nil { |
| 845 | t.Error("Expected non-nil handle") |
| 846 | } else if h.ID() != "recordid" { |
| 847 | t.Errorf("Expected handle id '%s', got '%s'", "recordid", h.ID()) |
| 848 | } |
| 849 | |
| 850 | m.Shutdown() |
| 851 | |
| 852 | m.Channel.AssertCalled(t, "Record", key, "recordid", opts) |
| 853 | }) |
| 854 | |
| 855 | runTest("no-id", t, s, func(t *testing.T, m *mock, cl ari.Client) { |
| 856 | var opts *ari.RecordingOptions |
| 857 | |
| 858 | lrkey := ari.NewKey(ari.LiveRecordingKey, "lrh1") |
| 859 | expected := ari.NewLiveRecordingHandle(lrkey, m.LiveRecording, nil) |
| 860 | |
| 861 | m.Channel.On("Record", key, nonEmpty, opts).Return(expected, nil) |
| 862 | |
| 863 | h, err := cl.Channel().Record(key, "", nil) |
| 864 | if err != nil { |
| 865 | t.Errorf("Unexpected error in remote Record call: %s", err) |
| 866 | } |
| 867 | if h == nil { |
| 868 | t.Error("Expected non-nil handle") |
| 869 | } |
| 870 | |
| 871 | m.Shutdown() |
| 872 | |
| 873 | m.Channel.AssertCalled(t, "Record", key, nonEmpty, opts) |
| 874 | }) |
| 875 | |
| 876 | runTest("err", t, s, func(t *testing.T, m *mock, cl ari.Client) { |
| 877 | var opts *ari.RecordingOptions |
| 878 | |
| 879 | m.Channel.On("Record", key, "recordid", opts).Return(nil, errors.New("error")) |
| 880 | |
| 881 | h, err := cl.Channel().Record(key, "recordid", nil) |
| 882 | if err == nil { |
| 883 | t.Errorf("Expected error in remote Record call") |
| 884 | } |
| 885 | if h != nil { |
| 886 | t.Error("Expected nil handle") |