ModelContentTests.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. import Foundation
  15. import XCTest
  16. @testable import FirebaseVertexAI
  17. @available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
  18. final class ModelContentTests: XCTestCase {
  19. let encoder = JSONEncoder()
  20. override func setUp() {
  21. encoder.outputFormatting = .init(
  22. arrayLiteral: .prettyPrinted, .sortedKeys, .withoutEscapingSlashes
  23. )
  24. }
  25. // MARK: ModelContent.Part Encoding
  26. func testEncodeFileDataPart() throws {
  27. let mimeType = "image/jpeg"
  28. let fileURI = "gs://test-bucket/image.jpg"
  29. let fileDataPart = ModelContent.Part.fileData(mimetype: mimeType, uri: fileURI)
  30. let jsonData = try encoder.encode(fileDataPart)
  31. let json = try XCTUnwrap(String(data: jsonData, encoding: .utf8))
  32. XCTAssertEqual(json, """
  33. {
  34. "fileData" : {
  35. "file_uri" : "\(fileURI)",
  36. "mime_type" : "\(mimeType)"
  37. }
  38. }
  39. """)
  40. }
  41. }