github.com/weaviate/weaviate@v1.24.6/usecases/modulecomponents/arguments/nearImage/param_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 "testing"
    15  
    16  func Test_validateNearImageFn(t *testing.T) {
    17  	type args struct {
    18  		param interface{}
    19  	}
    20  	tests := []struct {
    21  		name    string
    22  		args    args
    23  		wantErr bool
    24  	}{
    25  		{
    26  			name: "should pass with proper values",
    27  			args: args{
    28  				param: &NearImageParams{
    29  					Image: "base64;enncoded",
    30  				},
    31  			},
    32  		},
    33  		{
    34  			name: "should not pass with empty image",
    35  			args: args{
    36  				param: &NearImageParams{
    37  					Image: "",
    38  				},
    39  			},
    40  			wantErr: true,
    41  		},
    42  		{
    43  			name: "should not pass with nil image",
    44  			args: args{
    45  				param: &NearImageParams{},
    46  			},
    47  			wantErr: true,
    48  		},
    49  		{
    50  			name: "should not pass with struct param, not a pointer to struct",
    51  			args: args{
    52  				param: NearImageParams{
    53  					Image: "image",
    54  				},
    55  			},
    56  			wantErr: true,
    57  		},
    58  		{
    59  			name: "should not pass with distance and certainty set",
    60  			args: args{
    61  				param: &NearImageParams{
    62  					Image:        "image",
    63  					Distance:     0.4,
    64  					WithDistance: true,
    65  					Certainty:    0.7,
    66  				},
    67  			},
    68  			wantErr: true,
    69  		},
    70  		{
    71  			name: "should pass with proper values and target vector",
    72  			args: args{
    73  				param: &NearImageParams{
    74  					Image:         "base64;enncoded",
    75  					TargetVectors: []string{"targetVector"},
    76  				},
    77  			},
    78  		},
    79  		{
    80  			name: "should not pass with more then 1 target vector",
    81  			args: args{
    82  				param: &NearImageParams{
    83  					Image:         "base64;enncoded",
    84  					TargetVectors: []string{"targetVector1", "targetVector2"},
    85  				},
    86  			},
    87  			wantErr: true,
    88  		},
    89  	}
    90  	for _, tt := range tests {
    91  		t.Run(tt.name, func(t *testing.T) {
    92  			if err := ValidateNearImageFn(tt.args.param); (err != nil) != tt.wantErr {
    93  				t.Errorf("ValidateNearImageFn() error = %v, wantErr %v", err, tt.wantErr)
    94  			}
    95  		})
    96  	}
    97  }