tests: add hcl task driver config parsing tests (#5314)

* drivers: add config parsing tests

Add basic tests for parsing and encoding task config.

* drivers/docker: fix some config declarations

* refactor and document config parse helpers
This commit is contained in:
Mahmood Ali
2019-02-12 14:46:37 -05:00
committed by GitHub
parent 0fd2b45740
commit 941f89e0fe
9 changed files with 584 additions and 66 deletions

View File

@@ -14,6 +14,7 @@ import (
"time"
ctestutil "github.com/hashicorp/nomad/client/testutil"
"github.com/hashicorp/nomad/helper/pluginutils/hclutils"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/structs"
@@ -291,3 +292,27 @@ func copyFile(src, dst string, t *testing.T) {
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
}
}
func TestConfig_ParseAllHCL(t *testing.T) {
cfgStr := `
config {
class = "java.main"
class_path = "/tmp/cp"
jar_path = "/tmp/jar.jar"
jvm_options = ["-Xmx600"]
args = ["arg1", "arg2"]
}`
expected := &TaskConfig{
Class: "java.main",
ClassPath: "/tmp/cp",
JarPath: "/tmp/jar.jar",
JvmOpts: []string{"-Xmx600"},
Args: []string{"arg1", "arg2"},
}
var tc *TaskConfig
hclutils.NewConfigParser(taskConfigSpec).ParseHCL(t, cfgStr, &tc)
require.EqualValues(t, expected, tc)
}