File tree Expand file tree Collapse file tree
genai/src/test/java/genai/textgeneration Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,8 +40,28 @@ public static void requireEnvVar(String envVarName) {
4040 .isNotEmpty ();
4141 }
4242
43+ // Helper function to set environment variables programmatically
44+ public static void setEnvVariable (String key , String value ) {
45+ try {
46+ Map <String , String > env = System .getenv ();
47+ Class <?> cl = env .getClass ();
48+ Field field = cl .getDeclaredField ("m" );
49+ field .setAccessible (true );
50+ @ SuppressWarnings ("unchecked" )
51+ Map <String , String > writableEnv = (Map <String , String >) field .get (env );
52+ if (!writableEnv .containsKey (key )) {
53+ writableEnv .put (key , value );
54+ }
55+ } catch (Exception e ) {
56+ throw new IllegalStateException ("Failed to set environment variable" , e );
57+ }
58+ }
59+
4360 @ BeforeClass
4461 public static void setUp () {
62+ setEnvVariable ("GOOGLE_CLOUD_LOCATION" , "us-central1" );
63+ setEnvVariable ("GOOGLE_GENAI_USE_VERTEXAI" , "True" );
64+
4565 requireEnvVar ("GOOGLE_APPLICATION_CREDENTIALS" );
4666 requireEnvVar ("GOOGLE_CLOUD_PROJECT" );
4767 requireEnvVar ("GOOGLE_CLOUD_LOCATION" );
You can’t perform that action at this time.
0 commit comments