New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add functions_env_vars #1551
Conversation
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
public class Env { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class Env { | |
public class EnviromentVariableExample { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggested name is too verbose and not in line with other class names. It is not common to add Example
to all the other examples. Looking at the other 3 languages, I've changed the name to EnvVars
.
@Test | ||
public void envTest() throws IOException { | ||
new Env().env(request, response); | ||
assertThat(responseOut.toString(), containsString("")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking for any empty string doesn't actually verify that this function works - any non-null string will contain and empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to set an env var in a test and tried doing so.
Do you know how to set an env var?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you stub it with Mockito?
when(System.getenv("FOO")).thenReturn("someTestValue");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like I can't stub with Mockito.
Cannot mock/spy class java.lang.System Mockito cannot mock/spy because : - final class
Not sure what to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, it looks like we'll have to add an additional dependency to do this:
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>1.19.0</version>
<scope>test</scope>
</dependency>
import org.junit.contrib.java.lang.system.EnvironmentVariables;
public void EnvironmentVariablesTest {
@Rule
public final EnvironmentVariables environmentVariables
= new EnvironmentVariables();
@Test
public void setEnvironmentVariable() {
environmentVariables.set("name", "value");
assertEquals("value", System.getenv("name"));
}
}
Not exactly sure what to do in terms of mocking |
Thanks for the tip and extensive suggestion to fix this. Tests are now logical and pass. (Getting some merge conflicts, but those should be trivial.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, pending tests passing
…form/java-docs-samples into grant_functions_env_vars
@kurtisvg Please advise as to how to fix the Java 11 test. I don't have permission to see the errors and debug. |
@grant - You should be able to access the logs by clicking Details next to the test name, and then clicking on the failed test log. This repo uses resultstore, so it should be open to the public. If it's not please let me know so we can debug. Here is what is says atm:
|
Oh, there's a bug where the You just need to wait a few seconds until the 15k lines of logs download and then you can see the error. A bit frustrating. I sent feedback using the feedback tool. |
Adds
devrel/samples/1063
.