forked from furan917/MageComm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from akoova/upstream/v0.1.9-alignment
Upstream v0.1.9 alignment
- Loading branch information
Showing
17 changed files
with
277 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,95 @@ | ||
package cmd | ||
|
||
import ( | ||
"magecomm/messages/publisher" | ||
"strings" | ||
"testing" | ||
"magecomm/messages/publisher" | ||
"os" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type testMessagePublisher struct { | ||
Queue string | ||
MessageBody string | ||
AddCorrelationID string | ||
Queue string | ||
MessageBody string | ||
AddCorrelationID string | ||
} | ||
|
||
func (t *testMessagePublisher) Publish(messageBody string, queue string, AddCorrelationID string) (string, error) { | ||
t.Queue = queue | ||
t.MessageBody = messageBody | ||
t.AddCorrelationID = AddCorrelationID | ||
return "UniqueCorrelationID", nil | ||
t.Queue = queue | ||
t.MessageBody = messageBody | ||
t.AddCorrelationID = AddCorrelationID | ||
return "UniqueCorrelationID", nil | ||
} | ||
|
||
func TestMagerunCmd(t *testing.T) { | ||
testPublisher := &testMessagePublisher{} | ||
publisher.SetMessagePublisher(testPublisher) | ||
testPublisher := &testMessagePublisher{} | ||
publisher.SetMessagePublisher(testPublisher) | ||
|
||
testRootCmd := CreateTestRootCmd() | ||
testRootCmd.AddCommand(MagerunCmd) | ||
testArgs := []string{"magerun", "cache:clean"} | ||
testRootCmd.SetArgs(testArgs) | ||
_ = testRootCmd.Execute() | ||
// Create a pipe to simulate stdin | ||
r, w, err := os.Pipe() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
oldStdin := os.Stdin | ||
defer func() { os.Stdin = oldStdin }() | ||
os.Stdin = r | ||
|
||
assert.Equal(t, MageRunQueue, testPublisher.Queue) | ||
assert.Equal(t, "cache:clean", testPublisher.MessageBody) | ||
testRootCmd := CreateTestRootCmd() | ||
testRootCmd.AddCommand(MagerunCmd) | ||
testArgs := []string{"magerun", "cache:clean"} | ||
testRootCmd.SetArgs(testArgs) | ||
|
||
publisher.SetMessagePublisher(&publisher.DefaultMessagePublisher{}) | ||
done := make(chan struct{}) | ||
go func() { | ||
_ = testRootCmd.Execute() | ||
close(done) | ||
}() | ||
|
||
// Simulate stop command for listening to return value | ||
time.Sleep(1 * time.Second) | ||
_, _ = w.Write([]byte("\n")) | ||
<-done | ||
|
||
assert.Equal(t, MageRunQueue, testPublisher.Queue) | ||
assert.Equal(t, "cache:clean", testPublisher.MessageBody) | ||
|
||
publisher.SetMessagePublisher(&publisher.DefaultMessagePublisher{}) | ||
} | ||
|
||
func TestMagerunCmdBlocksBannedCmd(t *testing.T) { | ||
testPublisher := &testMessagePublisher{} | ||
publisher.SetMessagePublisher(testPublisher) | ||
testPublisher := &testMessagePublisher{} | ||
publisher.SetMessagePublisher(testPublisher) | ||
|
||
// Create a pipe to simulate stdin | ||
r, w, err := os.Pipe() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
oldStdin := os.Stdin | ||
defer func() { os.Stdin = oldStdin }() | ||
os.Stdin = r | ||
|
||
testRootCmd := CreateTestRootCmd() | ||
testRootCmd.AddCommand(MagerunCmd) | ||
testArgs := []string{"magerun", "module:enable", "Vendor_Module"} | ||
testRootCmd.SetArgs(testArgs) | ||
|
||
done := make(chan struct{}) | ||
var executeErr error | ||
go func() { | ||
executeErr = testRootCmd.Execute() | ||
close(done) | ||
}() | ||
|
||
testRootCmd := CreateTestRootCmd() | ||
testRootCmd.AddCommand(MagerunCmd) | ||
testArgs := []string{"magerun", "module:enable", "Vendor_Module"} | ||
testRootCmd.SetArgs(testArgs) | ||
err := testRootCmd.Execute() | ||
// Simulate stop command for listening to return value | ||
time.Sleep(1 * time.Second) | ||
_, _ = w.Write([]byte("\n")) | ||
<-done | ||
|
||
assert.True(t, strings.Contains(err.Error(), "the command 'module:enable' is not allowed")) | ||
assert.NotNil(t, executeErr) | ||
assert.True(t, strings.Contains(executeErr.Error(), "`module:enable` Command not allowed")) | ||
|
||
publisher.SetMessagePublisher(&publisher.DefaultMessagePublisher{}) | ||
publisher.SetMessagePublisher(&publisher.DefaultMessagePublisher{}) | ||
} |
Oops, something went wrong.