Skip to content

Commit

Permalink
Add OS Version check tests
Browse files Browse the repository at this point in the history
  • Loading branch information
surik committed Jan 19, 2024
1 parent 90db83e commit 865a028
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
4 changes: 2 additions & 2 deletions management/server/posture/os_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func (c *OSVersionCheck) Check(peer nbpeer.Peer) error {
case "ios":
return checkMinVersion(peerGoOS, peer.Meta.Core, c.Ios)
case "linux":
return checkMinKernelVersion(peerGoOS, peer.Meta.Core, c.Linux)
return checkMinKernelVersion(peerGoOS, peer.Meta.KernelVersion, c.Linux)
case "windows":
return checkMinKernelVersion(peerGoOS, peer.Meta.Core, c.Windows)
return checkMinKernelVersion(peerGoOS, peer.Meta.KernelVersion, c.Windows)
}
return nil
}
Expand Down
75 changes: 75 additions & 0 deletions management/server/posture/os_version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package posture

import (
"testing"

"github.com/netbirdio/netbird/management/server/peer"

"github.com/stretchr/testify/assert"
)

func TestOSVersionCheck_Check(t *testing.T) {
tests := []struct {
name string
input peer.Peer
check OSVersionCheck
wantErr bool
}{
{
name: "Valid Peer Linux Kernel version",
input: peer.Peer{
Meta: peer.PeerSystemMeta{
GoOS: "linux",
KernelVersion: "6.1.1",
},
},
check: OSVersionCheck{
Linux: &MinKernelVersionCheck{
MinKernelVersion: "6.0.0",
},
},
wantErr: false,
},
{
name: "Valid Peer macOS version",
input: peer.Peer{
Meta: peer.PeerSystemMeta{
GoOS: "darwin",
Core: "14.2.1",
},
},
check: OSVersionCheck{
Darwin: &MinVersionCheck{
MinVersion: "13",
},
},
wantErr: false,
},
{
name: "No valid Peer macOS version",
input: peer.Peer{
Meta: peer.PeerSystemMeta{
GoOS: "darwin",
Core: "14.2.1",
},
},
check: OSVersionCheck{
Darwin: &MinVersionCheck{
MinVersion: "15",
},
},
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.check.Check(tt.input)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}

0 comments on commit 865a028

Please sign in to comment.