Skip to content

Commit

Permalink
Integration tests for Maven and Gradle providers
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailshilkov committed Feb 5, 2025
1 parent 04f79be commit f328017
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ pulumi-analyzer-policy-python.cmd
# Ignore user-provided go.work files.
/go.work
/go.work.sum
**/build/
**/target/
40 changes: 40 additions & 0 deletions tests/integration/java_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package integration

import (
"bytes"
"encoding/json"
"os/exec"
"path/filepath"
"testing"
Expand Down Expand Up @@ -117,6 +119,44 @@ func TestIntegrations(t *testing.T) {
integration.ProgramTest(t, &test)
})

t.Run("package-schema", func(t *testing.T) {
t.Parallel()

dir := getCwd(t)
pulumi, err := exec.LookPath("pulumi")
require.NoError(t, err)

providers := []string{"provider-maven", "provider-gradle"}
for _, provider := range providers {
provider := provider // Create new variable to avoid loop capture
t.Run(provider, func(t *testing.T) {
t.Parallel()

var stdout bytes.Buffer
var stderr bytes.Buffer
cmd := exec.Command(pulumi, "package", "get-schema", "./"+provider)
cmd.Dir = dir
cmd.Stdout = &stdout
cmd.Stderr = &stderr

err = cmd.Run()
require.NoError(t, err)

// Validate that the schema output is valid JSON
var schema map[string]interface{}
err = json.Unmarshal(stdout.Bytes(), &schema)
require.NoError(t, err, "schema should be valid JSON")

// Validate required schema fields
assert.Contains(t, schema, "name", "schema should have a name field")
assert.Equal(t, "example", schema["name"], "schema name should be 'example'")
assert.Contains(t, schema, "version", "schema should have a version field")
assert.Equal(t, "0.0.1", schema["version"], "schema version should be '0.0.1'")
assert.Contains(t, schema, "resources", "schema should have a resources field")
})
}
})

runAliasTest(t, "rename")
runAliasTest(t, "rename-component")
runAliasTest(t, "rename-component-and-child")
Expand Down
1 change: 1 addition & 0 deletions tests/integration/provider-gradle/PulumiPlugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
runtime: java
35 changes: 35 additions & 0 deletions tests/integration/provider-gradle/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
plugins {
id 'application'
}

group 'com.pulumi.example.provider'
version '0.0.1-SNAPSHOT'

repositories {
mavenLocal()
maven { // The google mirror is less flaky than mavenCentral()
url("https://maven-central.storage-download.googleapis.com/maven2/")
}
mavenCentral()
}

def grpcVersion = '1.67.1'
def protobufVersion = '3.25.1'
def pulumiJavaSdkVersion = System.getenv("PULUMI_JAVA_SDK_VERSION") ?: "0.0.1"

dependencies {
implementation("com.pulumi:pulumi:$pulumiJavaSdkVersion") {
exclude group: 'io.grpc', module: 'grpc-netty-shaded'
}
implementation "io.grpc:grpc-netty-shaded:$grpcVersion"
implementation "io.grpc:grpc-protobuf:$grpcVersion"
implementation "io.grpc:grpc-stub:$grpcVersion"
implementation "javax.annotation:javax.annotation-api:1.3.2"
implementation "com.google.protobuf:protobuf-java:$protobufVersion"
}

application {
mainClass = project.hasProperty("mainClass")
? project.getProperty("mainClass")
: "${group}.Main"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pulumi.example.provider;

import com.pulumi.provider.internal.models.*;

import java.util.concurrent.CompletableFuture;
import com.pulumi.provider.internal.Provider;

public class ExampleProvider extends Provider {
@Override
public CompletableFuture<GetSchemaResponse> getSchema(GetSchemaRequest request) {
String schema = "{\n" +
" \"name\": \"example\",\n" +
" \"version\": \"0.0.1\",\n" +
" \"resources\": {\n" +
" \"example:index:Resource\": {\n" +
" \"properties\": {\n" +
" \"value\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" }" +
" }\n" +
" }\n" +
"}";
return CompletableFuture.completedFuture(new GetSchemaResponse(schema));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.pulumi.example.provider;

import java.io.IOException;
import com.pulumi.provider.internal.ResourceProviderService;

public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
var server = new ResourceProviderService(new ExampleProvider());
server.startAndBlockUntilShutdown();
}
}

1 change: 1 addition & 0 deletions tests/integration/provider-maven/PulumiPlugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
runtime: java
132 changes: 132 additions & 0 deletions tests/integration/provider-maven/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.pulumi.example</groupId>
<artifactId>provider</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<encoding>UTF-8</encoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<mainClass>${project.groupId}.${project.artifactId}.App</mainClass>
<mainArgs/>
<grpc.version>1.67.1</grpc.version>
<protobuf.version>3.25.1</protobuf.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<profiles>
<profile>
<id>default-pulumi-java-sdk-dependency</id>
<activation>
<property>
<name>!env.PULUMI_JAVA_SDK_VERSION</name>
</property>
</activation>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>pulumi</artifactId>
<version>0.0.1</version>
<exclusions>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${protobuf.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<mainClass>${mainClass}</mainClass>
<commandlineArgs>${mainArgs}</commandlineArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-wrapper-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<mavenVersion>3.8.5</mavenVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.pulumi.example.provider;

import java.io.IOException;
import com.pulumi.provider.internal.ResourceProviderService;

public class App {
public static void main(String[] args) throws IOException, InterruptedException {
var server = new ResourceProviderService(new ExampleProvider());
server.startAndBlockUntilShutdown();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pulumi.example.provider;

import com.pulumi.provider.internal.models.*;

import java.util.concurrent.CompletableFuture;
import com.pulumi.provider.internal.Provider;

public class ExampleProvider extends Provider {
@Override
public CompletableFuture<GetSchemaResponse> getSchema(GetSchemaRequest request) {
String schema = "{\n" +
" \"name\": \"example\",\n" +
" \"version\": \"0.0.1\",\n" +
" \"resources\": {\n" +
" \"example:index:Resource\": {\n" +
" \"properties\": {\n" +
" \"value\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" }" +
" }\n" +
" }\n" +
"}";
return CompletableFuture.completedFuture(new GetSchemaResponse(schema));
}
}

0 comments on commit f328017

Please sign in to comment.