aboutsummaryrefslogtreecommitdiff
path: root/pkg/rtree/shared_test.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2017-07-07 12:24:09 +0200
committerStefan Majewsky <majewsky@gmx.net>2017-07-07 12:24:09 +0200
commit9365e7673bfb490edbad02dfbf449d3da5deed98 (patch)
treee59d035aa7bd607ce34778440a5dec71af00f7db /pkg/rtree/shared_test.go
parent23077b75410d6fab51762236f195d92bd559fc6a (diff)
downloadgofu-9365e7673bfb490edbad02dfbf449d3da5deed98.tar.gz
more compact specification of recorded commands
Diffstat (limited to 'pkg/rtree/shared_test.go')
-rw-r--r--pkg/rtree/shared_test.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/pkg/rtree/shared_test.go b/pkg/rtree/shared_test.go
index cad9378..3dadcec 100644
--- a/pkg/rtree/shared_test.go
+++ b/pkg/rtree/shared_test.go
@@ -137,6 +137,24 @@ type RecordedCommand struct {
Fails bool
}
+//Recorded is a shortcut function for initializing a []RecordedCommand. It
+//splits each line on whitespace to obtain the command line of that command,
+//and recognizes a leading "@/some/path" to set the workdir.
+//
+//This function can only be used for RecordedCommands without output that do not fail.
+func Recorded(lines ...string) (cs []RecordedCommand) {
+ cs = make([]RecordedCommand, len(lines))
+ for idx, line := range lines {
+ cmdline := strings.Fields(line)
+ if strings.HasPrefix(cmdline[0], "@") {
+ cs[idx].Cmd.WorkDir = strings.TrimPrefix(cmdline[0], "@")
+ cmdline = cmdline[1:]
+ }
+ cs[idx].Cmd.Program = cmdline
+ }
+ return
+}
+
//CommandSimulator implements the cli.CommandRunner interface (via its Next
//method). When a cli.Command is given to Next(), it is matched with the next
//command in the .Cmd list, and the result from that RecordedCommand is