Skip to content

Update fake_client.go #239

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions fake_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1290,11 +1290,27 @@ func (c *FakeClient) NewVolume(v *VolumeConfig) (*VolumeResult, error) {
func (c *FakeClient) ResizeVolume(id string, size int) (*SimpleResponse, error) {
for i, volume := range c.Volumes {
if volume.ID == id {
// Simulate API behavior: Check for possible failures
if volume.Attached {
return nil, fmt.Errorf("VolumeResizeOnlineError: volume %s cannot be resized while attached", id)
}
if size <= volume.SizeGigabytes {
return nil, fmt.Errorf("ResizeError: new size must be greater than current size")
}
if size > 1000 { // Assume an upper limit for simulation
return nil, fmt.Errorf("ResizeError: requested size exceeds allowed limit")
}
if rand.Intn(10) < 2 { // Simulate a 20% chance of a retryable error
return nil, fmt.Errorf("RetryableError: temporary failure, please retry")
}

// If no errors, update the size
c.Volumes[i].SizeGigabytes = size
return &SimpleResponse{Result: "success"}, nil
}
}

// Volume not found error
err := fmt.Errorf("unable to find volume %s, zero matches", id)
return nil, ZeroMatchesError.wrap(err)
}
Expand Down