feat(autoapi): add IsSelectStack404Error and IsCreateStack409Error
This commit is contained in:
parent
3f445be494
commit
51c235352c
|
@ -2,6 +2,10 @@ CHANGELOG
|
|||
=========
|
||||
|
||||
## HEAD (Unreleased)
|
||||
|
||||
- Add IsSelectStack404Error and IsCreateStack409Error
|
||||
[#5255](https://github.com/pulumi/pulumi/pull/5255)
|
||||
|
||||
- Add internal scaffolding for cross-language components.
|
||||
[#5280](https://github.com/pulumi/pulumi/pull/5280)
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package auto
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
@ -50,6 +51,28 @@ func IsConcurrentUpdateError(e error) bool {
|
|||
return strings.Contains(ae.stderr, "[409] Conflict: Another update is currently in progress.")
|
||||
}
|
||||
|
||||
// IsSelectStack404Error returns true if the error was a result of selecting a stack that does not exist.
|
||||
func IsSelectStack404Error(e error) bool {
|
||||
ae, ok := e.(autoError)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
regex := regexp.MustCompile(`no stack named.*found`)
|
||||
return regex.MatchString(ae.stderr)
|
||||
}
|
||||
|
||||
// IsCreateStack409Error returns true if the error was a result of creating a stack that already exists.
|
||||
func IsCreateStack409Error(e error) bool {
|
||||
ae, ok := e.(autoError)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
regex := regexp.MustCompile(`stack.*already exists`)
|
||||
return regex.MatchString(ae.stderr)
|
||||
}
|
||||
|
||||
// IsCompilationError returns true if the program failed at the build/run step (only Typescript, Go, .NET)
|
||||
func IsCompilationError(e error) bool {
|
||||
as, ok := e.(autoError)
|
||||
|
|
|
@ -166,6 +166,59 @@ func TestCompilationErrorGo(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSelectStack404Error(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
sName := fmt.Sprintf("int_test%d", rangeIn(10000000, 99999999))
|
||||
fqsn := FullyQualifiedStackName(pulumiOrg, "testproj", sName)
|
||||
|
||||
// initialize
|
||||
pDir := filepath.Join(".", "test", "testproj")
|
||||
opts := []LocalWorkspaceOption{WorkDir(pDir)}
|
||||
w, err := NewLocalWorkspace(ctx, opts...)
|
||||
if err != nil {
|
||||
t.Errorf("failed to initialize workspace, err: %v", err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
// attempt to select stack that has not been created.
|
||||
_, err = SelectStack(ctx, fqsn, w)
|
||||
assert.NotNil(t, err)
|
||||
assert.True(t, IsSelectStack404Error(err))
|
||||
}
|
||||
|
||||
func TestCreateStack409Error(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
sName := fmt.Sprintf("int_test%d", rangeIn(10000000, 99999999))
|
||||
fqsn := FullyQualifiedStackName(pulumiOrg, "testproj", sName)
|
||||
|
||||
// initialize first stack
|
||||
pDir := filepath.Join(".", "test", "testproj")
|
||||
s, err := NewStackLocalSource(ctx, fqsn, pDir)
|
||||
if err != nil {
|
||||
t.Errorf("failed to initialize stack, err: %v", err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
defer func() {
|
||||
// -- pulumi stack rm --
|
||||
err = s.Workspace().RemoveStack(ctx, s.Name())
|
||||
assert.Nil(t, err, "failed to remove stack. Resources have leaked.")
|
||||
}()
|
||||
|
||||
// initialize workspace for dupe stack
|
||||
opts := []LocalWorkspaceOption{WorkDir(pDir)}
|
||||
w, err := NewLocalWorkspace(ctx, opts...)
|
||||
if err != nil {
|
||||
t.Errorf("failed to initialize workspace, err: %v", err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
// attempt to create a dupe stack.
|
||||
_, err = NewStack(ctx, fqsn, w)
|
||||
assert.NotNil(t, err)
|
||||
assert.True(t, IsCreateStack409Error(err))
|
||||
}
|
||||
|
||||
func TestCompilationErrorDotnet(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
sName := fmt.Sprintf("int_test%d", rangeIn(10000000, 99999999))
|
||||
|
|
|
@ -102,6 +102,26 @@ func ExampleIsConcurrentUpdateError() {
|
|||
}
|
||||
}
|
||||
|
||||
func ExampleIsSelectStack404Error() {
|
||||
ctx := context.Background()
|
||||
s, _ := NewStackLocalSource(ctx, "o/p/s", filepath.Join(".", "stack", "notfound", "program"))
|
||||
_, err := s.Up(ctx)
|
||||
if err != nil && IsSelectStack404Error(err) {
|
||||
// stack "o/p/s" does not exist
|
||||
// implement some retry logic here...
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleIsCreateStack409Error() {
|
||||
ctx := context.Background()
|
||||
s, _ := NewStackLocalSource(ctx, "o/p/s", filepath.Join(".", "stack", "alreadyexists", "program"))
|
||||
_, err := s.Up(ctx)
|
||||
if err != nil && IsCreateStack409Error(err) {
|
||||
// stack "o/p/s" already exists
|
||||
// implement some retry logic here...
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleIsRuntimeError() {
|
||||
ctx := context.Background()
|
||||
s, _ := NewStackLocalSource(ctx, "o/p/s", filepath.Join(".", "runtime", "error", "program"))
|
||||
|
|
Loading…
Reference in a new issue