forked from kyma-project/cli
-
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.
Support args while building from dockerfile (kyma-project#2273)
- Loading branch information
Showing
4 changed files
with
97 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type Map struct { | ||
Values map[string]string | ||
} | ||
|
||
func (em *Map) String() string { | ||
values := make([]string, len(em.Values)) | ||
|
||
index := 0 | ||
for key, value := range em.Values { | ||
values[index] = fmt.Sprintf("%s=%s", key, value) | ||
index++ | ||
} | ||
|
||
return strings.Join(values, ",") | ||
} | ||
|
||
func (em *Map) Set(value string) error { | ||
elems := strings.Split(value, "=") | ||
if len(elems) != 2 { | ||
return fmt.Errorf("failed to parse value '%s', should be in format KEY=VALUE", value) | ||
} | ||
|
||
if em.Values == nil { | ||
em.Values = map[string]string{} | ||
} | ||
|
||
em.Values[elems[0]] = elems[1] | ||
return nil | ||
} | ||
|
||
func (em *Map) Type() string { | ||
return "stringArray" | ||
} | ||
|
||
func (em *Map) GetNullableMap() map[string]*string { | ||
nullableMap := map[string]*string{} | ||
for key, value := range em.Values { | ||
v := value | ||
nullableMap[key] = &v | ||
} | ||
|
||
return nullableMap | ||
} |
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 types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"k8s.io/utils/ptr" | ||
) | ||
|
||
func TestEnvMap(t *testing.T) { | ||
t.Run("set values", func(t *testing.T) { | ||
envMap := Map{} | ||
require.NoError(t, envMap.Set("TEST1=1")) | ||
require.NoError(t, envMap.Set("TEST2=2")) | ||
|
||
expectedMap := map[string]string{ | ||
"TEST1": "1", | ||
"TEST2": "2", | ||
} | ||
expectedNullableMap := map[string]*string{ | ||
"TEST1": ptr.To("1"), | ||
"TEST2": ptr.To("2"), | ||
} | ||
require.Equal(t, expectedMap, envMap.Values) | ||
require.Equal(t, expectedNullableMap, envMap.GetNullableMap()) | ||
require.Equal(t, "TEST1=1,TEST2=2", envMap.String()) | ||
}) | ||
|
||
t.Run("get type", func(t *testing.T) { | ||
envMap := Map{} | ||
require.Equal(t, "stringArray", envMap.Type()) | ||
}) | ||
|
||
t.Run("set values validation error", func(t *testing.T) { | ||
envMap := Map{} | ||
|
||
err := envMap.Set("not valid value") | ||
require.ErrorContains(t, err, "failed to parse value 'not valid value', should be in format KEY=VALUE") | ||
}) | ||
} |
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