예제 #1
0
func testRootFsAvailable(t *testing.T) {
	policy := testPolicy()
	policy.RootFreeDiskMB = 10
	mockCadvisor := new(cadvisor.Mock)
	dm, err := newDiskSpaceManager(mockCadvisor, policy)
	require.NoError(t, err)

	const mb = 1024 * 1024
	// 500MB available
	mockCadvisor.On("DockerImagesFsInfo").Return(cadvisorApi.FsInfo{
		Usage:     9500 * mb,
		Capacity:  10000 * mb,
		Available: 500 * mb,
	}, nil)
	// 10MB available
	mockCadvisor.On("RootFsInfo").Return(cadvisorApi.FsInfo{
		Usage:     990 * mb,
		Capacity:  1000 * mb,
		Available: 10 * mb,
	}, nil)
	ok, err := dm.IsDockerDiskSpaceAvailable()
	require.NoError(t, err)
	require.True(t, ok)
	ok, err = dm.IsRootDiskSpaceAvailable()
	require.NoError(t, err)
	require.False(t, ok)
}
예제 #2
0
func testCache(t *testing.T) {
	policy := testPolicy()
	mockCadvisor := new(cadvisor.Mock)
	dm, err := newDiskSpaceManager(mockCadvisor, policy)
	require.NoError(t, err)
	const mb = 1024 * 1024
	mockCadvisor.On("DockerImagesFsInfo").Return(cadvisorApi.FsInfo{
		Usage:     400 * mb,
		Capacity:  1000 * mb,
		Available: 300 * mb,
	}, nil).Once()
	mockCadvisor.On("RootFsInfo").Return(cadvisorApi.FsInfo{
		Usage:     9 * mb,
		Capacity:  10 * mb,
		Available: 500,
	}, nil).Once()
	ok, err := dm.IsDockerDiskSpaceAvailable()
	ok, err = dm.IsRootDiskSpaceAvailable()

	// Checking for space again shouldn't need to mock as cache would serve it.
	ok, err = dm.IsDockerDiskSpaceAvailable()
	require.NoError(t, err)
	require.True(t, ok)
	ok, err = dm.IsRootDiskSpaceAvailable()
	require.NoError(t, err)
	require.True(t, ok)
}
예제 #3
0
func testFsInfoError(t *testing.T) {
	assert := assert.New(t)
	policy := testPolicy()
	policy.RootFreeDiskMB = 10
	mockCadvisor := new(cadvisor.Mock)
	dm, err := newDiskSpaceManager(mockCadvisor, policy)
	require.NoError(t, err)

	mockCadvisor.On("DockerImagesFsInfo").Return(cadvisorApi.FsInfo{}, fmt.Errorf("can't find fs"))
	mockCadvisor.On("RootFsInfo").Return(cadvisorApi.FsInfo{}, fmt.Errorf("EBUSY"))
	ok, err := dm.IsDockerDiskSpaceAvailable()
	assert.Error(err)
	require.True(t, ok)
	ok, err = dm.IsRootDiskSpaceAvailable()
	assert.Error(err)
	require.True(t, ok)
}
예제 #4
0
func testSpaceAvailable(t *testing.T) {
	policy := testPolicy()
	mockCadvisor := new(cadvisor.Mock)
	dm, err := newDiskSpaceManager(mockCadvisor, policy)
	require.NoError(t, err)
	const mb = 1024 * 1024
	mockCadvisor.On("DockerImagesFsInfo").Return(cadvisorApi.FsInfo{
		Usage:    400 * mb,
		Capacity: 1000 * mb,
	}, nil)
	mockCadvisor.On("RootFsInfo").Return(cadvisorApi.FsInfo{
		Usage:    9 * mb,
		Capacity: 10 * mb,
	}, nil)
	ok, err := dm.IsDockerDiskSpaceAvailable()
	require.NoError(t, err)
	require.True(t, ok)
	ok, err = dm.IsRootDiskSpaceAvailable()
	require.NoError(t, err)
	require.True(t, ok)
}