@@ -39,10 +39,6 @@ def setUp(self):
39
39
# in its well-known location
40
40
self .simulated_home = get_bash_call_output ("mktemp -d" )
41
41
bash_call (f"mkdir { self .simulated_home } /.library_generation" )
42
- bash_call (
43
- f"touch { self .simulated_home } /.library_generation/gapic-generator-java.jar"
44
- )
45
-
46
42
# We create a per-test directory where all output files will be created into.
47
43
# Each folder will be deleted after its corresponding test finishes.
48
44
test_dir = get_bash_call_output ("mktemp -d" )
@@ -76,34 +72,84 @@ def _run_command_and_get_sdout(self, command, **kwargs):
76
72
command , stderr = subprocess .PIPE , ** kwargs
77
73
).stdout .decode ()[:- 1 ]
78
74
79
- def test_get_grpc_version_with_no_env_var_fails (self ):
80
- # the absence of DOCKER_GRPC_VERSION will make this function to fail
81
- result = self ._run_command ("get_grpc_version" )
75
+ def test_get_generator_location_with_env_returns_env (self ):
76
+ os .environ ["GAPIC_GENERATOR_LOCATION" ] = "/gapic-generator-java"
77
+ result = self ._run_command_and_get_sdout ("get_gapic_generator_location" )
78
+ self .assertEqual ("/gapic-generator-java" , result )
79
+ os .environ .pop ("GAPIC_GENERATOR_LOCATION" )
80
+
81
+ def test_get_generator_location_without_env_with_local_returns_local (self ):
82
+ bash_call (
83
+ f"touch { self .simulated_home } /.library_generation/gapic-generator-java.jar"
84
+ )
85
+ result = self ._run_command_and_get_sdout ("get_gapic_generator_location" )
86
+ self .assertEqual (
87
+ f"{ self .simulated_home } /.library_generation/gapic-generator-java.jar" ,
88
+ result ,
89
+ )
90
+
91
+ def test_get_generator_location_with_no_env_no_local_file_failed (self ):
92
+ result = self ._run_command ("get_gapic_generator_location" )
93
+ self .assertEqual (1 , result .returncode )
94
+ self .assertRegex (result .stdout .decode (), "Can't find GAPIC generator in" )
95
+
96
+ def test_get_protoc_location_with_env_returns_env (self ):
97
+ os .environ ["DOCKER_PROTOC_LOCATION" ] = "/protoc"
98
+ result = self ._run_command_and_get_sdout ("get_protoc_location" )
99
+ self .assertEqual ("/protoc" , result )
100
+ os .environ .pop ("DOCKER_PROTOC_LOCATION" )
101
+
102
+ def test_get_protoc_location_without_env_with_local_returns_local (self ):
103
+ bash_call (f"mkdir -p { self .simulated_home } /.library_generation/bin" )
104
+ result = self ._run_command_and_get_sdout ("get_protoc_location" )
105
+ self .assertEqual (
106
+ f"{ self .simulated_home } /.library_generation/bin" ,
107
+ result ,
108
+ )
109
+
110
+ def test_get_protoc_location_with_no_env_no_local_file_failed (self ):
111
+ result = self ._run_command ("get_protoc_location" )
82
112
self .assertEqual (1 , result .returncode )
83
- self .assertRegex (result .stdout .decode (), "DOCKER_GRPC_VERSION is not set" )
113
+ self .assertRegex (result .stdout .decode (), "Can't find protoc in" )
114
+
115
+ def test_get_grpc_plugin_location_with_env_returns_env (self ):
116
+ os .environ ["DOCKER_GRPC_LOCATION" ] = "/grpc"
117
+ result = self ._run_command_and_get_sdout ("get_grpc_plugin_location" )
118
+ self .assertEqual ("/grpc" , result )
119
+ os .environ .pop ("DOCKER_GRPC_LOCATION" )
84
120
85
- def test_get_protoc_version_with_no_env_var_fails (self ):
86
- # the absence of DOCKER_PROTOC_VERSION will make this function to fail
87
- result = self ._run_command ("get_protoc_version" )
121
+ def test_get_grpc_plugin_location_without_env_with_local_returns_local (self ):
122
+ bash_call (
123
+ f"touch { self .simulated_home } /.library_generation/protoc-gen-grpc-java.exe"
124
+ )
125
+ result = self ._run_command_and_get_sdout ("get_grpc_plugin_location" )
126
+ self .assertEqual (
127
+ f"{ self .simulated_home } /.library_generation/protoc-gen-grpc-java.exe" ,
128
+ result ,
129
+ )
130
+
131
+ def test_get_grpc_plugin_location_with_no_env_no_local_file_failed (self ):
132
+ result = self ._run_command ("get_grpc_plugin_location" )
88
133
self .assertEqual (1 , result .returncode )
89
- self .assertRegex (result .stdout .decode (), "DOCKER_PROTOC_VERSION is not set " )
134
+ self .assertRegex (result .stdout .decode (), "Can't find grpc plugin in " )
90
135
91
- def test_download_tools_without_baked_generator_fails (self ):
92
- # This test has the same structure as
93
- # download_tools_succeed_with_baked_protoc, but meant for
94
- # gapic-generator-java.
136
+ def test_get_formatter_location_with_env_returns_env (self ):
137
+ os .environ ["JAVA_FORMATTER_LOCATION" ] = "/java-formatter"
138
+ result = self ._run_command_and_get_sdout ("get_java_formatter_location" )
139
+ self .assertEqual ("/java-formatter" , result )
140
+ os .environ .pop ("JAVA_FORMATTER_LOCATION" )
95
141
96
- test_protoc_version = "1.64.0"
97
- test_grpc_version = "1.64.0"
98
- jar_location = (
99
- f"{ self .simulated_home } /.library_generation/gapic-generator-java.jar"
142
+ def test_get_formatter_location_without_env_with_local_returns_local (self ):
143
+ bash_call (
144
+ f"touch { self .simulated_home } /.library_generation/google-java-format.jar"
100
145
)
101
- # we expect the function to fail because the generator jar is not found in
102
- # its well-known location. To achieve this, we temporarily remove the fake
103
- # generator jar
104
- bash_call (f"rm { jar_location } " )
105
- result = self ._run_command (
106
- f"download_tools { test_protoc_version } { test_grpc_version } { self .TEST_ARCHITECTURE } "
146
+ result = self ._run_command_and_get_sdout ("get_java_formatter_location" )
147
+ self .assertEqual (
148
+ f"{ self .simulated_home } /.library_generation/google-java-format.jar" ,
149
+ result ,
107
150
)
151
+
152
+ def test_get_formatter_location_with_no_env_no_local_file_failed (self ):
153
+ result = self ._run_command ("get_java_formatter_location" )
108
154
self .assertEqual (1 , result .returncode )
109
- self .assertRegex (result .stdout .decode (), "Please configure your environment " )
155
+ self .assertRegex (result .stdout .decode (), "Can't find Java formatter in " )
0 commit comments