Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions cmd/workflow/deploy/deploy_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package deploy

import (
"bytes"
"context"
"encoding/hex"
"encoding/json"
Expand All @@ -9,6 +10,8 @@ import (
"math/big"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -740,6 +743,47 @@ func (f fakeUserDonLimitClient) GetWorkflowListByOwnerAndName(common.Address, st
return f.workflowsByOwnerName, nil
}

func TestWarnExistingPausedWorkflowUpdate(t *testing.T) {
// Do not use t.Parallel: stderr redirection uses package-global os.Stderr.

captureStderr := func(f func()) string {
t.Helper()
old := os.Stderr
r, w, err := os.Pipe()
require.NoError(t, err)
os.Stderr = w

f()

require.NoError(t, w.Close())
os.Stderr = old

var buf bytes.Buffer
_, copyErr := io.Copy(&buf, r)
require.NoError(t, copyErr)
require.NoError(t, r.Close())
return buf.String()
}

t.Run("no output when status is nil", func(t *testing.T) {
out := captureStderr(func() { warnIfPausedWorkflowUpdate(nil) })
assert.Empty(t, strings.TrimSpace(out))
})

t.Run("no output when workflow is active", func(t *testing.T) {
active := workflowStatusActive
out := captureStderr(func() { warnIfPausedWorkflowUpdate(&active) })
assert.Empty(t, strings.TrimSpace(out))
})

t.Run("prints warning when workflow is paused", func(t *testing.T) {
paused := workflowStatusPaused
out := captureStderr(func() { warnIfPausedWorkflowUpdate(&paused) })
assert.Contains(t, out, "Your workflow is paused")
assert.Contains(t, out, "and has been updated")
})
}

func TestCheckUserDonLimitBeforeDeploy(t *testing.T) {
owner := common.HexToAddress(chainsim.TestAddress)
donFamily := "test-don"
Expand Down
1 change: 1 addition & 0 deletions cmd/workflow/deploy/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

const (
workflowStatusActive = uint8(0)
workflowStatusPaused = uint8(1)
workflowListPageSize = int64(200)
)

Expand Down
7 changes: 7 additions & 0 deletions cmd/workflow/deploy/registry_deploy_strategy_onchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,16 @@ func (a *onchainRegistryDeployStrategy) Upsert() error {
if err := h.upsert(); err != nil {
return fmt.Errorf("failed to register workflow: %w", err)
}
warnIfPausedWorkflowUpdate(h.existingWorkflowStatus)
return nil
}

func warnIfPausedWorkflowUpdate(status *uint8) {
if status != nil && *status == workflowStatusPaused {
ui.Warning("Your workflow is paused and has been updated")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This could be a little more clear. e.g. your workflow has been updated and remains in a paused state

}
}

func (h *handler) workflowExists() error {
workflow, err := h.wrc.GetWorkflow(common.HexToAddress(h.inputs.WorkflowOwner), h.inputs.WorkflowName, h.inputs.WorkflowTag)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/workflow/deploy/registry_deploy_strategy_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (a *privateRegistryDeployStrategy) Upsert() error {
if result.Owner != "" {
ui.Dim(fmt.Sprintf(" Owner: %s", result.Owner))
}
warnIfPausedWorkflowUpdate(h.existingWorkflowStatus)

return nil
}
Expand Down
Loading