Skip to content

Commit 8d596c6

Browse files
committed
Add RequestOptionsTests
1 parent 18ebbd4 commit 8d596c6

File tree

2 files changed

+91
-4
lines changed

2 files changed

+91
-4
lines changed

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/RequestOptions.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import kotlin.time.toDuration
2525
public class RequestOptions
2626
internal constructor(
2727
internal val timeout: Duration,
28-
internal val endpoint: String = "https://firebasevertexai.googleapis.com",
28+
internal val endpoint: String = DEFAULT_ENDPOINT,
2929
internal val apiVersion: String = DEFAULT_API_VERSION.value,
3030
) {
3131

@@ -59,9 +59,10 @@ internal constructor(
5959
apiVersion = apiVersion,
6060
)
6161

62-
private companion object {
63-
private const val DEFAULT_TIMEOUT_IN_MILLIS: Long = 180_000L
62+
internal companion object {
63+
internal const val DEFAULT_TIMEOUT_IN_MILLIS: Long = 180_000L
64+
internal const val DEFAULT_ENDPOINT: String = "https://firebasevertexai.googleapis.com"
6465

65-
private val DEFAULT_API_VERSION: ApiVersion = ApiVersion.V1BETA
66+
internal val DEFAULT_API_VERSION: ApiVersion = ApiVersion.V1BETA
6667
}
6768
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.vertexai.type
18+
19+
import com.google.firebase.vertexai.type.RequestOptions.Companion.DEFAULT_API_VERSION
20+
import com.google.firebase.vertexai.type.RequestOptions.Companion.DEFAULT_ENDPOINT
21+
import com.google.firebase.vertexai.type.RequestOptions.Companion.DEFAULT_TIMEOUT_IN_MILLIS
22+
import io.kotest.matchers.equals.shouldBeEqual
23+
import kotlin.time.DurationUnit
24+
import kotlin.time.toDuration
25+
import org.junit.Test
26+
27+
internal class RequestOptionsTests {
28+
private val defaultTimeout = DEFAULT_TIMEOUT_IN_MILLIS.toDuration(DurationUnit.MILLISECONDS)
29+
30+
@Test
31+
fun `init default values`() {
32+
val requestOptions = RequestOptions()
33+
34+
requestOptions.timeout shouldBeEqual defaultTimeout
35+
requestOptions.endpoint shouldBeEqual DEFAULT_ENDPOINT
36+
requestOptions.apiVersion shouldBeEqual DEFAULT_API_VERSION.value
37+
}
38+
39+
@Test
40+
fun `init custom timeout`() {
41+
val expectedTimeoutInMillis = 60_000L
42+
43+
val requestOptions = RequestOptions(timeoutInMillis = expectedTimeoutInMillis)
44+
45+
requestOptions.timeout shouldBeEqual
46+
expectedTimeoutInMillis.toDuration(DurationUnit.MILLISECONDS)
47+
requestOptions.endpoint shouldBeEqual DEFAULT_ENDPOINT
48+
requestOptions.apiVersion shouldBeEqual DEFAULT_API_VERSION.value
49+
}
50+
51+
@Test
52+
fun `init API version v1`() {
53+
val expectedApiVersion = ApiVersion.V1
54+
55+
val requestOptions = RequestOptions(apiVersion = expectedApiVersion)
56+
57+
requestOptions.timeout shouldBeEqual defaultTimeout
58+
requestOptions.endpoint shouldBeEqual DEFAULT_ENDPOINT
59+
requestOptions.apiVersion shouldBeEqual expectedApiVersion.value
60+
}
61+
62+
@Test
63+
fun `init API version v1beta`() {
64+
val expectedApiVersion = ApiVersion.V1BETA
65+
66+
val requestOptions = RequestOptions(apiVersion = expectedApiVersion)
67+
68+
requestOptions.timeout shouldBeEqual defaultTimeout
69+
requestOptions.endpoint shouldBeEqual DEFAULT_ENDPOINT
70+
requestOptions.apiVersion shouldBeEqual expectedApiVersion.value
71+
}
72+
73+
@Test
74+
fun `init all public options`() {
75+
val expectedTimeoutInMillis = 30_000L
76+
val expectedApiVersion = ApiVersion.V1BETA
77+
78+
val requestOptions =
79+
RequestOptions(timeoutInMillis = expectedTimeoutInMillis, apiVersion = expectedApiVersion)
80+
81+
requestOptions.timeout shouldBeEqual
82+
expectedTimeoutInMillis.toDuration(DurationUnit.MILLISECONDS)
83+
requestOptions.endpoint shouldBeEqual DEFAULT_ENDPOINT
84+
requestOptions.apiVersion shouldBeEqual expectedApiVersion.value
85+
}
86+
}

0 commit comments

Comments
 (0)