2019-04-06 15:44:04 +02:00
|
|
|
package compiler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-11-23 16:36:52 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-04-06 15:44:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParamsToEnv(t *testing.T) {
|
|
|
|
from := map[string]interface{}{
|
2021-12-07 02:13:02 +02:00
|
|
|
"skip": nil,
|
|
|
|
"string": "stringz",
|
|
|
|
"int": 1,
|
|
|
|
"float": 1.2,
|
|
|
|
"bool": true,
|
|
|
|
"slice": []int{1, 2, 3},
|
|
|
|
"map": map[string]string{"hello": "world"},
|
|
|
|
"complex": []struct{ Name string }{{"Jack"}, {"Jill"}},
|
|
|
|
"complex2": struct{ Name string }{"Jack"},
|
|
|
|
"from.address": "noreply@example.com",
|
2021-12-08 19:17:52 +02:00
|
|
|
"tags": stringsToInterface("next", "latest"),
|
|
|
|
"tag": stringsToInterface("next"),
|
2019-04-06 15:44:04 +02:00
|
|
|
}
|
|
|
|
want := map[string]string{
|
2021-12-07 02:13:02 +02:00
|
|
|
"PLUGIN_STRING": "stringz",
|
|
|
|
"PLUGIN_INT": "1",
|
|
|
|
"PLUGIN_FLOAT": "1.2",
|
|
|
|
"PLUGIN_BOOL": "true",
|
|
|
|
"PLUGIN_SLICE": "1,2,3",
|
|
|
|
"PLUGIN_MAP": `{"hello":"world"}`,
|
|
|
|
"PLUGIN_COMPLEX": `[{"name":"Jack"},{"name":"Jill"}]`,
|
|
|
|
"PLUGIN_COMPLEX2": `{"name":"Jack"}`,
|
|
|
|
"PLUGIN_FROM_ADDRESS": "noreply@example.com",
|
2021-12-08 19:17:52 +02:00
|
|
|
"PLUGIN_TAG": "next",
|
|
|
|
"PLUGIN_TAGS": "next,latest",
|
2019-04-06 15:44:04 +02:00
|
|
|
}
|
|
|
|
got := map[string]string{}
|
2021-11-23 16:36:52 +02:00
|
|
|
assert.NoError(t, paramsToEnv(from, got))
|
2021-12-04 14:23:33 +02:00
|
|
|
assert.EqualValues(t, want, got, "Problem converting plugin parameters to environment variables")
|
2019-04-06 15:44:04 +02:00
|
|
|
}
|
2021-12-08 19:17:52 +02:00
|
|
|
|
|
|
|
func stringsToInterface(val ...string) []interface{} {
|
|
|
|
res := make([]interface{}, len(val))
|
|
|
|
for i := range val {
|
|
|
|
res[i] = val[i]
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|