2016-05-28 23:56:12 +00:00
|
|
|
package env_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
2023-10-12 11:34:50 +00:00
|
|
|
"testing"
|
2016-05-28 23:56:12 +00:00
|
|
|
|
2021-02-06 21:39:17 +00:00
|
|
|
. "github.com/Luzifer/go_helpers/v2/env"
|
2023-10-12 11:34:50 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-05-28 23:56:12 +00:00
|
|
|
)
|
|
|
|
|
2023-10-12 11:34:50 +00:00
|
|
|
func TestListToMap(t *testing.T) {
|
|
|
|
var (
|
|
|
|
list = []string{
|
|
|
|
"FIRST_KEY=firstvalue",
|
|
|
|
"SECOND_KEY=secondvalue",
|
|
|
|
"WEIRD=",
|
|
|
|
"NOVALUE",
|
|
|
|
"",
|
|
|
|
}
|
|
|
|
emap = map[string]string{
|
|
|
|
"FIRST_KEY": "firstvalue",
|
|
|
|
"SECOND_KEY": "secondvalue",
|
|
|
|
"WEIRD": "",
|
|
|
|
"NOVALUE": "",
|
|
|
|
}
|
|
|
|
)
|
2016-05-28 23:56:12 +00:00
|
|
|
|
2023-10-12 11:34:50 +00:00
|
|
|
assert.Equal(t, emap, ListToMap(list))
|
|
|
|
}
|
2016-05-28 23:56:12 +00:00
|
|
|
|
2023-10-12 11:34:50 +00:00
|
|
|
func TestMapToList(t *testing.T) {
|
|
|
|
var (
|
|
|
|
list = []string{
|
|
|
|
"FIRST_KEY=firstvalue",
|
|
|
|
"SECOND_KEY=secondvalue",
|
|
|
|
"WEIRD=",
|
|
|
|
}
|
|
|
|
emap = map[string]string{
|
|
|
|
"FIRST_KEY": "firstvalue",
|
|
|
|
"SECOND_KEY": "secondvalue",
|
|
|
|
"WEIRD": "",
|
|
|
|
}
|
|
|
|
)
|
2016-05-28 23:56:12 +00:00
|
|
|
|
2023-10-12 11:34:50 +00:00
|
|
|
l := MapToList(emap)
|
|
|
|
sort.Strings(l) // Workaround: The test needs the elements to be in same order
|
|
|
|
assert.Equal(t, list, l)
|
|
|
|
}
|