db86bac9ef
Some nvme devices do not report their capacity through the usual 'user_capacity' field, instead the total capacity is reported with the 'nvme_total_capacity' field. Fixes: #466
34 lines
696 B
Go
34 lines
696 B
Go
package collector
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSmartInfo_Capacity(t *testing.T) {
|
|
t.Run("should report nvme capacity", func(t *testing.T) {
|
|
smartInfo := SmartInfo{
|
|
UserCapacity: UserCapacity{
|
|
Bytes: 1234,
|
|
},
|
|
NvmeTotalCapacity: 5678,
|
|
}
|
|
assert.Equal(t, int64(5678), smartInfo.Capacity())
|
|
})
|
|
|
|
t.Run("should report user capacity", func(t *testing.T) {
|
|
smartInfo := SmartInfo{
|
|
UserCapacity: UserCapacity{
|
|
Bytes: 1234,
|
|
},
|
|
}
|
|
assert.Equal(t, int64(1234), smartInfo.Capacity())
|
|
})
|
|
|
|
t.Run("should report 0 for unknown capacities", func(t *testing.T) {
|
|
var smartInfo SmartInfo
|
|
assert.Zero(t, smartInfo.Capacity())
|
|
})
|
|
}
|