diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index c819eb95f..3123c2607 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 @@ -23,12 +23,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - name: Setup up python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 - name: Install tox run: pip install tox @@ -44,16 +44,16 @@ jobs: go-version: ["1.19", "1.20"] steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: go-version: ${{ matrix.go-version }} - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: | ~/.cache/go-build @@ -95,14 +95,14 @@ jobs: run: find /tmp/receptor-testing -name controlsock -delete - name: Artifact receptor data - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: ${{ failure() }} with: name: test-logs path: /tmp/receptor-testing - name: Archive receptor binary - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: receptor path: /usr/local/bin/receptor @@ -115,12 +115,12 @@ jobs: python-version: [3.8, 3.9] steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - name: Download receptor - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: receptor path: /usr/local/bin/ @@ -129,7 +129,7 @@ jobs: run: sudo chmod a+x /usr/local/bin/receptor - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} @@ -143,12 +143,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 - name: Install python dependencies run: pip install build diff --git a/pkg/utils/sysinfo_test.go b/pkg/utils/sysinfo_test.go new file mode 100644 index 000000000..ba23cf743 --- /dev/null +++ b/pkg/utils/sysinfo_test.go @@ -0,0 +1,48 @@ +package utils_test + +import ( + "os/exec" + "runtime" + "strconv" + "strings" + "testing" + + "github.com/ansible/receptor/pkg/utils" +) + +func TestGetSysCPUCount(t *testing.T) { + got := utils.GetSysCPUCount() + if got <= 0 { + t.Errorf("Non-positive CPU count: %d\n", got) + } + + if runtime.GOOS == "linux" { + commandOutput, _ := exec.Command("nproc").CombinedOutput() + + commandOutputWithout := strings.TrimSpace(string(commandOutput)) + want, _ := strconv.Atoi(commandOutputWithout) + + if got != want { + t.Errorf("Expected CPU count: %d, got %d\n", want, got) + } + } +} + +func TestGetSysMemoryMiB(t *testing.T) { + got := utils.GetSysMemoryMiB() + if got <= 0 { + t.Errorf("Non-positive Memory: %d\n", got) + } + + if runtime.GOOS == "linux" { + commandOutput, _ := exec.Command("sed", "-n", "s/^MemTotal:[[:space:]]*\\([[:digit:]]*\\).*/\\1/p", "/proc/meminfo").CombinedOutput() + + commandOutputWithout := strings.TrimSpace(string(commandOutput)) + wantKb, _ := strconv.ParseUint(commandOutputWithout, 10, 64) + + want := wantKb / 1024 + if got != want { + t.Errorf("Expected Memory: %d, got %d\n", want, got) + } + } +}