Files
atlantis/server/pre_run_test.go
Luke Kysow d425de95fa Refactoring
* set version in one place
* rename ExecutionContext to CommandContext
* delete unneeded PullRequestContext since it just duplicated what is in CommandContext
* split fields inside CommandContext into Repo, PullRequest, and User models
* clean up unused fields
* remove base_executor stuff which was trying to do inheritance in go and didn't get us anywhere
* clean up unused code and assets
* created a locking.Client that creates the Keys that are used on the front-end. This allows the backends to store the locks any way they like as long as they support the interface
2017-06-17 14:14:21 -07:00

68 lines
1.9 KiB
Go

package server
import (
"github.com/hootsuite/atlantis/logging"
. "github.com/hootsuite/atlantis/testing_util"
"log"
"os"
"testing"
)
var level logging.LogLevel = logging.Info
var logger = &logging.SimpleLogger{
Source: "server",
Log: log.New(os.Stderr, "", log.LstdFlags),
Level: level,
}
func TestPreRunCreateScript_empty(t *testing.T) {
scriptName, err := createScript(nil)
Assert(t, scriptName == "", "there should not be a script name")
Assert(t, err == nil, "there should not be an error")
}
func TestPreRunCreateScript_valid(t *testing.T) {
cmds := []string{"echo", "date"}
scriptName, err := createScript(cmds)
Assert(t, scriptName != "", "there should be a script name")
Assert(t, err == nil, "there should not be an error")
}
func TestPreRunExecuteScript_invalid(t *testing.T) {
cmds := []string{"invalid", "command"}
scriptName, _ := createScript(cmds)
_, err := execute(scriptName)
Assert(t, err != nil, "there should be an error")
}
func TestPreRunExecuteScript_valid(t *testing.T) {
cmds := []string{"echo", "date"}
scriptName, _ := createScript(cmds)
output, err := execute(scriptName)
Assert(t, err == nil, "there should not be an error")
Assert(t, output != "", "there should be output")
}
func TestPreRun_valid(t *testing.T) {
cmds := []string{"echo", "date"}
prePlan := PrePlan{Commands: cmds}
preApply := PreApply{Commands: cmds}
var config Config
config.PrePlan = prePlan
config.PreApply = preApply
config.StashPath = "/some/path"
err := PreRun(&config, logger, "/some/path", &Command{environment: "staging", commandType: Plan})
Assert(t, err == nil, "should not error")
}
func TestPreRun_partial_valid(t *testing.T) {
cmds := []string{"echo", "date"}
prePlan := PrePlan{Commands: cmds}
var config Config
config.PrePlan = prePlan
config.StashPath = "/some/path"
err := PreRun(&config, logger, "/some/path", &Command{environment: "staging", commandType: Plan})
Assert(t, err == nil, "should not error")
}