2015-10-03 07:25:13 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-02-26 22:01:52 +00:00
|
|
|
"fmt"
|
2015-10-03 07:25:13 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-10-07 23:31:31 +00:00
|
|
|
var parseValueTests = []struct {
|
2015-10-03 07:25:13 +00:00
|
|
|
argument string
|
|
|
|
expectedResult interface{}
|
|
|
|
testDescription string
|
|
|
|
}{
|
|
|
|
{"true", true, "boolean"},
|
|
|
|
{"\"true\"", "true", "boolean as string"},
|
|
|
|
{"3.4", 3.4, "number"},
|
|
|
|
{"\"3.4\"", "3.4", "number as string"},
|
2017-06-06 00:19:32 +00:00
|
|
|
{"", "", "empty string"},
|
2015-10-03 07:25:13 +00:00
|
|
|
}
|
|
|
|
|
2015-10-07 23:31:31 +00:00
|
|
|
func TestParseValue(t *testing.T) {
|
|
|
|
for _, tt := range parseValueTests {
|
|
|
|
assertResultWithContext(t, tt.expectedResult, parseValue(tt.argument), tt.testDescription)
|
2015-10-03 07:25:13 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-09 10:24:42 +00:00
|
|
|
|
|
|
|
func TestRead(t *testing.T) {
|
|
|
|
result := read([]string{"sample.yaml", "b.c"})
|
|
|
|
assertResult(t, 2, result)
|
|
|
|
}
|
|
|
|
|
2017-08-03 07:30:07 +00:00
|
|
|
func TestReadArray(t *testing.T) {
|
|
|
|
result := read([]string{"sample_array.yaml", "[1]"})
|
|
|
|
assertResult(t, 2, result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadString(t *testing.T) {
|
|
|
|
result := read([]string{"sample_text.yaml"})
|
|
|
|
assertResult(t, "hi", result)
|
|
|
|
}
|
|
|
|
|
2017-02-26 22:01:52 +00:00
|
|
|
func TestOrder(t *testing.T) {
|
|
|
|
result := read([]string{"order.yaml"})
|
|
|
|
formattedResult := yamlToString(result)
|
|
|
|
assertResult(t,
|
|
|
|
`version: 3
|
|
|
|
application: MyApp`,
|
|
|
|
formattedResult)
|
|
|
|
}
|
|
|
|
|
2017-04-12 11:10:00 +00:00
|
|
|
func TestNewYaml(t *testing.T) {
|
|
|
|
result := newYaml([]string{"b.c", "3"})
|
|
|
|
formattedResult := fmt.Sprintf("%v", result)
|
|
|
|
assertResult(t,
|
|
|
|
"[{b [{c 3}]}]",
|
|
|
|
formattedResult)
|
|
|
|
}
|
|
|
|
|
2017-08-08 07:04:30 +00:00
|
|
|
func TestNewYamlArray(t *testing.T) {
|
|
|
|
result := newYaml([]string{"[0].cat", "meow"})
|
|
|
|
formattedResult := fmt.Sprintf("%v", result)
|
|
|
|
assertResult(t,
|
|
|
|
"[[{cat meow}]]",
|
|
|
|
formattedResult)
|
|
|
|
}
|
|
|
|
|
2015-10-09 10:24:42 +00:00
|
|
|
func TestUpdateYaml(t *testing.T) {
|
2017-02-26 22:01:52 +00:00
|
|
|
result := updateYaml([]string{"sample.yaml", "b.c", "3"})
|
|
|
|
formattedResult := fmt.Sprintf("%v", result)
|
|
|
|
assertResult(t,
|
|
|
|
"[{a Easy! as one two three} {b [{c 3} {d [3 4]} {e [[{name fred} {value 3}] [{name sam} {value 4}]]}]}]",
|
|
|
|
formattedResult)
|
2015-10-09 10:24:42 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 06:55:57 +00:00
|
|
|
func TestUpdateYamlArray(t *testing.T) {
|
|
|
|
result := updateYaml([]string{"sample_array.yaml", "[0]", "3"})
|
|
|
|
formattedResult := fmt.Sprintf("%v", result)
|
|
|
|
assertResult(t,
|
|
|
|
"[3 2 3]",
|
|
|
|
formattedResult)
|
|
|
|
}
|
|
|
|
|
2015-10-09 10:24:42 +00:00
|
|
|
func TestUpdateYaml_WithScript(t *testing.T) {
|
|
|
|
writeScript = "instruction_sample.yaml"
|
|
|
|
updateYaml([]string{"sample.yaml"})
|
|
|
|
}
|
2017-04-12 11:10:00 +00:00
|
|
|
|
|
|
|
func TestNewYaml_WithScript(t *testing.T) {
|
|
|
|
writeScript = "instruction_sample.yaml"
|
2017-04-14 02:56:50 +00:00
|
|
|
expectedResult := `b:
|
|
|
|
c: cat
|
|
|
|
e:
|
|
|
|
- name: Mike Farah`
|
2017-04-12 11:10:00 +00:00
|
|
|
result := newYaml([]string{""})
|
2017-04-14 02:56:50 +00:00
|
|
|
actualResult := yamlToString(result)
|
|
|
|
assertResult(t, expectedResult, actualResult)
|
2017-04-12 11:10:00 +00:00
|
|
|
}
|