Skip to content

Commit

Permalink
fix: handle empty logs= value
Browse files Browse the repository at this point in the history
  • Loading branch information
smlx committed Jul 21, 2023
1 parent 508f866 commit 72fcc6d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/sshserver/connectionparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var (
serviceRegex = regexp.MustCompile(`^service=(.+)`)
containerRegex = regexp.MustCompile(`^container=(.+)`)
logsRegex = regexp.MustCompile(`^logs=(.+)`)
logsRegex = regexp.MustCompile(`^logs=(.+)?`)
tailLinesRegex = regexp.MustCompile(`^tailLines=(\d+)$`)
)

Expand Down Expand Up @@ -117,6 +117,8 @@ func parseLogsArg(service, logs string, cmd []string) (bool, int64, error) {
for _, arg := range strings.Split(logs, ",") {
matches := tailLinesRegex.FindStringSubmatch(arg)
switch {
case arg == "":
// ignore empty arg
case arg == "follow":
follow = true
case len(matches) == 2:
Expand Down
16 changes: 16 additions & 0 deletions internal/sshserver/connectionparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ func TestParseConnectionParams(t *testing.T) {
args: []string{"drush do something"},
},
},
"service, container and empty logs params": {
input: []string{"service=nginx", "container=php", "logs=", "drush do something"},
expect: parsedParams{
service: "nginx",
container: "php",
logs: "",
args: []string{"drush do something"},
},
},
"service, container and logs params (wrong order)": {
input: []string{"service=nginx", "logs=follow", "container=php", "drush do something"},
expect: parsedParams{
Expand Down Expand Up @@ -225,6 +234,13 @@ func TestValidateConnectionParams(t *testing.T) {
err: sshserver.ErrInvalidLogsValue,
},
},
"empty logs args - rely on default": {
input: parsedParams{
service: "nginx-php",
logs: "",
},
expect: result{},
},
}
for name, tc := range testCases {
t.Run(name, func(tt *testing.T) {
Expand Down

0 comments on commit 72fcc6d

Please sign in to comment.