mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
Support JSON and template format with nomad CLI
This commit is contained in:
41
command/data_format_test.go
Normal file
41
command/data_format_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
type testData struct {
|
||||
Region string
|
||||
ID string
|
||||
Name string
|
||||
}
|
||||
|
||||
const expectJSON = `{
|
||||
"Region": "global",
|
||||
"ID": "1",
|
||||
"Name": "example"
|
||||
}`
|
||||
|
||||
var (
|
||||
tData = testData{"global", "1", "example"}
|
||||
testFormat = map[string]string{"json": "", "template": "{{.Region}}"}
|
||||
expectOutput = map[string]string{"json": expectJSON, "template": "global"}
|
||||
)
|
||||
|
||||
func TestDataFormat(t *testing.T) {
|
||||
for k, v := range testFormat {
|
||||
fm, err := DataFormat(k, v)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
result, err := fm.TransformData(tData)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
if result != expectOutput[k] {
|
||||
t.Fatalf("expected output: %s, actual: %s", expectOutput[k], result)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user