-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add utils test and CI action (#44)
* chore: add utils test and CI action * chore: fixed linting
- Loading branch information
1 parent
e572d45
commit 77d2c30
Showing
7 changed files
with
114 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ main | |
dist/ | ||
grafana-interacter | ||
**/.DS_Store | ||
cover.out |
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 |
---|---|---|
|
@@ -43,3 +43,4 @@ linters: | |
- goimports | ||
- mnd | ||
- perfsprint | ||
- testpackage |
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,75 @@ | ||
package generic | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFilter(t *testing.T) { | ||
t.Parallel() | ||
|
||
array := []int64{1, 2, 3} | ||
|
||
filtered := Filter(array, func(value int64) bool { | ||
return value == 2 | ||
}) | ||
|
||
assert.Len(t, filtered, 1) | ||
assert.Equal(t, int64(2), filtered[0]) | ||
} | ||
|
||
func TestMap(t *testing.T) { | ||
t.Parallel() | ||
|
||
array := []int64{1, 2, 3} | ||
|
||
filtered := Map(array, func(value int64) int64 { | ||
return value * 2 | ||
}) | ||
|
||
assert.Len(t, filtered, 3) | ||
assert.Equal(t, int64(2), filtered[0]) | ||
assert.Equal(t, int64(4), filtered[1]) | ||
assert.Equal(t, int64(6), filtered[2]) | ||
} | ||
|
||
func TestFind(t *testing.T) { | ||
t.Parallel() | ||
|
||
array := []int64{1, 2, 3} | ||
|
||
_, found := Find(array, func(value int64) bool { | ||
return value == 2 | ||
}) | ||
require.True(t, found) | ||
|
||
value, found2 := Find(array, func(value int64) bool { | ||
return value == 4 | ||
}) | ||
require.Nil(t, value) | ||
require.False(t, found2) | ||
} | ||
|
||
func TestMergeMaps(t *testing.T) { | ||
t.Parallel() | ||
|
||
map1 := map[string]string{"a": "1"} | ||
map2 := map[string]string{"b": "2"} | ||
|
||
resultMap := MergeMaps(map1, map2) | ||
require.Equal(t, map[string]string{"a": "1", "b": "2"}, resultMap) | ||
} | ||
|
||
func TestSplitArrayIntoChunks(t *testing.T) { | ||
t.Parallel() | ||
|
||
array := []int{1, 2, 3, 4, 5, 6, 7, 8, 9} | ||
|
||
chunks1 := SplitArrayIntoChunks(array, 3) | ||
require.Equal(t, [][]int{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, chunks1) | ||
|
||
chunks2 := SplitArrayIntoChunks(array, 5) | ||
require.Equal(t, [][]int{{1, 2, 3, 4, 5}, {6, 7, 8, 9}}, chunks2) | ||
} |
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,12 @@ | ||
package normalize | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNormalizeString(t *testing.T) { | ||
t.Parallel() | ||
require.Equal(t, "abc", NormalizeString("abcабв")) | ||
} |