Ejemplo n.º 1
0
func TestTranscribeWithIBM(t *testing.T) {
	assert := assert.New(t)
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	// Setup the mock package
	websocket.MOCK().SetController(ctrl)
	mockos.MOCK().SetController(ctrl)
	bufio.MOCK().SetController(ctrl)

	mockWS := new(websocket.Conn)
	mockFile := new(mockos.File)
	mockReader := new(bufio.Reader)

	websocket.DefaultDialer.EXPECT().Dial(gomock.Any(), gomock.Any()).Return(mockWS, nil, nil).Times(1)
	mockWS.EXPECT().WriteJSON(gomock.Any()).MinTimes(1)
	mockos.EXPECT().Open("file.flac").Times(1).Return(mockFile, nil).Times(1)
	bufio.EXPECT().NewReader(mockFile).Return(mockReader).Times(1)
	mockReader.EXPECT().Read(gomock.Any()).Return(0, nil).Times(1)
	mockWS.EXPECT().WriteMessage(websocket.BinaryMessage, gomock.Any()).MinTimes(1)
	mockWS.EXPECT().ReadJSON(gomock.Any()).Do(func(res **IBMResult) {
		(*res).Results = []ibmResultField{
			ibmResultField{},
			ibmResultField{},
		}
	}).Times(1)
	mockWS.EXPECT().Close().Times(1) // could run many times

	_, err := TranscribeWithIBM("file.flac", "", "")
	assert.NoError(err)
}