Add demo test variant

We're piggybacking on our existing integration test framework to record  demos that we can include in our docs
This commit is contained in:
Jesse Duffield 2023-07-31 18:32:38 +10:00
parent 71d2fd37e2
commit 9cc1d65280
32 changed files with 891 additions and 12 deletions

View file

@ -74,6 +74,13 @@ func (self *Shell) RunShellCommand(cmdStr string) *Shell {
func (self *Shell) CreateFile(path string, content string) *Shell {
fullPath := filepath.Join(self.dir, path)
// create any required directories
dir := filepath.Dir(fullPath)
if err := os.MkdirAll(dir, 0o755); err != nil {
self.fail(fmt.Sprintf("error creating directory: %s\n%s", dir, err))
}
err := os.WriteFile(fullPath, []byte(content), 0o644)
if err != nil {
self.fail(fmt.Sprintf("error creating file: %s\n%s", fullPath, err))
@ -195,6 +202,21 @@ func (self *Shell) CreateNCommitsStartingAt(n, startIndex int) *Shell {
return self
}
// Only to be used in demos, because the list might change and we don't want
// tests to break when it does.
func (self *Shell) CreateNCommitsWithRandomMessages(n int) *Shell {
for i := 0; i < n; i++ {
file := RandomFiles[i]
self.CreateFileAndAdd(
file.Name,
file.Content,
).
Commit(RandomCommitMessages[i])
}
return self
}
func (self *Shell) SetConfig(key string, value string) *Shell {
self.RunCommand([]string{"git", "config", "--local", key, value})
return self