pulumi/tests/cloud/login_test.go

47 lines
1.3 KiB
Go
Raw Normal View History

2017-10-31 02:23:20 +01:00
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
package cloud
2017-10-31 02:23:20 +01:00
import (
"os"
"testing"
"github.com/pulumi/pulumi/pkg/backend/cloud"
2017-10-31 02:23:20 +01:00
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) {
2017-10-31 02:23:20 +01:00
if os.Getenv("PULUMI_API") == "" {
t.Skip("PULUMI_API environment variable not set. Skipping this test.")
2017-10-31 02:23:20 +01:00
}
}
func TestRequireLogin(t *testing.T) {
requirePulumiAPISet(t)
2017-10-31 02:23:20 +01:00
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")
2017-10-31 02:23:20 +01:00
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")
2017-10-31 02:23:20 +01:00
// login and confirm things work.
os.Setenv(cloud.AccessTokenEnvVar, integration.TestAccountAccessToken)
2017-10-31 02:23:20 +01:00
e.RunCommand("pulumi", "login")
e.RunCommand("pulumi", "stack", "init", "foo")
2017-10-31 02:23:20 +01:00
e.RunCommand("pulumi", "stack", "rm", "foo", "--yes")
})
}