github.com/creachadair/ffs@v0.17.3/storage/filestore/filestore_test.go (about)

     1  // Copyright 2019 Michael J. Fromberger. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package filestore_test
    16  
    17  import (
    18  	"flag"
    19  	"os"
    20  	"testing"
    21  
    22  	"github.com/creachadair/ffs/blob/storetest"
    23  	"github.com/creachadair/ffs/storage/filestore"
    24  )
    25  
    26  var keepOutput = flag.Bool("keep", false, "Keep test output after running")
    27  
    28  func TestStore(t *testing.T) {
    29  	dir, err := os.MkdirTemp("", "filestore")
    30  	if err != nil {
    31  		t.Fatalf("Creating temp directory: %v", err)
    32  	}
    33  	t.Logf("Test store: %s", dir)
    34  	if !*keepOutput {
    35  		defer os.RemoveAll(dir) // best effort cleanup
    36  	}
    37  
    38  	s, err := filestore.New(dir)
    39  	if err != nil {
    40  		t.Fatalf("Creating store in %q: %v", dir, err)
    41  	}
    42  	storetest.Run(t, s)
    43  }
    44  
    45  func TestNesting(t *testing.T) {
    46  	dir := t.TempDir()
    47  	t.Logf("Test store: %s", dir)
    48  
    49  	s, err := filestore.New(dir)
    50  	if err != nil {
    51  		t.Fatalf("Creating store in %q: %v", dir, err)
    52  	}
    53  
    54  	ctx := t.Context()
    55  	k1 := storetest.SubKV(t, ctx, s, "foo", "bar")
    56  	k2 := storetest.SubKV(t, ctx, s, "foo/_bar")
    57  
    58  	if k1d, k2d := k1.(filestore.KV).Dir(), k2.(filestore.KV).Dir(); k1d == k2d {
    59  		t.Fatalf("Equal directories: %q", k1d)
    60  	}
    61  }