有没有人遇到过运行google spanner maven测试(创建和删除数据库)的方法,我总是得到无效的权限。这些测试作为已确认在本地运行的服务帐户所有者运行。
在调试模式下运行travis时,您可以确认已激活正确的服务帐户。
有什么想法吗?
答案 0 :(得分:0)
你的问题不是很具体,但肯定是可能的。我在Travis CI上为我的开源JDBC驱动程序运行集成测试。包含Travis配置文件的源代码可以在这里找到:https://github.com/olavloite/spanner-jdbc
要在Travis上运行测试,您需要确保Travis可以对Google进行身份验证。为此你需要:
before_install:
- openssl aes-256-cbc -K $encrypted_aabbccddeeff_key -iv $encrypted_aabbccddeeff_iv
-in cloudspanner-key.json.enc -out cloudspanner-key.json -d
为了让您的代码获取解密文件,您应该将json文件显式传递给Google,而不是将其设置为环境变量:
Builder builder = SpannerOptions.newBuilder();
builder.setCredentials(getCredentialsFromFile(credentialsPath));
...
public static GoogleCredentials getCredentialsFromFile(String credentialsPath) throws IOException
{
if (credentialsPath == null || credentialsPath.length() == 0)
throw new IllegalArgumentException("credentialsPath may not be null or empty");
GoogleCredentials credentials = null;
File credentialsFile = new File(credentialsPath);
if (!credentialsFile.isFile())
{
throw new IOException(
String.format("Error reading credential file %s: File does not exist", credentialsPath));
}
try (InputStream credentialsStream = new FileInputStream(credentialsFile))
{
credentials = GoogleCredentials.fromStream(credentialsStream, CloudSpannerOAuthUtil.HTTP_TRANSPORT_FACTORY);
}
return credentials;
}