645ca2eb56
Instead of just allowing booleans, type the map as string->interface{} so in the future we could pass string or number options to the language host.
38 lines
1 KiB
Go
38 lines
1 KiB
Go
package workspace
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
func TestProjectRuntimeInfoRoundtripYAML(t *testing.T) {
|
|
doTest := func(marshal func(interface{}) ([]byte, error), unmarshal func([]byte, interface{}) error) {
|
|
ri := NewProjectRuntimeInfo("nodejs", nil)
|
|
byts, err := marshal(ri)
|
|
assert.NoError(t, err)
|
|
|
|
var riRountrip ProjectRuntimeInfo
|
|
err = unmarshal(byts, &riRountrip)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, "nodejs", riRountrip.Name())
|
|
assert.Nil(t, riRountrip.Options())
|
|
|
|
ri = NewProjectRuntimeInfo("nodejs", map[string]interface{}{
|
|
"typescript": true,
|
|
"stringOption": "hello",
|
|
})
|
|
byts, err = marshal(ri)
|
|
assert.NoError(t, err)
|
|
err = unmarshal(byts, &riRountrip)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, "nodejs", riRountrip.Name())
|
|
assert.Equal(t, true, riRountrip.Options()["typescript"])
|
|
assert.Equal(t, "hello", riRountrip.Options()["stringOption"])
|
|
}
|
|
|
|
doTest(yaml.Marshal, yaml.Unmarshal)
|
|
doTest(json.Marshal, json.Unmarshal)
|
|
}
|