github.com/weaviate/weaviate@v1.24.6/usecases/modules/fakes_for_test.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package modules
    13  
    14  import (
    15  	"context"
    16  	"net/http"
    17  
    18  	"github.com/go-openapi/strfmt"
    19  	"github.com/stretchr/testify/mock"
    20  	"github.com/weaviate/weaviate/entities/additional"
    21  	"github.com/weaviate/weaviate/entities/models"
    22  	"github.com/weaviate/weaviate/entities/modulecapabilities"
    23  	"github.com/weaviate/weaviate/entities/moduletools"
    24  	"github.com/weaviate/weaviate/entities/schema"
    25  	"github.com/weaviate/weaviate/entities/search"
    26  )
    27  
    28  func newDummyModule(name string, t modulecapabilities.ModuleType) modulecapabilities.Module {
    29  	switch t {
    30  	case modulecapabilities.Text2Vec:
    31  		return newDummyText2VecModule(name)
    32  	case modulecapabilities.Ref2Vec:
    33  		return newDummyRef2VecModule(name)
    34  	default:
    35  		return newDummyNonVectorizerModule(name)
    36  	}
    37  }
    38  
    39  func newDummyText2VecModule(name string) dummyText2VecModuleNoCapabilities {
    40  	return dummyText2VecModuleNoCapabilities{name: name}
    41  }
    42  
    43  type dummyText2VecModuleNoCapabilities struct {
    44  	name string
    45  }
    46  
    47  func (m dummyText2VecModuleNoCapabilities) Name() string {
    48  	return m.name
    49  }
    50  
    51  func (m dummyText2VecModuleNoCapabilities) Init(ctx context.Context,
    52  	params moduletools.ModuleInitParams,
    53  ) error {
    54  	return nil
    55  }
    56  
    57  // TODO remove as this is a capability
    58  func (m dummyText2VecModuleNoCapabilities) RootHandler() http.Handler {
    59  	return nil
    60  }
    61  
    62  func (m dummyText2VecModuleNoCapabilities) Type() modulecapabilities.ModuleType {
    63  	return modulecapabilities.Text2Vec
    64  }
    65  
    66  func (m dummyText2VecModuleNoCapabilities) VectorizeObject(ctx context.Context,
    67  	in *models.Object, comp moduletools.VectorizablePropsComparator, cfg moduletools.ClassConfig,
    68  ) ([]float32, models.AdditionalProperties, error) {
    69  	return []float32{1, 2, 3}, nil, nil
    70  }
    71  
    72  func newDummyRef2VecModule(name string) dummyRef2VecModuleNoCapabilities {
    73  	return dummyRef2VecModuleNoCapabilities{name: name}
    74  }
    75  
    76  type dummyRef2VecModuleNoCapabilities struct {
    77  	name string
    78  }
    79  
    80  func (m dummyRef2VecModuleNoCapabilities) Name() string {
    81  	return m.name
    82  }
    83  
    84  func (m dummyRef2VecModuleNoCapabilities) Init(ctx context.Context,
    85  	params moduletools.ModuleInitParams,
    86  ) error {
    87  	return nil
    88  }
    89  
    90  // TODO remove as this is a capability
    91  func (m dummyRef2VecModuleNoCapabilities) RootHandler() http.Handler {
    92  	return nil
    93  }
    94  
    95  func (m dummyRef2VecModuleNoCapabilities) Type() modulecapabilities.ModuleType {
    96  	return modulecapabilities.Ref2Vec
    97  }
    98  
    99  func (m dummyRef2VecModuleNoCapabilities) VectorizeObject(ctx context.Context,
   100  	in *models.Object, cfg moduletools.ClassConfig,
   101  	findRefVecsFn modulecapabilities.FindObjectFn,
   102  ) ([]float32, error) {
   103  	return []float32{1, 2, 3}, nil
   104  }
   105  
   106  func newDummyNonVectorizerModule(name string) dummyNonVectorizerModule {
   107  	return dummyNonVectorizerModule{name: name}
   108  }
   109  
   110  type dummyNonVectorizerModule struct {
   111  	name string
   112  }
   113  
   114  func (m dummyNonVectorizerModule) Name() string {
   115  	return m.name
   116  }
   117  
   118  func (m dummyNonVectorizerModule) Init(ctx context.Context,
   119  	params moduletools.ModuleInitParams,
   120  ) error {
   121  	return nil
   122  }
   123  
   124  // TODO remove as this is a capability
   125  func (m dummyNonVectorizerModule) RootHandler() http.Handler {
   126  	return nil
   127  }
   128  
   129  func (m dummyNonVectorizerModule) Type() modulecapabilities.ModuleType {
   130  	var non modulecapabilities.ModuleType = "NonVectorizer"
   131  	return non
   132  }
   133  
   134  type fakeSchemaGetter struct{ schema schema.Schema }
   135  
   136  func (f *fakeSchemaGetter) GetSchemaSkipAuth() schema.Schema {
   137  	return f.schema
   138  }
   139  
   140  type fakeObjectsRepo struct {
   141  	mock.Mock
   142  }
   143  
   144  func (r *fakeObjectsRepo) Object(ctx context.Context, class string,
   145  	id strfmt.UUID, props search.SelectProperties,
   146  	addl additional.Properties, tenant string,
   147  ) (*search.Result, error) {
   148  	args := r.Called(ctx, class, id, props, addl)
   149  	if args.Get(0) == nil {
   150  		return nil, args.Error(1)
   151  	}
   152  	return args.Get(0).(*search.Result), args.Error(1)
   153  }