Add single Unix/Windows path check in process tests

This commit is contained in:
bcmmbaga
2024-03-14 14:32:55 +03:00
parent cc60df7805
commit 9db450d599
2 changed files with 62 additions and 2 deletions

View File

@@ -27,14 +27,14 @@ func (p *ProcessCheck) Check(peer nbpeer.Peer) (bool, error) {
switch peer.Meta.GoOS {
case "darwin", "linux":
for _, process := range p.Processes {
if !slices.Contains(peerActiveProcesses, process.Path) {
if process.Path == "" || !slices.Contains(peerActiveProcesses, process.Path) {
return false, nil
}
}
return true, nil
case "windows":
for _, process := range p.Processes {
if !slices.Contains(peerActiveProcesses, process.WindowsPath) {
if process.WindowsPath == "" || !slices.Contains(peerActiveProcesses, process.WindowsPath) {
return false, nil
}
}

View File

@@ -35,6 +35,26 @@ func TestProcessCheck_Check(t *testing.T) {
wantErr: false,
isValid: true,
},
{
name: "darwin with windows process paths",
input: peer.Peer{
Meta: peer.PeerSystemMeta{
GoOS: "darwin",
Processes: []peer.Process{
{Path: "process1"},
{Path: "process2"},
},
},
},
check: ProcessCheck{
Processes: []Process{
{WindowsPath: "process1"},
{WindowsPath: "process2"},
},
},
wantErr: false,
isValid: false,
},
{
name: "linux with matching processes",
input: peer.Peer{
@@ -55,6 +75,26 @@ func TestProcessCheck_Check(t *testing.T) {
wantErr: false,
isValid: true,
},
{
name: "linux with windows process paths",
input: peer.Peer{
Meta: peer.PeerSystemMeta{
GoOS: "linux",
Processes: []peer.Process{
{Path: "process1"},
{Path: "process2"},
},
},
},
check: ProcessCheck{
Processes: []Process{
{WindowsPath: "process1"},
{WindowsPath: "process2"},
},
},
wantErr: false,
isValid: false,
},
{
name: "linux with non-matching processes",
input: peer.Peer{
@@ -95,6 +135,26 @@ func TestProcessCheck_Check(t *testing.T) {
wantErr: false,
isValid: true,
},
{
name: "windows with darwin process paths",
input: peer.Peer{
Meta: peer.PeerSystemMeta{
GoOS: "windows",
Processes: []peer.Process{
{Path: "process1"},
{Path: "process2"},
},
},
},
check: ProcessCheck{
Processes: []Process{
{Path: "process1"},
{Path: "process2"},
},
},
wantErr: false,
isValid: false,
},
{
name: "windows with non-matching processes",
input: peer.Peer{