2024-01-13 14:39:40 +00:00
|
|
|
package grm
|
2021-11-02 18:19:31 +00:00
|
|
|
|
2021-11-07 13:05:45 +00:00
|
|
|
import (
|
2024-01-13 14:39:40 +00:00
|
|
|
"gitlab.com/revalus/grm/internal/config"
|
2021-11-07 13:05:45 +00:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
2021-11-02 18:19:31 +00:00
|
|
|
|
|
|
|
func TestGetFileExtension(t *testing.T) {
|
|
|
|
|
|
|
|
toTest := map[string]string{
|
|
|
|
"myYamlFile.yaml": "yaml",
|
|
|
|
"myTxtFile.txt": "txt",
|
|
|
|
"myJsonFile.json": "json",
|
|
|
|
}
|
|
|
|
|
|
|
|
for key, value := range toTest {
|
2022-12-10 22:47:59 +00:00
|
|
|
result, err := getFileExtension(key)
|
2021-11-02 18:19:31 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if result != value {
|
|
|
|
t.Errorf("Expected to get %v, instead of this got %v", value, result)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-06-13 19:19:04 +00:00
|
|
|
func TestErrorInGetExtensionFile(t *testing.T) {
|
2021-11-02 18:19:31 +00:00
|
|
|
|
2022-12-10 22:47:59 +00:00
|
|
|
result, err := getFileExtension("test")
|
2021-11-02 18:19:31 +00:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Expected to get error, instead of this got result %v", result)
|
|
|
|
}
|
2021-11-07 13:05:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsItemInSlice(t *testing.T) {
|
|
|
|
testedSlice := []string{"1", "2", "3", "4", "5"}
|
|
|
|
|
|
|
|
result := checkIsItemInSlice("0", testedSlice)
|
|
|
|
if result {
|
|
|
|
t.Error("Expected to get false as result")
|
|
|
|
}
|
|
|
|
|
|
|
|
result = checkIsItemInSlice("1", testedSlice)
|
|
|
|
if !result {
|
|
|
|
t.Error("Expected to get true as result")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsAnyInSlice(t *testing.T) {
|
|
|
|
testedSlice := []string{"1", "2", "3", "4", "5"}
|
2021-11-02 18:19:31 +00:00
|
|
|
|
2021-11-07 13:05:45 +00:00
|
|
|
result := checkAnyOfItemInSlice([]string{"0", "10"}, testedSlice)
|
|
|
|
if result {
|
|
|
|
t.Error("Expected to get false as result")
|
|
|
|
}
|
|
|
|
|
|
|
|
result = checkAnyOfItemInSlice([]string{"0", "5"}, testedSlice)
|
|
|
|
if !result {
|
|
|
|
t.Error("Expected to get true as result")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReverseStringsSlice(t *testing.T) {
|
|
|
|
testedSlice := []config.RepositoryConfig{
|
|
|
|
{Name: "test1"},
|
|
|
|
{Name: "test2"},
|
|
|
|
{Name: "test3"},
|
|
|
|
}
|
|
|
|
expectedResult := []config.RepositoryConfig{
|
|
|
|
{Name: "test3"},
|
|
|
|
{Name: "test2"},
|
|
|
|
{Name: "test1"},
|
|
|
|
}
|
|
|
|
result := reverseRepositoryConfigs(testedSlice)
|
|
|
|
if !reflect.DeepEqual(result, expectedResult) {
|
|
|
|
t.Errorf("Expected to get \"%#v\", instead of this got \"%#v\"", expectedResult, result)
|
|
|
|
}
|
2021-11-02 18:19:31 +00:00
|
|
|
}
|