Debian Codegraph @

vertexai/genai/chat_test.go

raw
1 // Copyright 2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package genai
16
17 import (
18 "fmt"
19 "testing"
20
21 "github.com/google/go-cmp/cmp"
22 )
23
24 func TestCopySanitizedModelContent(t *testing.T) {
25 var tests = []struct {
26 partsIn []Part
27 wantParts []Part
28 }{
29 {[]Part{Text("foobar"), Text("")},
30 []Part{Text("foobar")}},
31 {[]Part{Text(""), Text("foobar"), Text(""), Text("a b c")},
32 []Part{Text("foobar"), Text("a b c")}},
33 {[]Part{Text(""), Text("foobar"), Text(""), Text(""), Blob{MIMEType: "png"}},
34 []Part{Text("foobar"), Blob{MIMEType: "png"}}},
35 }
36
37 for _, tt := range tests {
38 testname := fmt.Sprintf("%v", tt.partsIn)
39 t.Run(testname, func(t *testing.T) {
40 got := copySanitizedModelContent(&Content{Role: "model", Parts: tt.partsIn})
41 if !cmp.Equal(got.Parts, tt.wantParts) {
42 t.Errorf("got %v, want %v", got.Parts, tt.wantParts)
43 }
44 })
45 }
46 }