mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-11 01:55:27 +00:00
added code for testing buildfiles
This commit is contained in:
parent
17318d5623
commit
62ec8634f6
1 changed files with 49 additions and 0 deletions
49
pkg/build/buildfile/buildfile_test.go
Normal file
49
pkg/build/buildfile/buildfile_test.go
Normal file
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue