예제 #1
0
func TestJSONSource(t *testing.T) {
	table := New("./data.json")
	expected := []optimus.Row{
		{"header1": "field1", "header2": "field2", "header3": "field3"},
		{"header1": "field4", "header2": "field5", "header3": "field6"},
		{"header1": "field7", "header2": "field8", "header3": "field9"},
	}
	assert.Equal(t, expected, tests.GetRows(table))
	assert.Nil(t, table.Err())
}
예제 #2
0
func TestGearmanSourceFail(t *testing.T) {
	c := &mockClient{Mock: &mock.Mock{}, chans: []chan *packet.Packet{}}
	c.On("Submit", "function", []byte("workload"), mock.Anything, mock.Anything).Return(nil, nil).Once()
	table := New(c, "function", []byte("workload"), func(in []byte) (optimus.Row, error) {
		t.Fatal("never expected converter to be called")
		return nil, nil
	})
	go func() {
		packets := c.chans[0]
		packets <- handlePacket("", packet.WorkWarning, [][]byte{[]byte("1")})
		packets <- handlePacket("", packet.WorkFail, nil)
	}()
	expected := []optimus.Row{}
	assert.Equal(t, expected, tests.GetRows(table))
	assert.EqualError(t, table.Err(), "gearman job 'function' failed with warnings: 1")
}
예제 #3
0
func TestGearmanSource(t *testing.T) {
	c := &mockClient{Mock: &mock.Mock{}, chans: []chan *packet.Packet{}}
	c.On("Submit", "function", []byte("workload"), mock.Anything, mock.Anything).Return(nil, nil).Once()
	numCalls := 0
	table := New(c, "function", []byte("workload"), func(in []byte) (optimus.Row, error) {
		numCalls++
		assert.Equal(t, in, []byte(fmt.Sprintf("%d", numCalls)))
		return optimus.Row{"field1": fmt.Sprintf("value%d", numCalls)}, nil
	})
	expected := []optimus.Row{
		{"field1": "value1"},
		{"field1": "value2"},
	}
	go func() {
		packets := c.chans[0]
		packets <- handlePacket("", packet.WorkData, [][]byte{[]byte("1")})
		packets <- handlePacket("", packet.WorkData, [][]byte{[]byte("2")})
		packets <- handlePacket("", packet.WorkComplete, nil)
	}()
	assert.Equal(t, expected, tests.GetRows(table))
	assert.Nil(t, table.Err())
}