github.com/weaviate/weaviate@v1.24.6/modules/qna-openai/ask/param_helper_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 ask 13 14 import ( 15 "reflect" 16 "testing" 17 ) 18 19 func TestParamsHelper_GetQuestion(t *testing.T) { 20 type args struct { 21 params interface{} 22 } 23 tests := []struct { 24 name string 25 args args 26 want string 27 }{ 28 { 29 name: "should get question with certainty", 30 args: args{ 31 params: &AskParams{ 32 Question: "question", 33 Certainty: 0.8, 34 }, 35 }, 36 want: "question", 37 }, 38 { 39 name: "should get question with distance", 40 args: args{ 41 params: &AskParams{ 42 Question: "question", 43 Distance: 0.8, 44 }, 45 }, 46 want: "question", 47 }, 48 { 49 name: "should get empty string when empty params", 50 args: args{ 51 params: &AskParams{}, 52 }, 53 want: "", 54 }, 55 { 56 name: "should get empty string when nil params", 57 args: args{ 58 params: nil, 59 }, 60 want: "", 61 }, 62 { 63 name: "should get empty string when passed a struct, not a pointer to struct", 64 args: args{ 65 params: AskParams{}, 66 }, 67 want: "", 68 }, 69 { 70 name: "should get empty string when passed a struct with question, not a pointer to struct", 71 args: args{ 72 params: AskParams{ 73 Question: "question?", 74 }, 75 }, 76 want: "", 77 }, 78 } 79 for _, tt := range tests { 80 t.Run(tt.name, func(t *testing.T) { 81 p := &ParamsHelper{} 82 if got := p.GetQuestion(tt.args.params); got != tt.want { 83 t.Errorf("ParamsHelper.GetQuestion() = %v, want %v", got, tt.want) 84 } 85 }) 86 } 87 } 88 89 func TestParamsHelper_GetProperties(t *testing.T) { 90 type args struct { 91 params interface{} 92 } 93 tests := []struct { 94 name string 95 p *ParamsHelper 96 args args 97 want []string 98 }{ 99 { 100 name: "should get properties with distance", 101 args: args{ 102 params: &AskParams{ 103 Question: "question", 104 Properties: []string{"prop1", "prop2"}, 105 Distance: 0.8, 106 }, 107 }, 108 want: []string{"prop1", "prop2"}, 109 }, 110 { 111 name: "should get properties with certainty", 112 args: args{ 113 params: &AskParams{ 114 Question: "question", 115 Properties: []string{"prop1", "prop2"}, 116 Certainty: 0.8, 117 }, 118 }, 119 want: []string{"prop1", "prop2"}, 120 }, 121 { 122 name: "should get nil properties with empty pointer to AskParams", 123 args: args{ 124 params: &AskParams{}, 125 }, 126 want: nil, 127 }, 128 { 129 name: "should get nil properties with empty AskParams", 130 args: args{ 131 params: AskParams{}, 132 }, 133 want: nil, 134 }, 135 { 136 name: "should get nil properties with nil params", 137 args: args{ 138 params: nil, 139 }, 140 want: nil, 141 }, 142 } 143 for _, tt := range tests { 144 t.Run(tt.name, func(t *testing.T) { 145 p := &ParamsHelper{} 146 if got := p.GetProperties(tt.args.params); !reflect.DeepEqual(got, tt.want) { 147 t.Errorf("ParamsHelper.GetProperties() = %v, want %v", got, tt.want) 148 } 149 }) 150 } 151 }