Skip to content
Draft
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
7 changes: 7 additions & 0 deletions cmd/workflow/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,16 @@ func (h *handler) Execute(ctx context.Context) 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")
}
}

func (h *handler) workflowExists() error {
workflow, err := h.wrc.GetWorkflow(common.HexToAddress(h.settings.Workflow.UserWorkflowSettings.WorkflowOwnerAddress), h.inputs.WorkflowName, h.inputs.WorkflowTag)
if err != nil {
Expand Down
44 changes: 44 additions & 0 deletions cmd/workflow/deploy/deploy_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package deploy

import (
"bytes"
"errors"
"io"
"math/big"
"os"
"strings"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -454,6 +457,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
Loading