Skip to content

Commit

Permalink
create mlmodel_service in testutils/inject (#2205)
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-mishra authored Apr 12, 2023
1 parent f9ba224 commit de0b51c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions testutils/inject/mlmodel_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package inject

import (
"context"

"go.viam.com/rdk/services/mlmodel"
)

// MLModelService represents a fake instance of a mlmodel service.
type MLModelService struct {
mlmodel.Service
InferFunc func(ctx context.Context, input map[string]interface{}) (map[string]interface{}, error)
MetadataFunc func(ctx context.Context) (mlmodel.MLMetadata, error)
}

// Infer calls the injected InferFunc or the real version.
func (mlmodelSvc *MLModelService) Infer(ctx context.Context, input map[string]interface{}) (map[string]interface{}, error) {
if mlmodelSvc.InferFunc == nil {
return mlmodelSvc.Service.Infer(ctx, input)
}
return mlmodelSvc.InferFunc(ctx, input)
}

// Metadata calls the injected MetadataFunc or the real version.
func (mlmodelSvc *MLModelService) Metadata(ctx context.Context) (mlmodel.MLMetadata, error) {
if mlmodelSvc.MetadataFunc == nil {
return mlmodelSvc.Service.Metadata(ctx)
}
return mlmodelSvc.MetadataFunc(ctx)
}

0 comments on commit de0b51c

Please sign in to comment.