Skip to content

Commit

Permalink
Added API functionality + testing to change engine IO type
Browse files Browse the repository at this point in the history
Signed-off-by: David Son <[email protected]>
  • Loading branch information
sondavidb committed Jun 20, 2022
1 parent f0a967e commit 876156a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drives.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,12 @@ func WithCacheType(cacheType string) DriveOpt {
d.CacheType = String(cacheType)
}
}

// WithIoEngine sets the io engine of the drive
// Defaults to Sync, Async is in developer preview at the moment
// https://github.com/firecracker-microvm/firecracker/blob/v1.1.0/docs/api_requests/block-io-engine.md
func WithIoEngine(ioEngine string) DriveOpt {
return func(d *models.Drive) {
d.IoEngine = String(ioEngine)
}
}
20 changes: 20 additions & 0 deletions drives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,23 @@ func TestDrivesBuilderAddDrive(t *testing.T) {
t.Errorf("expected drives %+v\n, but received %+v", e, a)
}
}

func TestDrivesBuilderWithIoEngine(t *testing.T) {
expectedPath := "/path/to/rootfs"
expectedVal := "Async"
expectedDrives := []models.Drive{
{
DriveID: String(rootDriveName),
PathOnHost: &expectedPath,
IsRootDevice: Bool(true),
IsReadOnly: Bool(false),
IoEngine: &expectedVal,
},
}

drives := NewDrivesBuilder(expectedPath).WithRootDrive(expectedPath,
WithDriveID(string(rootDriveName)), WithIoEngine(expectedVal)).Build()
if e, a := expectedDrives, drives; !reflect.DeepEqual(e, a) {
t.Errorf("expected drives %+v, but received %+v", e, a)
}
}

0 comments on commit 876156a

Please sign in to comment.