forked from AdguardTeam/AdGuardHome
-
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.
Pull request: 3457 fix service reload
Merge in DNS/adguard-home from 3457-darwin-svc-reload to master Closes AdguardTeam#3457. Squashed commit of the following: commit e3d6fbc Author: Eugene Burkov <e.burkov@adguard.com> Date: Wed Aug 18 00:52:39 2021 +0300 aghos: imp docs commit 220d37e Author: Eugene Burkov <e.burkov@adguard.com> Date: Tue Aug 17 15:45:52 2021 +0300 all: fix ps
- Loading branch information
1 parent
d2c9052
commit 550b179
Showing
9 changed files
with
220 additions
and
53 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 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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package aghos | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/AdguardTeam/AdGuardHome/internal/aghio" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestLargestLabeled(t *testing.T) { | ||
const ( | ||
comm = `command-name` | ||
nl = "\n" | ||
) | ||
|
||
testCases := []struct { | ||
name string | ||
data []byte | ||
wantPID int | ||
wantInstNum int | ||
}{{ | ||
name: "success", | ||
data: []byte(nl + | ||
` 123 not-a-` + comm + nl + | ||
` 321 ` + comm + nl, | ||
), | ||
wantPID: 321, | ||
wantInstNum: 1, | ||
}, { | ||
name: "several", | ||
data: []byte(nl + | ||
`1 ` + comm + nl + | ||
`5 /` + comm + nl + | ||
`2 /some/path/` + comm + nl + | ||
`4 ./` + comm + nl + | ||
`3 ` + comm + nl + | ||
`10 .` + comm + nl, | ||
), | ||
wantPID: 5, | ||
wantInstNum: 5, | ||
}, { | ||
name: "no_any", | ||
data: []byte(nl + | ||
`1 ` + `not-a-` + comm + nl + | ||
`2 ` + `not-a-` + comm + nl + | ||
`3 ` + `not-a-` + comm + nl, | ||
), | ||
wantPID: 0, | ||
wantInstNum: 0, | ||
}, { | ||
name: "weird_input", | ||
data: []byte(nl + | ||
`abc ` + comm + nl + | ||
`-1 ` + comm + nl, | ||
), | ||
wantPID: 0, | ||
wantInstNum: 0, | ||
}} | ||
|
||
for _, tc := range testCases { | ||
r := bytes.NewReader(tc.data) | ||
|
||
t.Run(tc.name, func(t *testing.T) { | ||
pid, instNum, err := parsePSOutput(r, comm) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, tc.wantPID, pid) | ||
assert.Equal(t, tc.wantInstNum, instNum) | ||
}) | ||
} | ||
|
||
t.Run("scanner_fail", func(t *testing.T) { | ||
lr, err := aghio.LimitReader(bytes.NewReader([]byte{1, 2, 3}), 0) | ||
require.NoError(t, err) | ||
|
||
target := &aghio.LimitReachedError{} | ||
_, _, err = parsePSOutput(lr, "") | ||
require.ErrorAs(t, err, &target) | ||
|
||
assert.EqualValues(t, 0, target.Limit) | ||
}) | ||
|
||
t.Run("ignore", func(t *testing.T) { | ||
r := bytes.NewReader([]byte(nl + | ||
`1 ` + comm + nl + | ||
`2 ` + comm + nl + | ||
`3` + comm + nl, | ||
)) | ||
|
||
pid, instances, err := parsePSOutput(r, comm, 1, 3) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, 2, pid) | ||
assert.Equal(t, 1, instances) | ||
}) | ||
} |
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