aboutsummaryrefslogtreecommitdiff
path: root/provider/provider_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'provider/provider_test.go')
-rw-r--r--provider/provider_test.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/provider/provider_test.go b/provider/provider_test.go
new file mode 100644
index 0000000..ade33a6
--- /dev/null
+++ b/provider/provider_test.go
@@ -0,0 +1,77 @@
+package provider_test
+
+import (
+ "encoding/json"
+ "net/http/httptest"
+ "testing"
+
+ p "github.com/pulumi/pulumi-go-provider"
+ "github.com/pulumi/pulumi/sdk/v3/go/property"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestConfigureRequiresCredentials(t *testing.T) {
+
+ t.Setenv("PORKBUN_API_KEY", "")
+ t.Setenv("PORKBUN_SECRET_API_KEY", "")
+
+ server := newIntegrationServer(t)
+ err := server.Configure(p.ConfigureRequest{Args: property.Map{}})
+ require.Error(t, err)
+ assert.Contains(t, err.Error(), "PORKBUN_API_KEY")
+}
+
+func TestConfigureReadsCredentialsFromEnvironment(t *testing.T) {
+ fake := newFakePorkbun(t)
+ httpSrv := httptest.NewServer(fake)
+ t.Cleanup(httpSrv.Close)
+
+ t.Setenv("PORKBUN_API_KEY", testAPIKey)
+ t.Setenv("PORKBUN_SECRET_API_KEY", testSecretKey)
+
+ server := newIntegrationServer(t)
+ checked, err := server.CheckConfig(p.CheckRequest{
+ Inputs: property.NewMap(map[string]property.Value{
+ "baseUrl": property.New(httpSrv.URL),
+ }),
+ })
+ require.NoError(t, err)
+ require.NoError(t, server.Configure(p.ConfigureRequest{Args: checked.Inputs}))
+
+ resp, err := server.Create(p.CreateRequest{
+ Urn: testURN,
+ Properties: checkedInputs(nil),
+ })
+ require.NoError(t, err)
+ assert.NotNil(t, fake.record("example.com", resp.ID))
+}
+
+func TestSchema(t *testing.T) {
+ server := newIntegrationServer(t)
+ resp, err := server.GetSchema(p.GetSchemaRequest{})
+ require.NoError(t, err)
+
+ var schema struct {
+ Name string `json:"name"`
+ Config struct {
+ Variables map[string]struct {
+ Secret bool `json:"secret"`
+ } `json:"variables"`
+ } `json:"config"`
+ Resources map[string]struct {
+ RequiredInputs []string `json:"requiredInputs"`
+ } `json:"resources"`
+ }
+ require.NoError(t, json.Unmarshal([]byte(resp.Schema), &schema))
+
+ assert.Equal(t, "porkbun", schema.Name)
+ require.Contains(t, schema.Resources, dnsRecordToken)
+ assert.ElementsMatch(t, []string{"domain", "type", "content"},
+ schema.Resources[dnsRecordToken].RequiredInputs)
+
+ require.Contains(t, schema.Config.Variables, "apiKey")
+ require.Contains(t, schema.Config.Variables, "secretApiKey")
+ assert.True(t, schema.Config.Variables["apiKey"].Secret, "apiKey must be marked secret")
+ assert.True(t, schema.Config.Variables["secretApiKey"].Secret, "secretApiKey must be marked secret")
+}