|
7 | 7 | "testing" |
8 | 8 |
|
9 | 9 | . "github.com/smartystreets/goconvey/convey" |
| 10 | + |
| 11 | + "github.com/coze-dev/cozeloop-go/internal/util" |
10 | 12 | ) |
11 | 13 |
|
12 | 14 | func TestPromptDeepCopy(t *testing.T) { |
@@ -210,6 +212,75 @@ func TestMessageDeepCopy(t *testing.T) { |
210 | 212 | So(copied.Role, ShouldEqual, RoleTool) |
211 | 213 | So(copied.Content, ShouldBeNil) |
212 | 214 | }) |
| 215 | + |
| 216 | + Convey("Test message with Role and Parts", func() { |
| 217 | + url := "http://example.com/image.png" |
| 218 | + parts := []*ContentPart{ |
| 219 | + { |
| 220 | + Type: "text", |
| 221 | + Text: util.Ptr("Hello"), |
| 222 | + }, |
| 223 | + { |
| 224 | + Type: "image", |
| 225 | + ImageURL: &url, |
| 226 | + }, |
| 227 | + } |
| 228 | + msg := &Message{ |
| 229 | + Role: "user", |
| 230 | + Parts: parts, |
| 231 | + } |
| 232 | + copied := msg.DeepCopy() |
| 233 | + So(copied, ShouldNotBeNil) |
| 234 | + So(copied.Role, ShouldEqual, msg.Role) |
| 235 | + So(copied.Content, ShouldBeNil) |
| 236 | + So(copied.Parts, ShouldNotBeNil) |
| 237 | + So(len(copied.Parts), ShouldEqual, len(msg.Parts)) |
| 238 | + for i, part := range copied.Parts { |
| 239 | + So(part.Type, ShouldEqual, msg.Parts[i].Type) |
| 240 | + if part.Text != nil { |
| 241 | + So(*part.Text, ShouldEqual, *msg.Parts[i].Text) |
| 242 | + } |
| 243 | + if part.ImageURL != nil { |
| 244 | + So(part.ImageURL, ShouldEqual, msg.Parts[i].ImageURL) |
| 245 | + } |
| 246 | + } |
| 247 | + }) |
| 248 | + |
| 249 | + Convey("Test message with Role, Content, and Parts", func() { |
| 250 | + content := "Hello, World!" |
| 251 | + url := "http://example.com/image.png" |
| 252 | + parts := []*ContentPart{ |
| 253 | + { |
| 254 | + Type: "text", |
| 255 | + Text: util.Ptr("Hello"), |
| 256 | + }, |
| 257 | + { |
| 258 | + Type: "image", |
| 259 | + ImageURL: &url, |
| 260 | + }, |
| 261 | + } |
| 262 | + msg := &Message{ |
| 263 | + Role: "user", |
| 264 | + Content: &content, |
| 265 | + Parts: parts, |
| 266 | + } |
| 267 | + copied := msg.DeepCopy() |
| 268 | + So(copied, ShouldNotBeNil) |
| 269 | + So(copied.Role, ShouldEqual, msg.Role) |
| 270 | + So(copied.Content, ShouldNotBeNil) |
| 271 | + So(*copied.Content, ShouldEqual, *msg.Content) |
| 272 | + So(copied.Parts, ShouldNotBeNil) |
| 273 | + So(len(copied.Parts), ShouldEqual, len(msg.Parts)) |
| 274 | + for i, part := range copied.Parts { |
| 275 | + So(part.Type, ShouldEqual, msg.Parts[i].Type) |
| 276 | + if part.Text != nil { |
| 277 | + So(*part.Text, ShouldEqual, *msg.Parts[i].Text) |
| 278 | + } |
| 279 | + if part.ImageURL != nil { |
| 280 | + So(part.ImageURL, ShouldEqual, msg.Parts[i].ImageURL) |
| 281 | + } |
| 282 | + } |
| 283 | + }) |
213 | 284 | }) |
214 | 285 | } |
215 | 286 |
|
|
0 commit comments