Skip to content

Commit def357d

Browse files
committed
Skip Imagen integration test unless VTXIntegrationImagen env var defined
1 parent 7059b0a commit def357d

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

.github/workflows/vertexai.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
schedule:
1010
# Run every day at 11pm (PST) - cron uses UTC times
1111
- cron: '0 7 * * *'
12+
workflow_dispatch:
1213

1314
concurrency:
1415
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
@@ -102,7 +103,7 @@ jobs:
102103
needs: spm-package-resolved
103104
env:
104105
TEST_RUNNER_FIRAAppCheckDebugToken: ${{ secrets.VERTEXAI_INTEGRATION_FAC_DEBUG_TOKEN }}
105-
TEST_RUNNER_VTXIntegrationImagen: ${{ github.event_name == 'schedule' }}
106+
TEST_RUNNER_VTXIntegrationImagen: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
106107
FIREBASECI_USE_LATEST_GOOGLEAPPMEASUREMENT: 1
107108
secrets_passphrase: ${{ secrets.GHASecretsGPGPassphrase1 }}
108109
steps:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
import Foundation
16+
import XCTest
17+
18+
enum IntegrationTestUtils {
19+
/// Skips an XCTest unless the specified environment variable is set.
20+
///
21+
/// - Parameters:
22+
/// - environmentVariable: The environment variable that must be defined for the test to
23+
/// continue (i.e., not get skipped).
24+
/// - requiredValue: If specified, skips the test if `environmentVariable` is not set to the
25+
/// this value; if `nil`, any value allows the test to continue.
26+
/// - Throws: `XCTSkip` if the test should be skipped.
27+
static func skipUnless(environmentVariable: String, requiredValue: String? = nil) throws {
28+
guard let variableValue = ProcessInfo.processInfo.environment[environmentVariable] else {
29+
throw XCTSkip("Skipped because environment variable '\(environmentVariable)' is not defined.")
30+
}
31+
32+
if let requiredValue, variableValue != requiredValue {
33+
throw XCTSkip("""
34+
Skipped because environment variable '\(environmentVariable)' != '\(requiredValue)'; value \
35+
is '\(variableValue)'.
36+
""")
37+
}
38+
}
39+
}

FirebaseVertexAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,7 @@ final class IntegrationTests: XCTestCase {
243243
// MARK: - Imagen
244244

245245
func testGenerateImage_inlineData() async throws {
246-
if let imagenEnvVar = ProcessInfo.processInfo.environment["VTXIntegrationImagen"] {
247-
XCTFail("VTXIntegrationImagen: \(imagenEnvVar)")
248-
} else {
249-
XCTFail("VTXIntegrationImagen is undefined.")
250-
}
251-
246+
try IntegrationTestUtils.skipUnless(environmentVariable: "VTXIntegrationImagen")
252247
let imagePrompt = """
253248
A realistic photo of a male lion, mane thick and dark, standing proudly on a rocky outcrop
254249
overlooking a vast African savanna at sunset. Golden hour light, long shadows, sharp focus on

FirebaseVertexAI/Tests/TestApp/VertexAITestApp.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
862218812D04E098007ED2D4 /* IntegrationTestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 862218802D04E08D007ED2D4 /* IntegrationTestUtils.swift */; };
1011
8661385C2CC943DD00F4B78E /* TestApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8661385B2CC943DD00F4B78E /* TestApp.swift */; };
1112
8661385E2CC943DD00F4B78E /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8661385D2CC943DD00F4B78E /* ContentView.swift */; };
1213
8661386E2CC943DE00F4B78E /* IntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8661386D2CC943DE00F4B78E /* IntegrationTests.swift */; };
@@ -33,6 +34,7 @@
3334
/* End PBXContainerItemProxy section */
3435

3536
/* Begin PBXFileReference section */
37+
862218802D04E08D007ED2D4 /* IntegrationTestUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegrationTestUtils.swift; sourceTree = "<group>"; };
3638
866138582CC943DD00F4B78E /* VertexAITestApp-SPM.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "VertexAITestApp-SPM.app"; sourceTree = BUILT_PRODUCTS_DIR; };
3739
8661385B2CC943DD00F4B78E /* TestApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestApp.swift; sourceTree = "<group>"; };
3840
8661385D2CC943DD00F4B78E /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -122,6 +124,7 @@
122124
children = (
123125
868A7C4D2CCC1F4700E449DD /* Credentials.swift */,
124126
8661386D2CC943DE00F4B78E /* IntegrationTests.swift */,
127+
862218802D04E08D007ED2D4 /* IntegrationTestUtils.swift */,
125128
);
126129
path = Integration;
127130
sourceTree = "<group>";
@@ -265,6 +268,7 @@
265268
files = (
266269
8698D7462CD3CF3600ABA833 /* FirebaseAppTestUtils.swift in Sources */,
267270
868A7C4F2CCC229F00E449DD /* Credentials.swift in Sources */,
271+
862218812D04E098007ED2D4 /* IntegrationTestUtils.swift in Sources */,
268272
8661386E2CC943DE00F4B78E /* IntegrationTests.swift in Sources */,
269273
);
270274
runOnlyForDeploymentPostprocessing = 0;

0 commit comments

Comments
 (0)