-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: support update and delete env
Signed-off-by: Michael Wan <[email protected]>
- Loading branch information
Showing
4 changed files
with
153 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package opts | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ParseEnv parses the env param of container. | ||
func ParseEnv(env []string) (map[string]string, error) { | ||
results := make(map[string]string) | ||
for _, e := range env { | ||
fields := strings.SplitN(e, "=", 2) | ||
if len(fields) != 2 { | ||
return nil, fmt.Errorf("invalid env %s: env must be in format of key=value", e) | ||
} | ||
results[fields[0]] = fields[1] | ||
} | ||
|
||
return results, nil | ||
} | ||
|
||
// ValidateEnv verifies the correct of env | ||
func ValidateEnv(map[string]string) error { | ||
// TODO | ||
|
||
return nil | ||
} |
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,34 @@ | ||
package opts | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestParseEnv(t *testing.T) { | ||
type args struct { | ||
env []string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string]string | ||
wantErr bool | ||
}{ | ||
// TODO: Add test cases. | ||
{name: "test1", args: args{env: []string{"foo=bar"}}, want: map[string]string{"foo": "bar"}, wantErr: false}, | ||
{name: "test2", args: args{env: []string{"ErrorInfo"}}, want: nil, wantErr: true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ParseEnv(tt.args.env) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ParseEnv() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ParseEnv() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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