From 28e17b7a0967b15a5c82a1237250b27693d85acc Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Thu, 4 May 2017 16:49:00 -0700 Subject: [PATCH] Test pre06ScriptCheck --- client/task_runner.go | 3 ++- client/task_runner_test.go | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/client/task_runner.go b/client/task_runner.go index c68ff7287..5eecdb8f8 100644 --- a/client/task_runner.go +++ b/client/task_runner.go @@ -327,7 +327,8 @@ var ver06 = version.Must(version.NewVersion("0.6.0dev")) // check is found on an exec/java task. const pre06ScriptCheckReason = "upgrading pre-0.6 script checks" -// pre06ScriptCheck returns true if version is prior to 0.6.0dev. +// pre06ScriptCheck returns true if version is prior to 0.6.0dev, has a script +// check, and uses exec or java drivers. func pre06ScriptCheck(ver, driver string, services []*structs.Service) bool { if driver != "exec" && driver != "java" && driver != "mock_driver" { // Only exec and java are affected diff --git a/client/task_runner_test.go b/client/task_runner_test.go index b373d6db8..cd818fde8 100644 --- a/client/task_runner_test.go +++ b/client/task_runner_test.go @@ -1520,3 +1520,49 @@ func TestTaskRunner_CleanupFail(t *testing.T) { t.Fatalf("expected %#v but found: %#v", expected, ctx.tr.createdResources.Resources) } } + +func TestTaskRunner_Pre06ScriptCheck(t *testing.T) { + run := func(ver, driver, checkType string, exp bool) (string, func(t *testing.T)) { + name := fmt.Sprintf("%s %s %s returns %t", ver, driver, checkType, exp) + return name, func(t *testing.T) { + services := []*structs.Service{ + { + Checks: []*structs.ServiceCheck{ + { + Type: checkType, + }, + }, + }, + } + if act := pre06ScriptCheck(ver, driver, services); act != exp { + t.Errorf("expected %t received %t", exp, act) + } + } + } + t.Run(run("0.5.6", "exec", "script", true)) + t.Run(run("0.5.6", "java", "script", true)) + t.Run(run("0.5.6", "mock_driver", "script", true)) + t.Run(run("0.5.9", "exec", "script", true)) + t.Run(run("0.5.9", "java", "script", true)) + t.Run(run("0.5.9", "mock_driver", "script", true)) + + t.Run(run("0.6.0dev", "exec", "script", false)) + t.Run(run("0.6.0dev", "java", "script", false)) + t.Run(run("0.6.0dev", "mock_driver", "script", false)) + t.Run(run("0.6.0", "exec", "script", false)) + t.Run(run("0.6.0", "java", "script", false)) + t.Run(run("0.6.0", "mock_driver", "script", false)) + t.Run(run("1.0.0", "exec", "script", false)) + t.Run(run("1.0.0", "java", "script", false)) + t.Run(run("1.0.0", "mock_driver", "script", false)) + + t.Run(run("0.5.6", "rkt", "script", false)) + t.Run(run("0.5.6", "docker", "script", false)) + t.Run(run("0.5.6", "qemu", "script", false)) + t.Run(run("0.5.6", "raw_exec", "script", false)) + t.Run(run("0.5.6", "invalid", "script", false)) + + t.Run(run("0.5.6", "exec", "tcp", false)) + t.Run(run("0.5.6", "java", "tcp", false)) + t.Run(run("0.5.6", "mock_driver", "tcp", false)) +}