From f21fd563e8a11821a6d16b8e8dfc80057f486639 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 1 Nov 2014 11:28:59 -0700 Subject: [PATCH 1/2] fixes #639 --- shared/build/buildfile/buildfile.go | 2 +- shared/build/buildfile/buildfile_test.go | 2 +- shared/build/script/script.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shared/build/buildfile/buildfile.go b/shared/build/buildfile/buildfile.go index da56fb6f..c0846380 100644 --- a/shared/build/buildfile/buildfile.go +++ b/shared/build/buildfile/buildfile.go @@ -43,7 +43,7 @@ func (b *Buildfile) WriteComment(comment string) { // are not echoed back to the console, and are // kept private by default. func (b *Buildfile) WriteEnv(key, value string) { - b.WriteString(fmt.Sprintf("export %s=%s\n", key, value)) + b.WriteString(fmt.Sprintf("export %s=%q\n", key, value)) } // WriteHost adds an entry to the /etc/hosts file. diff --git a/shared/build/buildfile/buildfile_test.go b/shared/build/buildfile/buildfile_test.go index c4a48c99..f9e0e942 100644 --- a/shared/build/buildfile/buildfile_test.go +++ b/shared/build/buildfile/buildfile_test.go @@ -35,7 +35,7 @@ func TestWrite(t *testing.T) { f = &Buildfile{} f.WriteEnv("FOO", "BAR") - got, want = f.String(), "export FOO=BAR\n" + got, want = f.String(), "export FOO=\"BAR\"\n" if got != want { t.Errorf("Exepected WriteEnv returned %s, got %s", want, got) } diff --git a/shared/build/script/script.go b/shared/build/script/script.go index 372e1dc2..62fa8e7e 100644 --- a/shared/build/script/script.go +++ b/shared/build/script/script.go @@ -103,7 +103,7 @@ func (b *Build) Write(f *buildfile.Buildfile, r *repo.Repo) { func (b *Build) WriteBuild(f *buildfile.Buildfile) { // append environment variables for _, env := range b.Env { - parts := strings.Split(env, "=") + parts := strings.SplitN(env, "=", 2) if len(parts) != 2 { continue } From 5022db8d551403ae55c479d0ebe2be0b2b4df2ee Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 1 Nov 2014 11:41:02 -0700 Subject: [PATCH 2/2] updated unit tests to account for quoted env vars --- plugin/deploy/modulus/modulus_test.go | 2 +- plugin/deploy/nodejitsu/nodejitsu_test.go | 4 ++-- plugin/deploy/ssh_test.go | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugin/deploy/modulus/modulus_test.go b/plugin/deploy/modulus/modulus_test.go index 59c8e6bf..b8f56ad3 100644 --- a/plugin/deploy/modulus/modulus_test.go +++ b/plugin/deploy/modulus/modulus_test.go @@ -40,7 +40,7 @@ func Test_Modulus(t *testing.T) { } m.Write(b) - g.Assert(b.String()).Equal(`export MODULUS_TOKEN=bar + g.Assert(b.String()).Equal(`export MODULUS_TOKEN="bar" [ -f /usr/bin/npm ] || echo ERROR: npm is required for modulus.io deployments [ -f /usr/bin/npm ] || exit 1 [ -f /usr/bin/sudo ] || npm install -g modulus diff --git a/plugin/deploy/nodejitsu/nodejitsu_test.go b/plugin/deploy/nodejitsu/nodejitsu_test.go index f1424d94..9acbf8de 100644 --- a/plugin/deploy/nodejitsu/nodejitsu_test.go +++ b/plugin/deploy/nodejitsu/nodejitsu_test.go @@ -40,8 +40,8 @@ func Test_Modulus(t *testing.T) { } n.Write(b) - g.Assert(b.String()).Equal(`export username=foo -export apiToken=bar + g.Assert(b.String()).Equal(`export username="foo" +export apiToken="bar" [ -f /usr/bin/sudo ] || npm install -g jitsu [ -f /usr/bin/sudo ] && sudo npm install -g jitsu echo '#DRONE:6a69747375206465706c6f79' diff --git a/plugin/deploy/ssh_test.go b/plugin/deploy/ssh_test.go index 037d3ab3..54aa1a1c 100644 --- a/plugin/deploy/ssh_test.go +++ b/plugin/deploy/ssh_test.go @@ -81,7 +81,7 @@ func TestSSHOneArtifact(t *testing.T) { t.Fatalf("Can't unmarshal deploy script: %s", err) } - if !strings.Contains(bscr, "ARTIFACT=build.result") { + if !strings.Contains(bscr, `ARTIFACT="build.result"`) { t.Error("Expect script to contains artifact") } @@ -96,7 +96,7 @@ func TestSSHMultiArtifact(t *testing.T) { t.Fatalf("Can't unmarshal deploy script: %s", err) } - if !strings.Contains(bscr, "ARTIFACT=${PWD##*/}.tar.gz") { + if !strings.Contains(bscr, `ARTIFACT="${PWD##*/}.tar.gz"`) { t.Errorf("Expect script to contains artifact") } @@ -111,11 +111,11 @@ func TestSSHGitArchive(t *testing.T) { t.Fatalf("Can't unmarshal deploy script: %s", err) } - if !strings.Contains(bscr, "COMMIT=$(git rev-parse HEAD)") { + if !strings.Contains(bscr, `COMMIT="$(git rev-parse HEAD)"`) { t.Errorf("Expect script to contains commit ref") } - if !strings.Contains(bscr, "ARTIFACT=${PWD##*/}-${COMMIT}.tar.gz") { + if !strings.Contains(bscr, `ARTIFACT="${PWD##*/}-${COMMIT}.tar.gz"`) { t.Errorf("Expect script to contains artifact") }