Skip to content

Commit 8bf9e55

Browse files
committed
Add tests for complex env values
1 parent c27cef3 commit 8bf9e55

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

plugin_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,3 +1026,64 @@ func TestPluginShouldPreserveDependsOnArray(t *testing.T) {
10261026
t.Fatalf("plugin diff (-want +got):\n%s", diff)
10271027
}
10281028
}
1029+
1030+
func TestPluginEnvWithEqualsSignsAndSpacesInValues(t *testing.T) {
1031+
param := `[{
1032+
"github.com/buildkite-plugins/monorepo-diff-buildkite-plugin#commit": {
1033+
"env": [
1034+
"EXTRA_BUILD_ARGS=--build-arg=ARG1=value1",
1035+
"QUOTED_ARGS=\"--build-arg=ARG1=value1\"",
1036+
"SPACE_VALUE=value with spaces",
1037+
"COMPLEX=\"--opt1=val1 --opt2=val2\""
1038+
],
1039+
"watch": [
1040+
{
1041+
"path": "services/",
1042+
"config": {
1043+
"command": "echo test"
1044+
}
1045+
}
1046+
]
1047+
}
1048+
}]`
1049+
1050+
got, err := initializePlugin(param)
1051+
assert.NoError(t, err)
1052+
1053+
expected := Plugin{
1054+
Diff: "git diff --name-only HEAD~1",
1055+
Wait: false,
1056+
LogLevel: "info",
1057+
Interpolation: true,
1058+
Env: map[string]string{
1059+
"EXTRA_BUILD_ARGS": "--build-arg=ARG1=value1",
1060+
"QUOTED_ARGS": "\"--build-arg=ARG1=value1\"",
1061+
"SPACE_VALUE": "value with spaces",
1062+
"COMPLEX": "\"--opt1=val1 --opt2=val2\"",
1063+
},
1064+
Watch: []WatchConfig{
1065+
{
1066+
Paths: []string{"services/"},
1067+
Step: Step{
1068+
Command: "echo test",
1069+
Env: map[string]string{
1070+
"EXTRA_BUILD_ARGS": "--build-arg=ARG1=value1",
1071+
"QUOTED_ARGS": "\"--build-arg=ARG1=value1\"",
1072+
"SPACE_VALUE": "value with spaces",
1073+
"COMPLEX": "\"--opt1=val1 --opt2=val2\"",
1074+
},
1075+
},
1076+
},
1077+
},
1078+
}
1079+
1080+
if diff := cmp.Diff(expected, got); diff != "" {
1081+
t.Fatalf("plugin diff (-want +got):\n%s", diff)
1082+
}
1083+
1084+
// Explicitly verify the env values are correct
1085+
assert.Equal(t, "--build-arg=ARG1=value1", got.Env["EXTRA_BUILD_ARGS"])
1086+
assert.Equal(t, "\"--build-arg=ARG1=value1\"", got.Env["QUOTED_ARGS"])
1087+
assert.Equal(t, "value with spaces", got.Env["SPACE_VALUE"])
1088+
assert.Equal(t, "\"--opt1=val1 --opt2=val2\"", got.Env["COMPLEX"])
1089+
}

0 commit comments

Comments
 (0)