summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-06-09 10:46:39 +0300
committerValery Piashchynski <[email protected]>2021-06-09 10:46:39 +0300
commit8020cbb83afbaaf4ea4e0321b1b6c24d38332887 (patch)
tree024c9e3540b2f12e940b6b8cc88f8b2a0359a5e9
parent0d89115ffed997cc0e3e30681369bf3d2296f377 (diff)
- Add more tests
Signed-off-by: Valery Piashchynski <[email protected]>
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--plugins/server/command.go2
-rw-r--r--plugins/server/command_test.go22
4 files changed, 26 insertions, 4 deletions
diff --git a/go.mod b/go.mod
index cbde0875..026a7d7d 100644
--- a/go.mod
+++ b/go.mod
@@ -21,7 +21,7 @@ require (
github.com/spf13/viper v1.7.1
// SPIRAL ====
github.com/spiral/endure v1.0.1
- github.com/spiral/errors v1.0.10
+ github.com/spiral/errors v1.0.11
github.com/spiral/goridge/v3 v3.0.1
// ===========
github.com/stretchr/testify v1.7.0
diff --git a/go.sum b/go.sum
index f0b99003..3b4461a2 100644
--- a/go.sum
+++ b/go.sum
@@ -387,8 +387,8 @@ github.com/spiral/endure v1.0.1 h1:JHXHHPDiet5Cfx8i2KiC+ayqACmK5Sw0fxNE/QpIuWM=
github.com/spiral/endure v1.0.1/go.mod h1:+gB0/jI9tXdHgv0x4P9vXLER8fLgwt9a7aPi0QZeJHE=
github.com/spiral/errors v1.0.5/go.mod h1:SwMSZVdZkkJVgXNNafccqOaxWg0XPzVU/dEdUEInE0o=
github.com/spiral/errors v1.0.9/go.mod h1:SwMSZVdZkkJVgXNNafccqOaxWg0XPzVU/dEdUEInE0o=
-github.com/spiral/errors v1.0.10 h1:pmntzYn0iXZTQ/2OQRYDRR/x/SQWpPk/tQ6GflmbK5E=
-github.com/spiral/errors v1.0.10/go.mod h1:SwMSZVdZkkJVgXNNafccqOaxWg0XPzVU/dEdUEInE0o=
+github.com/spiral/errors v1.0.11 h1:TGG+t3mNouLuRW54Ph7nHo4X3u4WhbxqEQmnIybi7Go=
+github.com/spiral/errors v1.0.11/go.mod h1:SwMSZVdZkkJVgXNNafccqOaxWg0XPzVU/dEdUEInE0o=
github.com/spiral/goridge/v3 v3.0.1 h1:mWo6hVEDJV3nRwsszx9y262CtrLQNojbONF4ikvKCBg=
github.com/spiral/goridge/v3 v3.0.1/go.mod h1:rYfsBwigGneLgYJTIh5urotnH63I5O+p6ZcVq7xc1lY=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
diff --git a/plugins/server/command.go b/plugins/server/command.go
index 527cc224..a3752e7b 100644
--- a/plugins/server/command.go
+++ b/plugins/server/command.go
@@ -22,7 +22,7 @@ func (server *Plugin) scanCommand(cmd []string) error {
// try to stat
_, err := os.Stat(cmd[i])
if err != nil {
- return errors.E(op, err)
+ return errors.E(op, errors.FileNotFound, err)
}
// stat successful
diff --git a/plugins/server/command_test.go b/plugins/server/command_test.go
index 24051fba..d226ae9c 100644
--- a/plugins/server/command_test.go
+++ b/plugins/server/command_test.go
@@ -4,6 +4,7 @@ import (
"strings"
"testing"
+ "github.com/spiral/errors"
"github.com/stretchr/testify/assert"
)
@@ -11,4 +12,25 @@ func TestServerCommandChecker(t *testing.T) {
s := &Plugin{}
cmd1 := "php ../../tests/client.php"
assert.NoError(t, s.scanCommand(strings.Split(cmd1, " ")))
+
+ cmd2 := "C:/../../abcdef/client.php"
+ assert.Error(t, s.scanCommand(strings.Split(cmd2, " ")))
+
+ cmd3 := "sh ./script.sh"
+ err := s.scanCommand(strings.Split(cmd3, " "))
+ assert.Error(t, err)
+ if !errors.Is(errors.FileNotFound, err) {
+ t.Fatal("should be of filenotfound type")
+ }
+
+ cmd4 := "php ../../tests/client.php --option1 --option2"
+ err = s.scanCommand(strings.Split(cmd4, " "))
+ assert.NoError(t, err)
+
+ cmd5 := "php ../../tests/cluent.php --option1 --option2"
+ err = s.scanCommand(strings.Split(cmd5, " "))
+ assert.Error(t, err)
+ if !errors.Is(errors.FileNotFound, err) {
+ t.Fatal("should be of filenotfound type")
+ }
}