This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 2134e7dacd8 GitHubTestParameterLoadStrategy support GitHub token. 
(#27966)
2134e7dacd8 is described below

commit 2134e7dacd85991ea672dc84fc8f0c4815ccddb6
Author: Cong Hu <[email protected]>
AuthorDate: Tue Aug 8 10:06:44 2023 +0800

    GitHubTestParameterLoadStrategy support GitHub token. (#27966)
    
    * GitHubTestParameterLoadStrategy support GitHub token.
    
    * GitHubTestParameterLoadStrategy support GitHub token.
---
 .../test/env/env/TestUtilEnvironment.java          | 64 ++++++++++++++++++++++
 .../impl/GitHubTestParameterLoadStrategy.java      | 20 +++++--
 .../main/resources/env/test-util-env.properties    | 17 ++++++
 3 files changed, 96 insertions(+), 5 deletions(-)

diff --git 
a/test/util/src/main/java/org/apache/shardingsphere/test/env/env/TestUtilEnvironment.java
 
b/test/util/src/main/java/org/apache/shardingsphere/test/env/env/TestUtilEnvironment.java
new file mode 100644
index 00000000000..2c96a17aa4a
--- /dev/null
+++ 
b/test/util/src/main/java/org/apache/shardingsphere/test/env/env/TestUtilEnvironment.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.shardingsphere.test.env.env;
+
+import lombok.Getter;
+import lombok.SneakyThrows;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * Test util environment.
+ */
+@Getter
+public final class TestUtilEnvironment {
+    
+    private static final String SQL_PARSER_EXTERNAL_IT_GITHUB_TOKEN = 
"test.util.github.token";
+    
+    private static final TestUtilEnvironment INSTANCE = new 
TestUtilEnvironment();
+    
+    private final String githubToken;
+    
+    private TestUtilEnvironment() {
+        Properties props = loadProperties();
+        githubToken = props.getProperty(SQL_PARSER_EXTERNAL_IT_GITHUB_TOKEN);
+    }
+    
+    /**
+     * Get instance.
+     *
+     * @return got instance
+     */
+    public static TestUtilEnvironment getInstance() {
+        return INSTANCE;
+    }
+    
+    @SneakyThrows(IOException.class)
+    private Properties loadProperties() {
+        Properties result = new Properties();
+        try (InputStream inputStream = 
Thread.currentThread().getContextClassLoader().getResourceAsStream("env/test-util-env.properties"))
 {
+            result.load(inputStream);
+        }
+        for (String each : System.getProperties().stringPropertyNames()) {
+            result.setProperty(each, System.getProperty(each));
+        }
+        return result;
+    }
+}
diff --git 
a/test/util/src/main/java/org/apache/shardingsphere/test/loader/strategy/impl/GitHubTestParameterLoadStrategy.java
 
b/test/util/src/main/java/org/apache/shardingsphere/test/loader/strategy/impl/GitHubTestParameterLoadStrategy.java
index bfae3981a07..9f081999f8a 100644
--- 
a/test/util/src/main/java/org/apache/shardingsphere/test/loader/strategy/impl/GitHubTestParameterLoadStrategy.java
+++ 
b/test/util/src/main/java/org/apache/shardingsphere/test/loader/strategy/impl/GitHubTestParameterLoadStrategy.java
@@ -20,6 +20,8 @@ package org.apache.shardingsphere.test.loader.strategy.impl;
 import com.jayway.jsonpath.DocumentContext;
 import com.jayway.jsonpath.JsonPath;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shardingsphere.test.env.env.TestUtilEnvironment;
 import 
org.apache.shardingsphere.test.loader.strategy.TestParameterLoadStrategy;
 import org.apache.shardingsphere.test.loader.summary.FileSummary;
 
@@ -27,6 +29,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URI;
+import java.net.URLConnection;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedList;
@@ -41,6 +44,9 @@ public final class GitHubTestParameterLoadStrategy implements 
TestParameterLoadS
     
     @Override
     public Collection<FileSummary> loadSQLCaseFileSummaries(final URI uri) {
+        if (uri.toString().isEmpty()) {
+            return Collections.emptyList();
+        }
         String content = loadContent(getGitHubApiUri(uri));
         if (content.isEmpty()) {
             return Collections.emptyList();
@@ -53,7 +59,7 @@ public final class GitHubTestParameterLoadStrategy implements 
TestParameterLoadS
         List<String> htmlURLs = documentContext.read("$..html_url");
         int length = documentContext.read("$.length()");
         for (int i = 0; i < length; i++) {
-            String fileName = fileNames.get(i).split("\\.")[0];
+            String fileName = fileNames.get(i);
             String folderType = folderTypes.get(i);
             String downloadURL = downloadURLs.get(i);
             String htmlURL = htmlURLs.get(i);
@@ -75,10 +81,14 @@ public final class GitHubTestParameterLoadStrategy 
implements TestParameterLoadS
     }
     
     private String loadContent(final URI casesURI) {
-        try (
-                InputStreamReader in = new 
InputStreamReader(casesURI.toURL().openStream());
-                BufferedReader reader = new BufferedReader(in)) {
-            return 
reader.lines().collect(Collectors.joining(System.lineSeparator()));
+        try {
+            URLConnection urlConnection = casesURI.toURL().openConnection();
+            if 
(StringUtils.isNotBlank(TestUtilEnvironment.getInstance().getGithubToken())) {
+                urlConnection.setRequestProperty("Authorization", "Bearer " + 
TestUtilEnvironment.getInstance().getGithubToken());
+            }
+            try (BufferedReader reader = new BufferedReader(new 
InputStreamReader(urlConnection.getInputStream()))) {
+                return 
reader.lines().collect(Collectors.joining(System.lineSeparator()));
+            }
         } catch (final IOException ex) {
             log.warn("Load failed, reason is: ", ex);
             return "";
diff --git a/test/util/src/main/resources/env/test-util-env.properties 
b/test/util/src/main/resources/env/test-util-env.properties
new file mode 100644
index 00000000000..93f8f4d9078
--- /dev/null
+++ b/test/util/src/main/resources/env/test-util-env.properties
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+test.util.github.token=

Reply via email to