Skip to content
This repository has been archived by the owner on Dec 24, 2020. It is now read-only.

Commit

Permalink
Update example test and README
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehoban committed Dec 14, 2018
1 parent 7a7cb40 commit e66664a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 118 deletions.
39 changes: 8 additions & 31 deletions README.md
@@ -1,33 +1,10 @@
# Terraform Bridge Provider Boilerplate
[![Build Status](https://travis-ci.com/pulumi/pulumi-packet.svg?token=eHg7Zp5zdDDJfTjY8ejq&branch=master)](https://travis-ci.com/pulumi/pulumi-packet)

This repository contains boilerplate code for building a new Pulumi provider which wraps an existing
Terraform provider.
# Packet provider

Modify this README to describe:
The Packet resource provider for Pulumi lets you use [Packet](https://www.packet.com/) resources in your cloud programs. To use
this package, please [install the Pulumi CLI first](https://pulumi.io/).

- The type of resources the provider manages
- Add a build status image from Travis at the top of the README
- Update package names in the information below
- Add any important documentation of concepts (e.g. the "serverless" components in the AWS provider).

Then:

- Rename the `cmd/pulumi-{resource,tfgen}-x` directories to match the provider name
- Update `scripts/publish-package.sh` with the provider name
- Update `Makefile` with the provider name
- Update `Gopkg.template.toml` with the upstream provider and version information

Lock in dependency versions:

- `go get github.com/pulumi/scripts/govendor-override`
- `govendor-override < Gopkg.template.toml > Gopkg.toml`
- `make ensure`

Finally, build the provider:

- Edit `resources.go` to map each resource, and specify provider information
- Enumerate any examples in `examples/examples_test.go`
- `make`

## Installing

Expand All @@ -37,17 +14,17 @@ This package is available in many languages in the standard packaging formats.

To use from JavaScript or TypeScript in Node.js, install using either `npm`:

$ npm install @pulumi/x
$ npm install @pulumi/packet

or `yarn`:

$ yarn add @pulumi/x
$ yarn add @pulumi/packet

### Python

To use from Python, install using `pip`:

$ pip install pulumi_x
$ pip install pulumi_packet

### Go

Expand All @@ -60,4 +37,4 @@ To use from Go, use `go get` to grab the latest version of the library
For detailed reference documentation, please visit [the API docs][1].


[1]: https://pulumi.io/reference/pkg/nodejs/@pulumi/x/index.html
[1]: https://pulumi.io/reference/pkg/nodejs/@pulumi/packet/index.html
110 changes: 30 additions & 80 deletions examples/examples_test.go
@@ -1,95 +1,45 @@
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
// Copyright 2016-2018, Pulumi Corporation.
//
// Licensed 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 examples

import (
"io/ioutil"
"net/http"
"os"
"path"
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/pulumi/pulumi/pkg/testing/integration"

"github.com/stretchr/testify/assert"
)

func TestExamples(t *testing.T) {
// Ensure we have any required configuration points
// region := os.Getenv("AWS_REGION")
// if region == "" {
// t.Skipf("Skipping test due to missing AWS_REGION environment variable")
// }
// cwd, err := os.Getwd()
// if !assert.NoError(t, err, "expected a valid working directory: %v", err) {
// return
// }
var base = integration.ProgramTestOptions{
ExpectRefreshChanges: true,
// Note: no Config! This package should be usable without any config.
}

// base options shared amongst all tests.
base := integration.ProgramTestOptions{
Config: map[string]string{
// Configuration map
},
Tracing: "https://tracing.pulumi-engineering.com/collector/api/v1/spans",
func TestWebserver(t *testing.T) {
cwd, err := os.Getwd()
if !assert.NoError(t, err) {
t.FailNow()
}
baseJS := base.With(integration.ProgramTestOptions{

opts := base.With(integration.ProgramTestOptions{
Dependencies: []string{
// JavaScript dependencies
"@pulumi/packet",
},
Dir: path.Join(cwd, "webserver"),
})

examples := []integration.ProgramTestOptions{
// List each test
// baseJS.With(integration.ProgramTestOptions{
// Dir: path.Join(cwd, "api"),
// ExtraRuntimeValidation: validateAPITest(func(body string) {
// assert.Equal(t, "Hello, world!", body)
// }),
// EditDirs: []integration.EditDir{{
// Dir: "./api/step2",
// Additive: true,
// ExtraRuntimeValidation: validateAPITest(func(body string) {
// assert.Equal(t, "<h1>Hello world!</h1>", body)
// }),
// }},
// ExpectRefreshChanges: true,
// }),
}

if !testing.Short() {
// Append any longer running tests
}

for _, ex := range examples {
example := ex
t.Run(example.Dir, func(t *testing.T) {
integration.ProgramTest(t, &example)
})
}
}

func createEditDir(dir string) integration.EditDir {
return integration.EditDir{Dir: dir, ExtraRuntimeValidation: nil}
}

func validateAPITest(isValid func(body string)) func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
return func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
var resp *http.Response
var err error
url := stack.Outputs["url"].(string)
// Retry a couple times on 5xx
for i := 0; i < 2; i++ {
resp, err = http.Get(url + "/b")
if !assert.NoError(t, err) {
return
}
if resp.StatusCode < 500 {
break
}
time.Sleep(10 * time.Second)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
assert.NoError(t, err)
isValid(string(body))
}
integration.ProgramTest(t, &opts)
}
8 changes: 1 addition & 7 deletions examples/webserver/index.ts
@@ -1,24 +1,18 @@
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.

import * as packet from "@pulumi/packet";
import * as fs from "fs";

let project = new packet.Project("project", {
name: "pulumi",
});

let sshkey = new packet.SSHKey("key", {
name: "mykey",
publicKey: fs.readFileSync("/Users/luke/.ssh/id_rsa.pub").toString(),
});

let vm = new packet.Device("vm", {
facility: "ewr1",
billingCycle: "hourly",
hostname: "lukehoban",
operatingSystem: "coreos_stable",
plan: "baremetal_0",
projectId: project.id,
}, { dependsOn: [sshkey] });
});

export let ip = vm.accessPublicIpv4;

0 comments on commit e66664a

Please sign in to comment.