generated from pulumi/pulumi-provider-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcebae7
commit a25013c
Showing
5 changed files
with
124 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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,16 @@ | ||
package tests | ||
|
||
import ( | ||
"github.com/blang/semver" | ||
"github.com/pulumi/pulumi-go-provider/integration" | ||
|
||
baremetal "github.com/unmango/pulumi-baremetal/provider" | ||
) | ||
|
||
func NewIntegrationProvider() integration.Server { | ||
return integration.NewServer( | ||
baremetal.Name, | ||
semver.MustParse("1.0.0"), | ||
baremetal.Provider(), | ||
) | ||
} |
This file contains 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 |
---|---|---|
@@ -1,13 +1,34 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var ( | ||
provisioner testProvisioner | ||
) | ||
|
||
func TestProvider(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Provider Suite") | ||
} | ||
|
||
var _ = BeforeSuite(func(ctx context.Context) { | ||
By("creating a provisioner") | ||
prov, err := NewTestProvisioner(ctx, GinkgoWriter) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = prov.Start(ctx) | ||
Expect(err).NotTo(HaveOccurred()) | ||
provisioner = prov | ||
}) | ||
|
||
var _ = AfterSuite(func(ctx context.Context) { | ||
By("stopping the provisioner") | ||
err := provisioner.Stop(ctx) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) |
This file contains 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 |
---|---|---|
@@ -1,89 +1,22 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/blang/semver" | ||
p "github.com/pulumi/pulumi-go-provider" | ||
"github.com/pulumi/pulumi-go-provider/integration" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/resource" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens" | ||
|
||
baremetal "github.com/unmango/pulumi-baremetal/provider" | ||
) | ||
|
||
var _ = Describe("Provider", Ordered, func() { | ||
var server integration.Server | ||
var provisioner *testProvisioner | ||
|
||
BeforeAll(func(ctx context.Context) { | ||
By("creating a provisioner") | ||
prov, err := NewTestProvisioner(ctx, GinkgoWriter) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = prov.Start(ctx) | ||
Expect(err).NotTo(HaveOccurred()) | ||
provisioner = prov | ||
|
||
By("creating a provider server") | ||
server = integration.NewServer( | ||
baremetal.Name, | ||
semver.MustParse("1.0.0"), | ||
baremetal.Provider(), | ||
) | ||
}) | ||
|
||
BeforeEach(func(ctx context.Context) { | ||
ip, err := provisioner.ct.ContainerIP(ctx) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(ip).NotTo(BeEmpty()) | ||
port := provisioner.port.Int() | ||
|
||
By("configuring the provider") | ||
err = server.Configure(p.ConfigureRequest{ | ||
Args: resource.PropertyMap{ | ||
"address": resource.NewStringProperty(ip), | ||
"port": resource.NewNumberProperty(float64(port)), | ||
}, | ||
}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
It("should create a tee", func() { | ||
stdin := "Test stdin" | ||
By("generating expected data") | ||
|
||
By("creating the resource") | ||
response, err := server.Create(p.CreateRequest{ | ||
Urn: urn("Tee"), | ||
Properties: resource.PropertyMap{ | ||
"stdin": resource.NewStringProperty(stdin), | ||
"create": resource.NewObjectProperty(resource.PropertyMap{ | ||
"files": resource.NewArrayProperty([]resource.PropertyValue{ | ||
resource.NewStringProperty("test"), | ||
}), | ||
}), | ||
}, | ||
Preview: false, | ||
}) | ||
|
||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(response).NotTo(BeNil()) | ||
Expect(response.Properties["stdout"].V).To(Equal("op: OP_CREATE, cmd: COMMAND_TEE, args: []string{\"test\"}, flags: map[string]*baremetalv1alpha1.Flag(nil)")) | ||
}) | ||
var _ = Describe("Provider", Ordered, func() {}) | ||
|
||
AfterAll(func(ctx context.Context) { | ||
By("stopping the provisioner") | ||
err := provisioner.Stop(ctx) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
}) | ||
func urn(typ string, mods ...string) resource.URN { | ||
if len(mods) == 0 { | ||
mods = []string{"index"} | ||
} | ||
|
||
// urn is a helper function to build an urn for running integration tests. | ||
func urn(typ string) resource.URN { | ||
tok := strings.Join(append(mods, typ), ":") | ||
return resource.NewURN("stack", "proj", "", | ||
tokens.Type("test:cmd:"+typ), "name") | ||
tokens.Type("test:"+tok), "name") | ||
} |
This file contains 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
This file contains 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,48 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
p "github.com/pulumi/pulumi-go-provider" | ||
"github.com/pulumi/pulumi-go-provider/integration" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/resource" | ||
) | ||
|
||
var _ = Describe("Tee", Ordered, func() { | ||
var server integration.Server | ||
|
||
BeforeEach(func(ctx context.Context) { | ||
By("creating a provider server") | ||
server = NewIntegrationProvider() | ||
|
||
By("configuring the provider") | ||
err := provisioner.ConfigureProvider(ctx, server) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
It("should create a tee", func() { | ||
stdin := "Test stdin" | ||
By("generating expected data") | ||
|
||
By("creating the resource") | ||
response, err := server.Create(p.CreateRequest{ | ||
Urn: urn("Tee", "cmd"), | ||
Properties: resource.PropertyMap{ | ||
"stdin": resource.NewStringProperty(stdin), | ||
"create": resource.NewObjectProperty(resource.PropertyMap{ | ||
"files": resource.NewArrayProperty([]resource.PropertyValue{ | ||
resource.NewStringProperty("test"), | ||
}), | ||
}), | ||
}, | ||
Preview: false, | ||
}) | ||
|
||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(response).NotTo(BeNil()) | ||
Expect(response.Properties["stdout"].V).To(Equal("op: OP_CREATE, cmd: COMMAND_TEE, args: []string{\"test\"}, flags: map[string]*baremetalv1alpha1.Flag(nil)")) | ||
}) | ||
}) |