github.com/adrianjagielak/goofys@v0.24.1-0.20230810095418-94919a5d2254/internal/dir_test.go (about)

     1  package internal
     2  
     3  import (
     4  	. "gopkg.in/check.v1"
     5  )
     6  
     7  type DirTest struct{}
     8  
     9  var _ = Suite(&DirTest{})
    10  
    11  func (s *DirTest) TestHasCharLtSlash(t *C) {
    12  	t.Assert(hasCharLtSlash("wow"), Equals, false)
    13  	// '-', ' ' are less than '/'
    14  	t.Assert(hasCharLtSlash("w-o-w"), Equals, true)
    15  	t.Assert(hasCharLtSlash("w o w"), Equals, true)
    16  	// All unicode chars have multi-byte values and are > '/'
    17  	t.Assert(hasCharLtSlash("wøw"), Equals, false)
    18  }
    19  
    20  func (s *DirTest) TestCloudPathToName(t *C) {
    21  	t.Assert(cloudPathToName(""), Equals, "")
    22  	t.Assert(cloudPathToName("/"), Equals, "")
    23  	t.Assert(cloudPathToName("/a/b/c"), Equals, "c")
    24  	t.Assert(cloudPathToName("a/b/c"), Equals, "c")
    25  	t.Assert(cloudPathToName("/a/b/c/"), Equals, "c")
    26  }
    27  
    28  func (s *DirTest) TestShouldFetchNextListBlobsPage(t *C) {
    29  	// Output is not truncated => No more pages fetch => ***FALSE***
    30  	// (No matter what Items and Prefixes are present)
    31  	t.Assert(shouldFetchNextListBlobsPage(
    32  		&ListBlobsOutput{IsTruncated: false}), Equals, false)
    33  	t.Assert(shouldFetchNextListBlobsPage(
    34  		&ListBlobsOutput{
    35  			IsTruncated: false,
    36  			Prefixes:    []BlobPrefixOutput{{Prefix: PString("prefix-has-dash/")}},
    37  		}),
    38  		Equals, false)
    39  	t.Assert(shouldFetchNextListBlobsPage(
    40  		&ListBlobsOutput{
    41  			IsTruncated: false,
    42  			Items:       []BlobItemOutput{{Key: PString("item-has-dash")}},
    43  		}),
    44  		Equals, false)
    45  
    46  	// Last Item and last Prefix are both "normal". All chars in their
    47  	// name (not path) are > '/' => ***FALSE***
    48  	t.Assert(shouldFetchNextListBlobsPage(
    49  		&ListBlobsOutput{
    50  			IsTruncated: true,
    51  			Items: []BlobItemOutput{
    52  				{Key: PString("w-o-w/item-has-dash")},
    53  				{Key: PString("w-o-w/item")}},
    54  			Prefixes: []BlobPrefixOutput{
    55  				{Prefix: PString("w-o-w/prefix-has-dash/")},
    56  				{Prefix: PString("w-o-w/prefix/")}},
    57  		}),
    58  		Equals, false)
    59  
    60  	// Last Item's name has '-' ('-' < '/'); No prefixes => ***TRUE***
    61  	t.Assert(shouldFetchNextListBlobsPage(
    62  		&ListBlobsOutput{
    63  			IsTruncated: true,
    64  			Items:       []BlobItemOutput{{Key: PString("wow/item-has-dash")}},
    65  		}),
    66  		Equals, true)
    67  	// Last Item's name has '-' ('-' < '/'); Has normal prefixes  => ***TRUE***
    68  	t.Assert(shouldFetchNextListBlobsPage(
    69  		&ListBlobsOutput{
    70  			IsTruncated: true,
    71  			Prefixes:    []BlobPrefixOutput{{Prefix: PString("wow/prefix")}},
    72  			Items:       []BlobItemOutput{{Key: PString("wow/item-has-dash")}},
    73  		}),
    74  		Equals, true)
    75  
    76  	// Last Prefix's name has '-' ('-' < '/'); No Items => ***TRUE***
    77  	t.Assert(shouldFetchNextListBlobsPage(
    78  		&ListBlobsOutput{
    79  			IsTruncated: true,
    80  			Prefixes:    []BlobPrefixOutput{{Prefix: PString("wow/prefix-has-dash/")}},
    81  		}),
    82  		Equals, true)
    83  	// Last Prefix's name has '-' ('-' < '/'); Has normal items => ***TRUE***
    84  	t.Assert(shouldFetchNextListBlobsPage(
    85  		&ListBlobsOutput{
    86  			IsTruncated: true,
    87  			Items:       []BlobItemOutput{{Key: PString("wow/item")}},
    88  			Prefixes:    []BlobPrefixOutput{{Prefix: PString("wow/prefix-has-dash/")}},
    89  		}),
    90  		Equals, true)
    91  
    92  }