Skip to content
New issue

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

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

Already on GitHub? # to your account

block storage: adding block type #209

Merged
merged 1 commit into from
Apr 6, 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
8 changes: 5 additions & 3 deletions block_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ type BlockStorage struct {
AttachedToInstance string `json:"attached_to_instance"`
Label string `json:"label"`
MountID string `json:"mount_id"`
BlockType string `json:"block_type"`
}

// BlockStorageCreate struct is used for creating Block Storage.
type BlockStorageCreate struct {
Region string `json:"region"`
SizeGB int `json:"size_gb"`
Label string `json:"label,omitempty"`
Region string `json:"region"`
SizeGB int `json:"size_gb"`
Label string `json:"label,omitempty"`
BlockType string `json:"block_type"`
}

// BlockStorageUpdate struct is used to update Block Storage.
Expand Down
16 changes: 10 additions & 6 deletions block_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ func TestBlockStorageServiceHandler_Create(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/blocks", func(writer http.ResponseWriter, request *http.Request) {
response := `{"block":{"id":"123456","cost":10,"status":"active","size_gb":100,"region":"ewr","attached_to_instance":"","date_created":"01-01-1960","label":"mylabel", "mount_id": "ewr-123abc"}}`
response := `{"block":{"id":"123456","cost":10,"status":"active","size_gb":100,"region":"ewr","attached_to_instance":"","date_created":"01-01-1960","label":"mylabel", "mount_id": "ewr-123abc", "block_type": "test"}}`
fmt.Fprint(writer, response)
})
blockReq := &BlockStorageCreate{
Region: "ewr",
SizeGB: 100,
Label: "mylabel",
Region: "ewr",
SizeGB: 100,
Label: "mylabel",
BlockType: "test",
}
blockStorage, err := client.BlockStorage.Create(ctx, blockReq)
if err != nil {
Expand All @@ -35,6 +36,7 @@ func TestBlockStorageServiceHandler_Create(t *testing.T) {
AttachedToInstance: "",
Label: "mylabel",
MountID: "ewr-123abc",
BlockType: "test",
}

if !reflect.DeepEqual(blockStorage, expected) {
Expand All @@ -47,7 +49,7 @@ func TestBlockStorageServiceHandler_Get(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/blocks/123456", func(writer http.ResponseWriter, request *http.Request) {
response := `{"block":{"id":"123456","cost":10,"status":"active","size_gb":100,"region":"ewr","attached_to_instance":"","date_created":"01-01-1960","label":"mylabel", "mount_id": "123abc"}}`
response := `{"block":{"id":"123456","cost":10,"status":"active","size_gb":100,"region":"ewr","attached_to_instance":"","date_created":"01-01-1960","label":"mylabel", "mount_id": "123abc", "block_type": "test"}}`
fmt.Fprint(writer, response)
})

Expand All @@ -66,6 +68,7 @@ func TestBlockStorageServiceHandler_Get(t *testing.T) {
AttachedToInstance: "",
Label: "mylabel",
MountID: "123abc",
BlockType: "test",
}

if !reflect.DeepEqual(blockStorage, expected) {
Expand Down Expand Up @@ -109,7 +112,7 @@ func TestBlockStorageServiceHandler_List(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/blocks", func(writer http.ResponseWriter, request *http.Request) {
response := `{"blocks":[{"id":"123456","cost":10,"status":"active","size_gb":100,"region":"ewr","attached_to_instance":"","date_created":"01-01-1960","label":"mylabel", "mount_id": "123abc"}],"meta":{"total":1,"links":{"next":"thisismycusror","prev":""}}}`
response := `{"blocks":[{"id":"123456","cost":10,"status":"active","size_gb":100,"region":"ewr","attached_to_instance":"","date_created":"01-01-1960","label":"mylabel", "mount_id": "123abc", "block_type": "test"}],"meta":{"total":1,"links":{"next":"thisismycusror","prev":""}}}`
fmt.Fprint(writer, response)
})

Expand All @@ -129,6 +132,7 @@ func TestBlockStorageServiceHandler_List(t *testing.T) {
AttachedToInstance: "",
Label: "mylabel",
MountID: "123abc",
BlockType: "test",
},
}

Expand Down