github.com/weaviate/weaviate@v1.24.6/modules/qna-openai/ask/grapqhl_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 ask 13 14 import ( 15 "reflect" 16 "testing" 17 ) 18 19 func Test_extractAskFn(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 parse properly with only question", 30 args: args{ 31 source: map[string]interface{}{ 32 "question": "some question", 33 }, 34 }, 35 want: &AskParams{ 36 Question: "some question", 37 }, 38 }, 39 { 40 name: "should parse properly without params", 41 args: args{ 42 source: map[string]interface{}{}, 43 }, 44 want: &AskParams{}, 45 }, 46 { 47 name: "should parse properly with question, and properties", 48 args: args{ 49 source: map[string]interface{}{ 50 "question": "some question", 51 "properties": []interface{}{"prop1", "prop2"}, 52 }, 53 }, 54 want: &AskParams{ 55 Question: "some question", 56 Properties: []string{"prop1", "prop2"}, 57 }, 58 }, 59 } 60 t.Run("should extract without text transformer", func(t *testing.T) { 61 provider := New(nil) 62 for _, tt := range tests { 63 t.Run(tt.name, func(t *testing.T) { 64 if got := provider.extractAskFn(tt.args.source); !reflect.DeepEqual(got, tt.want) { 65 t.Errorf("extractAskFn() = %v, want %v", got, tt.want) 66 } 67 }) 68 } 69 }) 70 }