pulumi/tests/cloud/login_test.go
Chris Smith decf814278
Enable running integration tests against the service (#775)
This PR updates the `pkg/testing/integration` package to support running integration tests against the Pulumi Service if desired. This is done through adding new options to `ProgramTestOptions`. (Generally adding support for providing values to flags that were previously inaccessible.)

I added an integration test to confirm that it all works if the PULUMI_API environment variable is set. These tests aren't run in Travis, only manually. Since we cannot reliably run tests from `master` against the service because of the delay in rolling out updates to the Pulumi SDK, etc.
2018-01-03 21:26:50 -08:00

47 lines
1.3 KiB
Go

// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
package cloud
import (
"os"
"testing"
"github.com/pulumi/pulumi/pkg/backend/cloud"
ptesting "github.com/pulumi/pulumi/pkg/testing"
"github.com/pulumi/pulumi/pkg/testing/integration"
"github.com/stretchr/testify/assert"
)
// requirePulumiAPISet will skip the test unless the PULUMI_API is set.
func requirePulumiAPISet(t *testing.T) {
if os.Getenv("PULUMI_API") == "" {
t.Skip("PULUMI_API environment variable not set. Skipping this test.")
}
}
func TestRequireLogin(t *testing.T) {
requirePulumiAPISet(t)
t.Run("SanityTest", func(t *testing.T) {
e := ptesting.NewEnvironment(t)
defer e.DeleteEnvironment()
integration.CreateBasicPulumiRepo(e)
// logout and confirm auth error.
e.RunCommand("pulumi", "logout")
out, err := e.RunCommandExpectError("pulumi", "stack", "init", "foo")
assert.Empty(t, out, "expected no stdout")
assert.Contains(t, err, "error: could not create stack: not yet authenticated with")
assert.Contains(t, err, "; please 'pulumi login' first")
// login and confirm things work.
os.Setenv(cloud.AccessTokenEnvVar, integration.TestAccountAccessToken)
e.RunCommand("pulumi", "login")
e.RunCommand("pulumi", "stack", "init", "foo")
e.RunCommand("pulumi", "stack", "rm", "foo", "--yes")
})
}