github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libkbfs/disk_limits_test.go (about)

     1  // Copyright 2017 Keybase Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD
     3  // license that can be found in the LICENSE file.
     4  
     5  package libkbfs
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/keybase/client/go/kbfs/ioutil"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  // TestDiskLimits checks that getDiskLimits() doesn't return an error,
    15  // and returns non-zero values. This assumes that the partition with
    16  // the root directory actually has free space/files, which may fail in
    17  // certain weird configs.
    18  func TestDiskLimits(t *testing.T) {
    19  	availableBytes, totalBytes, availableFiles, totalFiles, err :=
    20  		getDiskLimits("/")
    21  	require.NoError(t, err)
    22  	require.NotEqual(t, uint64(0), availableBytes)
    23  	require.NotEqual(t, uint64(0), totalBytes)
    24  	require.NotEqual(t, uint64(0), availableFiles)
    25  	require.NotEqual(t, uint64(0), totalFiles)
    26  }
    27  
    28  // TestDiskLimitsNonExistentFile checks that getDiskLimits() returns
    29  // an error for which ioutil.IsNotExist holds if its given file
    30  // doesn't exist.
    31  func TestDiskLimitsNonExistentFile(t *testing.T) {
    32  	// Of course, we're assuming this file doesn't exist.
    33  	_, _, _, _, err := getDiskLimits("/non-existent-file")
    34  	require.True(t, ioutil.IsNotExist(err))
    35  }
    36  
    37  func BenchmarkDiskLimits(b *testing.B) {
    38  	for i := 0; i < b.N; i++ {
    39  		_, _, _, _, _ = getDiskLimits("/")
    40  	}
    41  }