github.com/weaviate/weaviate@v1.24.6/usecases/modulecomponents/arguments/nearImage/graphql_extract_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 nearImage
    13  
    14  import (
    15  	"reflect"
    16  	"testing"
    17  )
    18  
    19  func Test_extractNearImageFn(t *testing.T) {
    20  	type args struct {
    21  		source map[string]interface{}
    22  	}
    23  	tests := []struct {
    24  		name string
    25  		args args
    26  		want interface{}
    27  	}{
    28  		{
    29  			name: "should extract properly with image and certainty set",
    30  			args: args{
    31  				source: map[string]interface{}{
    32  					"image":     "base64;encoded",
    33  					"certainty": float64(0.9),
    34  				},
    35  			},
    36  			want: &NearImageParams{
    37  				Image:     "base64;encoded",
    38  				Certainty: 0.9,
    39  			},
    40  		},
    41  		{
    42  			name: "should extract properly with only image set",
    43  			args: args{
    44  				source: map[string]interface{}{
    45  					"image": "base64;encoded",
    46  				},
    47  			},
    48  			want: &NearImageParams{
    49  				Image: "base64;encoded",
    50  			},
    51  		},
    52  		{
    53  			name: "should extract properly with image and distance set",
    54  			args: args{
    55  				source: map[string]interface{}{
    56  					"image":    "base64;encoded",
    57  					"distance": 0.4,
    58  				},
    59  			},
    60  			want: &NearImageParams{
    61  				Image:        "base64;encoded",
    62  				Distance:     0.4,
    63  				WithDistance: true,
    64  			},
    65  		},
    66  		{
    67  			name: "should extract properly with image and certainty set and targetVectors set",
    68  			args: args{
    69  				source: map[string]interface{}{
    70  					"image":         "base64;encoded",
    71  					"certainty":     float64(0.9),
    72  					"targetVectors": []interface{}{"targetVector1"},
    73  				},
    74  			},
    75  			want: &NearImageParams{
    76  				Image:         "base64;encoded",
    77  				Certainty:     0.9,
    78  				TargetVectors: []string{"targetVector1"},
    79  			},
    80  		},
    81  	}
    82  	for _, tt := range tests {
    83  		t.Run(tt.name, func(t *testing.T) {
    84  			if got := extractNearImageFn(tt.args.source); !reflect.DeepEqual(got, tt.want) {
    85  				t.Errorf("extractNearImageFn() = %+v, want %+v", got, tt.want)
    86  			}
    87  		})
    88  	}
    89  }