mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-02 22:34:56 -04:00
Add function to retrieve real device path of mapped device
Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
f8c9c0f17f
commit
437de8bcb1
4 changed files with 73 additions and 3 deletions
|
@ -64,6 +64,10 @@ func (c *stubCryptDevice) Free() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (c *stubCryptDevice) GetDeviceName() string {
|
||||
return c.deviceName
|
||||
}
|
||||
|
||||
func (c *stubCryptDevice) Load(cryptsetup.DeviceType) error {
|
||||
return c.loadErr
|
||||
}
|
||||
|
@ -314,6 +318,49 @@ func TestResizeCryptDevice(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetDevicePath(t *testing.T) {
|
||||
volumeID := "pvc-123"
|
||||
someErr := errors.New("error")
|
||||
testCases := map[string]struct {
|
||||
volumeID string
|
||||
device *stubCryptDevice
|
||||
wantErr bool
|
||||
}{
|
||||
"success": {
|
||||
volumeID: volumeID,
|
||||
device: &stubCryptDevice{deviceName: volumeID},
|
||||
},
|
||||
"InitByName fails": {
|
||||
volumeID: volumeID,
|
||||
device: &stubCryptDevice{initByNameErr: someErr},
|
||||
wantErr: true,
|
||||
},
|
||||
"GetDeviceName returns nothing": {
|
||||
volumeID: volumeID,
|
||||
device: &stubCryptDevice{},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
mapper := &CryptMapper{
|
||||
mapper: tc.device,
|
||||
}
|
||||
|
||||
res, err := mapper.GetDevicePath(tc.volumeID)
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
assert.Equal(tc.device.deviceName, res)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsIntegrityFS(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
wantIntegrity bool
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue