Skip to content

Commit

Permalink
fix: rename root object and updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
astromechza committed Jan 25, 2024
1 parent 2a6a89b commit f6a0c18
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 186 deletions.
2 changes: 1 addition & 1 deletion loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func ParseYAML(dest *map[string]interface{}, r io.Reader) error {
}

// MapSpec converts the source mapping structure into the target WorkloadSpec.
func MapSpec(dest *types.WorkloadSpec, src map[string]interface{}) error {
func MapSpec(dest *types.Workload, src map[string]interface{}) error {
mapper, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: dest,
TagName: "json",
Expand Down
20 changes: 10 additions & 10 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestDecodeYaml(t *testing.T) {
var tests = []struct {
Name string
Source io.Reader
Output types.WorkloadSpec
Output types.Workload
Error error
}{
{
Expand Down Expand Up @@ -130,20 +130,20 @@ resources:
}
}
`)),
Output: types.WorkloadSpec{
Output: types.Workload{
ApiVersion: "score.dev/v1b1",
Metadata: types.WorkloadSpecMetadata{
Metadata: types.WorkloadMetadata{
Name: "hello-world",
},
Service: &types.WorkloadSpecService{
Ports: types.WorkloadSpecServicePorts{
Service: &types.WorkloadService{
Ports: types.WorkloadServicePorts{
"www": types.ServicePort{
Port: intRef(80),
TargetPort: 8080,
Port: 80,
TargetPort: intRef(8080),
},
},
},
Containers: types.WorkloadSpecContainers{
Containers: types.WorkloadContainers{
"hello": types.Container{
Image: "busybox",
Command: []string{"/bin/echo"},
Expand Down Expand Up @@ -196,7 +196,7 @@ resources:
},
},
},
Resources: types.WorkloadSpecResources{
Resources: types.WorkloadResources{
"env": {
Type: "environment",
},
Expand Down Expand Up @@ -227,7 +227,7 @@ resources:
for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
var srcMap map[string]interface{}
var spec types.WorkloadSpec
var spec types.Workload

var err = ParseYAML(&srcMap, tt.Source)
if err == nil {
Expand Down
62 changes: 14 additions & 48 deletions schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ resources:

var obj map[string]interface{}
var yamlReader = bytes.NewReader(data)
yaml.NewDecoder(yamlReader).Decode(&obj)
_ = yaml.NewDecoder(yamlReader).Decode(&obj)
return obj
}

Expand Down Expand Up @@ -227,7 +227,7 @@ func TestSchema(t *testing.T) {
Message: "/service/ports/www",
},
{
Name: "service.ports.*.targetPort is missing",
Name: "service.ports.*.port is missing",
Src: func() map[string]interface{} {
src := newTestDocument()
src["service"] = map[string]interface{}{
Expand All @@ -240,50 +240,51 @@ func TestSchema(t *testing.T) {
Message: "/service/ports/www",
},
{
Name: "service.ports.*.targetPort is not a number",
Name: "service.ports.*.port is not a number",
Src: func() map[string]interface{} {
src := newTestDocument()
src["service"] = map[string]interface{}{
"ports": map[string]interface{}{
"www": map[string]interface{}{
"targetPort": false,
"port": false,
"targetPort": 8080,
},
},
}
return src
}(),
Message: "/service/ports/www/targetPort",
Message: "/service/ports/www/port",
},
{
Name: "service.ports.*.port is optional",
Name: "service.ports.*.targetPort is not a number",
Src: func() map[string]interface{} {
src := newTestDocument()
src["service"] = map[string]interface{}{
"ports": map[string]interface{}{
"www": map[string]interface{}{
"targetPort": 8080,
"port": 80,
"targetPort": false,
},
},
}
return src
}(),
Message: "",
Message: "/service/ports/www/targetPort",
},
{
Name: "service.ports.*.port is not a number",
Name: "service.ports.*.targetPort is optional",
Src: func() map[string]interface{} {
src := newTestDocument()
src["service"] = map[string]interface{}{
"ports": map[string]interface{}{
"www": map[string]interface{}{
"port": false,
"targetPort": 8080,
"port": 8080,
},
},
}
return src
}(),
Message: "/service/ports/www/port",
Message: "",
},
{
Name: "service with multiple ports",
Expand All @@ -296,7 +297,7 @@ func TestSchema(t *testing.T) {
"targetPort": 8080,
},
"admin": map[string]interface{}{
"targetPort": 8090,
"port": 90,
},
},
}
Expand Down Expand Up @@ -1532,41 +1533,6 @@ func TestSchema(t *testing.T) {
Message: "/resources/db/metadata/annotations/one",
},

// resources.*.properties
//
{
Name: "resources.*.properties is not set",
Src: func() map[string]interface{} {
src := newTestDocument()
var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{})
db["properties"] = nil
return src
}(),
Message: "",
},
{
Name: "resources.*.properties is empty",
Src: func() map[string]interface{} {
src := newTestDocument()
var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{})
db["properties"] = map[string]interface{}{}
return src
}(),
Message: "",
},
{
Name: "resources.*.properties is ignored",
Src: func() map[string]interface{} {
src := newTestDocument()
var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{})
db["properties"] = map[string]interface{}{
"key": "value",
}
return src
}(),
Message: "",
},

// resources.*.params
//
{
Expand Down
Loading

0 comments on commit f6a0c18

Please sign in to comment.