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

Exclude disk images with name containing "k3s" #58

Merged
merged 2 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion disk_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ func (c *Client) ListDiskImages() ([]DiskImage, error) {
return nil, err
}

return diskImages, nil
filteredDiskImages := make([]DiskImage, 0)
for _, diskImage := range diskImages {
if !strings.Contains(diskImage.Name, "k3s") {
filteredDiskImages = append(filteredDiskImages, diskImage)
}
}

return filteredDiskImages, nil
}

// GetDiskImage get one disk image using the id
Expand Down
64 changes: 64 additions & 0 deletions disk_image_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package civogo

import (
"reflect"
"testing"
)

Expand Down Expand Up @@ -69,3 +70,66 @@ func TestFindDiskImage(t *testing.T) {
}

}

func TestListDiskImagesV2(t *testing.T) {
zulh-civo marked this conversation as resolved.
Show resolved Hide resolved
client, server, _ := NewClientForTesting(map[string]string{
"/v2/disk_images": `[{"id":"22552dcf-aea3-4403-ae62-93651932bbd7","name":"centos-7","version":"7","state":"available","distribution":"centos","description":null,"label":null},{"id":"4204229c-510c-4ba4-ab07-522e2aaa2cf8","name":"debian-10","version":"10","state":"available","distribution":"debian","description":null,"label":null},{"id":"cddce6c9-f84e-4e4f-ab8d-7a33cab85158","name":"debian-9","version":"9","state":"available","distribution":"debian","description":null,"label":null},{"id":"c3b28d45-c161-4abc-bdda-4facac38f2b1","name":"ubuntu-bionic","version":"18.04","state":"available","distribution":"ubuntu","description":null,"label":null},{"id":"8eb48e20-e5db-49fe-9cdf-cc8f381c61c6","name":"ubuntu-focal","version":"20.04","state":"available","distribution":"ubuntu","description":null,"label":null}]`,
})
defer server.Close()
got, err := client.ListDiskImages()

if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
expected := []DiskImage{
{
ID: "22552dcf-aea3-4403-ae62-93651932bbd7",
Name: "centos-7",
Version: "7",
State: "available",
Distribution: "centos",
Description: "",
Label: "",
},
{
ID: "4204229c-510c-4ba4-ab07-522e2aaa2cf8",
Name: "debian-10",
Version: "10",
State: "available",
Distribution: "debian",
Description: "",
Label: "",
},
{
ID: "cddce6c9-f84e-4e4f-ab8d-7a33cab85158",
Name: "debian-9",
Version: "9",
State: "available",
Distribution: "debian",
Description: "",
Label: "",
},
{
ID: "c3b28d45-c161-4abc-bdda-4facac38f2b1",
Name: "ubuntu-bionic",
Version: "18.04",
State: "available",
Distribution: "ubuntu",
Description: "",
Label: "",
},
{
ID: "8eb48e20-e5db-49fe-9cdf-cc8f381c61c6",
Name: "ubuntu-focal",
Version: "20.04",
State: "available",
Distribution: "ubuntu",
Description: "",
Label: "",
},
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Expected %+v, got %+v", expected, got)
}
}