From 62ec8634f6cb1b66919143451d65ac27b2350609 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 13 Mar 2014 16:50:01 -0700 Subject: [PATCH] added code for testing buildfiles --- pkg/build/buildfile/buildfile_test.go | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 pkg/build/buildfile/buildfile_test.go diff --git a/pkg/build/buildfile/buildfile_test.go b/pkg/build/buildfile/buildfile_test.go new file mode 100644 index 000000000..aca239290 --- /dev/null +++ b/pkg/build/buildfile/buildfile_test.go @@ -0,0 +1,49 @@ +package buildfile + +import ( + "testing" +) + +func TestWrite(t *testing.T) { + + var f = New() + var got, want = f.String(), base + if got != want { + t.Errorf("Exepected New() returned %s, got %s", want, got) + } + + f = &Buildfile{} + f.WriteCmd("echo hi") + got, want = f.String(), "echo '#DRONE:6563686f206869'\necho hi\n" + if got != want { + t.Errorf("Exepected WriteCmd returned %s, got %s", want, got) + } + + f = &Buildfile{} + f.WriteCmdSilent("echo hi") + got, want = f.String(), "echo hi\n" + if got != want { + t.Errorf("Exepected WriteCmdSilent returned %s, got %s", want, got) + } + + f = &Buildfile{} + f.WriteComment("this is a comment") + got, want = f.String(), "#this is a comment\n" + if got != want { + t.Errorf("Exepected WriteComment returned %s, got %s", want, got) + } + + f = &Buildfile{} + f.WriteEnv("FOO", "BAR") + got, want = f.String(), "export FOO=BAR\n" + if got != want { + t.Errorf("Exepected WriteEnv returned %s, got %s", want, got) + } + + f = &Buildfile{} + f.WriteHost("127.0.0.1") + got, want = f.String(), "[ -f /usr/bin/sudo ] || echo \"127.0.0.1\" | tee -a /etc/hosts\n[ -f /usr/bin/sudo ] && echo \"127.0.0.1\" | sudo tee -a /etc/hosts\n" + if got != want { + t.Errorf("Exepected WriteHost returned %s, got %s", want, got) + } +} \ No newline at end of file