github.com/m3db/m3@v1.5.0/src/m3ninx/search/executor/executor_test.go (about)

     1  // Copyright (c) 2018 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package executor
    22  
    23  import (
    24  	"testing"
    25  
    26  	"github.com/m3db/m3/src/m3ninx/doc"
    27  	"github.com/m3db/m3/src/m3ninx/index"
    28  	"github.com/m3db/m3/src/m3ninx/search"
    29  	"github.com/m3db/m3/src/x/context"
    30  
    31  	"github.com/golang/mock/gomock"
    32  	"github.com/stretchr/testify/require"
    33  )
    34  
    35  type testIterator struct{}
    36  
    37  func newTestIterator() testIterator { return testIterator{} }
    38  
    39  func (it testIterator) Done() bool            { return true }
    40  func (it testIterator) Next() bool            { return false }
    41  func (it testIterator) Current() doc.Document { return doc.Document{} }
    42  func (it testIterator) Err() error            { return nil }
    43  func (it testIterator) Close() error          { return nil }
    44  
    45  func TestExecutor(t *testing.T) {
    46  	mockCtrl := gomock.NewController(t)
    47  	defer mockCtrl.Finish()
    48  
    49  	var (
    50  		q  = search.NewMockQuery(mockCtrl)
    51  		r  = index.NewMockReader(mockCtrl)
    52  		rs = index.Readers{r}
    53  	)
    54  	r.EXPECT().Close().Return(nil)
    55  
    56  	e := NewExecutor(rs).(*executor)
    57  
    58  	// Override newIteratorFn to return test iterator.
    59  	e.newIteratorFn = func(_ context.Context, _ search.Query, _ index.Readers) (doc.QueryDocIterator, error) {
    60  		return newTestIterator(), nil
    61  	}
    62  
    63  	it, err := e.Execute(context.NewBackground(), q)
    64  	require.NoError(t, err)
    65  
    66  	err = it.Close()
    67  	require.NoError(t, err)
    68  
    69  	err = e.Close()
    70  	require.NoError(t, err)
    71  }