github.com/marinho/drone@v0.2.1-0.20140504195434-d3ba962e89a7/pkg/build/buildfile/buildfile_test.go (about) 1 package buildfile 2 3 import ( 4 "testing" 5 ) 6 7 func TestWrite(t *testing.T) { 8 9 var f = New() 10 var got, want = f.String(), base 11 if got != want { 12 t.Errorf("Exepected New() returned %s, got %s", want, got) 13 } 14 15 f = &Buildfile{} 16 f.WriteCmd("echo hi") 17 got, want = f.String(), "echo '#DRONE:6563686f206869'\necho hi\n" 18 if got != want { 19 t.Errorf("Exepected WriteCmd returned %s, got %s", want, got) 20 } 21 22 f = &Buildfile{} 23 f.WriteCmdSilent("echo hi") 24 got, want = f.String(), "echo hi\n" 25 if got != want { 26 t.Errorf("Exepected WriteCmdSilent returned %s, got %s", want, got) 27 } 28 29 f = &Buildfile{} 30 f.WriteComment("this is a comment") 31 got, want = f.String(), "#this is a comment\n" 32 if got != want { 33 t.Errorf("Exepected WriteComment returned %s, got %s", want, got) 34 } 35 36 f = &Buildfile{} 37 f.WriteEnv("FOO", "BAR") 38 got, want = f.String(), "export FOO=BAR\n" 39 if got != want { 40 t.Errorf("Exepected WriteEnv returned %s, got %s", want, got) 41 } 42 43 f = &Buildfile{} 44 f.WriteHost("127.0.0.1") 45 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" 46 if got != want { 47 t.Errorf("Exepected WriteHost returned %s, got %s", want, got) 48 } 49 }