Files
atlantis/server/events/plan_executor_test.go
Luke Kysow c59b422949 Fmt
2017-10-18 06:44:44 -07:00

30 lines
1.2 KiB
Go

package events_test
import (
"testing"
"github.com/hootsuite/atlantis/server/events"
. "github.com/hootsuite/atlantis/testing_util"
)
var p events.PlanExecutor
func TestModifiedProjects(t *testing.T) {
runTest(t, "should handle no files modified", []string{}, []string{})
runTest(t, "should handle files at root", []string{"root.tf"}, []string{"."})
runTest(t, "should de-duplicate files at root", []string{"root1.tf", "root2.tf"}, []string{"."})
runTest(t, "should handle sub directories", []string{"sub/dir/file.tf"}, []string{"sub/dir"})
runTest(t, "should de-duplicate files in sub directories", []string{"sub/dir/file.tf", "sub/dir/file2.tf"}, []string{"sub/dir"})
runTest(t, "should handle nested sub directories", []string{"root.tf", "sub/child.tf", "sub/sub/child.tf"}, []string{".", "sub", "sub/sub"})
runTest(t, "should use parent of env/ dirs", []string{"env/env.tf"}, []string{"."})
runTest(t, "should use parent of env/ dirs in sub dirs", []string{"sub/env/env.tf"}, []string{"sub"})
}
func runTest(t *testing.T, testDescrip string, filesChanged []string, expectedPaths []string) {
projects := p.ModifiedProjects("owner/repo", filesChanged)
for i, p := range projects {
t.Log(testDescrip)
Equals(t, expectedPaths[i], p.Path)
}
}