2017-10-31 02:23:20 +01:00
|
|
|
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
|
2018-01-04 06:26:50 +01:00
|
|
|
package cloud
|
2017-10-31 02:23:20 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2017-12-05 22:39:13 +01:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2018-01-04 06:26:50 +01:00
|
|
|
// 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") == "" {
|
2018-01-04 06:26:50 +01:00
|
|
|
t.Skip("PULUMI_API environment variable not set. Skipping this test.")
|
2017-10-31 02:23:20 +01:00
|
|
|
}
|
2018-01-04 06:26:50 +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")
|
|
|
|
|
2018-01-04 06:26:50 +01:00
|
|
|
out, err := e.RunCommandExpectError("pulumi", "stack", "init", "foo")
|
2017-10-31 02:23:20 +01:00
|
|
|
assert.Empty(t, out, "expected no stdout")
|
2018-01-04 06:26:50 +01:00
|
|
|
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.
|
2017-12-05 22:39:13 +01:00
|
|
|
os.Setenv(cloud.AccessTokenEnvVar, integration.TestAccountAccessToken)
|
2017-10-31 02:23:20 +01:00
|
|
|
e.RunCommand("pulumi", "login")
|
|
|
|
|
2018-01-04 06:26:50 +01:00
|
|
|
e.RunCommand("pulumi", "stack", "init", "foo")
|
2017-10-31 02:23:20 +01:00
|
|
|
e.RunCommand("pulumi", "stack", "rm", "foo", "--yes")
|
|
|
|
})
|
|
|
|
}
|