-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[WIP] make smoke test a test and an app #3006
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
google-cloud-core/src/main/java/com/google/cloud/testing/SmokeTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright 2016 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
|
|
||
| package com.google.cloud.testing; | ||
|
|
||
| public interface SmokeTest {} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/DlpServiceSmokeTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Copyright 2018 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.google.cloud.dlp.v2beta1; | ||
|
|
||
| import com.google.privacy.dlp.v2beta1.ContentItem; | ||
| import com.google.privacy.dlp.v2beta1.InspectConfig; | ||
| import com.google.privacy.dlp.v2beta1.InspectContentResponse; | ||
| import com.google.privacy.dlp.v2beta1.Likelihood; | ||
| import com.google.cloud.testing.SmokeTest; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| import org.apache.commons.lang.builder.ReflectionToStringBuilder; | ||
| import org.apache.commons.lang.builder.ToStringStyle; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
|
|
||
|
|
||
| @Category(SmokeTest.class) | ||
| @javax.annotation.Generated("by GAPIC") | ||
| public class DlpServiceSmokeTest { | ||
| @Test | ||
| public void run() { | ||
| main(null); | ||
| } | ||
|
|
||
| public static void main(String args[]) { | ||
| Logger.getLogger("").setLevel(Level.WARNING); | ||
| try { | ||
| executeNoCatch(); | ||
| System.out.println("OK"); | ||
| } catch (Exception e) { | ||
| System.err.println("Failed with exception:"); | ||
| e.printStackTrace(System.err); | ||
| System.exit(1); | ||
| } | ||
| } | ||
|
|
||
| public static void executeNoCatch() throws Exception { | ||
| try (DlpServiceClient client = DlpServiceClient.create()) { | ||
| Likelihood minLikelihood = Likelihood.POSSIBLE; | ||
| InspectConfig inspectConfig = | ||
| InspectConfig.newBuilder().setMinLikelihood(minLikelihood).build(); | ||
| String type = "text/plain"; | ||
| String value = "my phone number is 215-512-1212"; | ||
| ContentItem itemsElement = ContentItem.newBuilder().setType(type).setValue(value).build(); | ||
| List<ContentItem> items = Arrays.asList(itemsElement); | ||
|
|
||
| InspectContentResponse response = client.inspectContent(inspectConfig, items); | ||
| System.out.println( | ||
| ReflectionToStringBuilder.toString(response, ToStringStyle.MULTI_LINE_STYLE)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/TopicAdminSmokeTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * Copyright 2018 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.google.cloud.pubsub.v1; | ||
|
|
||
| import static com.google.cloud.pubsub.v1.TopicAdminClient.ListTopicsPagedResponse; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
| import com.google.pubsub.v1.ProjectName; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
| import com.google.cloud.testing.SmokeTest; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.junit.Test; | ||
| import org.apache.commons.cli.CommandLine; | ||
| import org.apache.commons.cli.DefaultParser; | ||
| import org.apache.commons.cli.HelpFormatter; | ||
| import org.apache.commons.cli.Option; | ||
| import org.apache.commons.cli.Options; | ||
| import org.apache.commons.lang.builder.ReflectionToStringBuilder; | ||
|
|
||
|
|
||
|
|
||
| @Category(SmokeTest.class) | ||
| @javax.annotation.Generated("by GAPIC") | ||
| public class TopicAdminSmokeTest { | ||
| @Test | ||
| public void run() { | ||
| Logger.getLogger("").setLevel(Level.WARNING); | ||
| try { | ||
| String projectId = getProjectId(); | ||
| executeNoCatch(projectId); | ||
| System.out.println("OK"); | ||
| } catch (Exception e) { | ||
| System.err.println("Failed with exception:"); | ||
| e.printStackTrace(System.err); | ||
| System.exit(1); | ||
| } | ||
| } | ||
|
|
||
| public static void main(String args[]) { | ||
| Logger.getLogger("").setLevel(Level.WARNING); | ||
| try { | ||
| String projectId = getProjectId(); | ||
| if (projectId == null) { | ||
| projectId = tryParseProjectIdFromCmdline(args); | ||
| } | ||
| executeNoCatch(projectId); | ||
| System.out.println("OK"); | ||
| } catch (Exception e) { | ||
| System.err.println("Failed with exception:"); | ||
| e.printStackTrace(System.err); | ||
| System.exit(1); | ||
| } | ||
| } | ||
|
|
||
| public static void executeNoCatch(String projectId) throws Exception { | ||
| Preconditions.checkArgument(projectId != null, "A project ID is required."); | ||
| try (TopicAdminClient client = TopicAdminClient.create()) { | ||
| ProjectName project = ProjectName.of(projectId); | ||
|
|
||
| ListTopicsPagedResponse pagedResponse = client.listTopics(project); | ||
| System.out.println(pagedResponse.toString()); | ||
| } | ||
| } | ||
|
|
||
| private static String tryParseProjectIdFromCmdline(String args[]) { | ||
| try { | ||
| Options options = new Options(); | ||
| options.addOption("h", "help", false, "show usage"); | ||
| options.addOption( | ||
| Option.builder() | ||
| .longOpt("project_id") | ||
| .desc("Project id") | ||
| .hasArg() | ||
| .argName("PROJECT-ID") | ||
| .required(true) | ||
| .build()); | ||
| CommandLine cl = (new DefaultParser()).parse(options, args); | ||
| if (cl.hasOption("help")) { | ||
| HelpFormatter formater = new HelpFormatter(); | ||
| formater.printHelp("TopicAdminSmokeTest", options); | ||
| } | ||
| return cl.getOptionValue("project_id"); | ||
| } catch (Exception e) { | ||
| System.err.println("Failed with exception:"); | ||
| e.printStackTrace(System.err); | ||
| System.exit(1); | ||
| } | ||
| return ""; | ||
| } | ||
|
|
||
| private static String getProjectId() { | ||
| final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT"; | ||
| final String LEGACY_PROJECT_ENV_NAME = "GCLOUD_PROJECT"; | ||
| String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME)); | ||
| if (projectId == null) { | ||
| projectId = | ||
| System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME)); | ||
| } | ||
| return projectId; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.