Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed typo and sorted image definitions #3

Merged
merged 2 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion imagedef.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cmlclient

import "context"
import (
"context"
"sort"
)

// [
// {
Expand Down Expand Up @@ -45,5 +48,11 @@ func (c *Client) GetImageDefs(ctx context.Context) ([]ImageDefinition, error) {
if err != nil {
return nil, err
}

// sort the image list by their ID
sort.Slice(imgDef, func(i, j int) bool {
return imgDef[i].ID < imgDef[j].ID
})

return imgDef, nil
}
52 changes: 35 additions & 17 deletions imagedef_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,37 @@ func TestClient_GetImageDefs(t *testing.T) {

tc := newAuthedTestAPIclient()

aimgdef := `{
"id": "alpine-3-10-base",
"node_definition_id": "alpine",
"description": "Alpine Linux and network tools",
"label": "Alpine 3.10",
"disk_image": "alpine-3-10-base.qcow2",
"read_only": true,
"ram": null,
"cpus": null,
"cpu_limit": null,
"data_volume": null,
"boot_disk_size": null,
"disk_subfolder": "alpine-3-10-base",
"schema_version": "0.0.1"
}`
zimgdef := `{
"id": "zodiac-3-10-base",
"node_definition_id": "alpine",
"description": "Alpine Linux and network tools",
"label": "Alpine 3.10",
"disk_image": "alpine-3-10-base.qcow2",
"read_only": true,
"ram": null,
"cpus": null,
"cpu_limit": null,
"data_volume": null,
"boot_disk_size": null,
"disk_subfolder": "alpine-3-10-base",
"schema_version": "0.0.1"
}`

tests := []struct {
name string
responses mr.MockRespList
Expand All @@ -281,22 +312,8 @@ func TestClient_GetImageDefs(t *testing.T) {
"good",
mr.MockRespList{
mr.MockResp{
Data: []byte(
`[{
"id": "alpine-3-10-base",
"node_definition_id": "alpine",
"description": "Alpine Linux and network tools",
"label": "Alpine 3.10",
"disk_image": "alpine-3-10-base.qcow2",
"read_only": true,
"ram": null,
"cpus": null,
"cpu_limit": null,
"data_volume": null,
"boot_disk_size": null,
"disk_subfolder": "alpine-3-10-base",
"schema_version": "0.0.1"
}]`),
// need this to go through the sorting in the client
Data: []byte("[" + zimgdef + "," + aimgdef + "]"),
},
},
false,
Expand Down Expand Up @@ -324,7 +341,8 @@ func TestClient_GetImageDefs(t *testing.T) {
return
}
expected := []ImageDefinition{}
b := bytes.NewReader(tc.mr.LastData())
// this is properly sorted:
b := bytes.NewReader([]byte("[" + aimgdef + "," + zimgdef + "]"))
err = json.NewDecoder(b).Decode(&expected)
if err != nil {
t.Error("bad test data")
Expand Down
2 changes: 1 addition & 1 deletion node.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type nodePatchPostAlias struct {
X int `json:"x"`
Y int `json:"y"`
NodeDefinition string `json:"node_definition,omitempty"`
ImageDefinition string `json:"imagee_definition,omitempty"`
ImageDefinition string `json:"image_definition,omitempty"`
Configuration string `json:"configuration,omitempty"`
CPUs int `json:"cpus,omitempty"`
CPUlimit int `json:"cpu_limit,omitempty"`
Expand Down