Skip to content

Instantly share code, notes, and snippets.

@omarismail
Last active March 16, 2021 17:08
Show Gist options
  • Save omarismail/002e9e354fc4b2155b5a735a7493a3cf to your computer and use it in GitHub Desktop.
Save omarismail/002e9e354fc4b2155b5a735a7493a3cf to your computer and use it in GitHub Desktop.
package e2etfcapi
import (
"context"
"testing"
tfe "github.com/hashicorp/go-tfe"
"github.com/hashicorp/go-uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestOrganizationsCreate(t *testing.T) {
ctx := context.Background()
// e2e tests
cfg := &tfe.Config{
Token: "<TOKEN>",
}
client, err := tfe.NewClient(cfg)
if err != nil {
t.Fatal(err)
}
t.Run("with valid options", func(t *testing.T) {
options := tfe.OrganizationCreateOptions{
Name: getString("e2e-" + randomString(t)),
Email: getString(randomString(t) + "[email protected]"),
}
org, err := client.Organizations.Create(ctx, options)
require.NoError(t, err)
// Make sure we clean up the created org.
defer client.Organizations.Delete(ctx, org.Name)
assert.Equal(t, *options.Name, org.Name)
assert.Equal(t, *options.Email, org.Email)
})
}
func getString(v string) *string {
return &v
}
func randomString(t *testing.T) string {
v, err := uuid.GenerateUUID()
if err != nil {
t.Fatal(err)
}
return v
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment