-
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.
- Loading branch information
1 parent
9a3d31f
commit ab7db4b
Showing
7 changed files
with
137 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Upload Go test results | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
directory: [ './HadesAPI', './HadesScheduler', './HadesCloneContainer' ] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22 | ||
- name: Install dependencies | ||
run: cd ${{ matrix.directory }} && go mod download | ||
- name: Test with Go | ||
run: go test ./${{ matrix.directory }}/... -json > TestResults-${{ matrix.directory }}.json | ||
- name: Upload Go test results | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: Go-results-${{ matrix.directory }} | ||
path: TestResults-${{ matrix.directory }}.json |
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,40 @@ | ||
package utils | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGigabyte(t *testing.T) { | ||
got, err := ParseMemoryLimit("1G") | ||
assert.Nil(t, err) | ||
assert.Equal(t, int64(1073741824), got) | ||
|
||
got, err = ParseMemoryLimit("2g") | ||
assert.Nil(t, err) | ||
assert.Equal(t, int64(2147483648), got) | ||
} | ||
|
||
func TestMegabyte(t *testing.T) { | ||
got, err := ParseMemoryLimit("1M") | ||
assert.Nil(t, err) | ||
assert.Equal(t, int64(1048576), got) | ||
|
||
got, err = ParseMemoryLimit("2m") | ||
assert.Nil(t, err) | ||
assert.Equal(t, int64(2097152), got) | ||
} | ||
|
||
func TestUnknownUnit(t *testing.T) { | ||
_, err := ParseMemoryLimit("1T") | ||
assert.NotNil(t, err) | ||
assert.Equal(t, "unknown unit: T", err.Error()) | ||
} | ||
|
||
func TestInvalidNumber(t *testing.T) { | ||
_, err := ParseMemoryLimit("abc") | ||
assert.NotNil(t, err) | ||
assert.IsType(t, &strconv.NumError{}, err) | ||
} |
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,33 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFindMemoryLimit(t *testing.T) { | ||
// Test case 1: x and y are empty | ||
result := FindMemoryLimit("", "") | ||
assert.Equal(t, 0, result) | ||
|
||
// Test case 2: x is valid, y is empty | ||
result = FindMemoryLimit("1G", "") | ||
assert.Equal(t, 1073741824, result) | ||
|
||
// Test case 3: x is empty, y is valid | ||
result = FindMemoryLimit("", "2M") | ||
assert.Equal(t, 2097152, result) | ||
|
||
// Test case 4: x and y are valid | ||
result = FindMemoryLimit("1G", "2M") | ||
assert.Equal(t, 2097152, result) | ||
|
||
// Test case 5: x is invalid, y is valid | ||
result = FindMemoryLimit("abc", "2M") | ||
assert.Equal(t, 2097152, result) | ||
|
||
// Test case 6: x is valid, y is invalid | ||
result = FindMemoryLimit("1G", "xyz") | ||
assert.Equal(t, 1073741824, result) | ||
} |
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,28 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPrioFromInt(t *testing.T) { | ||
tests := []struct { | ||
priority int | ||
expected string | ||
}{ | ||
{10, "critical"}, | ||
{5, "critical"}, | ||
{4, "high"}, | ||
{3, "normal"}, | ||
{2, "low"}, | ||
{1, "minimal"}, | ||
{0, "minimal"}, | ||
{-1, "minimal"}, | ||
} | ||
|
||
for _, test := range tests { | ||
got := PrioFromInt(test.priority) | ||
assert.Equal(t, test.expected, got) | ||
} | ||
} |