github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/vector/hnsw/commit_logger_test.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package hnsw
    13  
    14  import (
    15  	_ "fmt"
    16  	"os"
    17  	"testing"
    18  )
    19  
    20  type MockDirEntry struct {
    21  	name  string
    22  	isDir bool
    23  }
    24  
    25  func (d MockDirEntry) Name() string {
    26  	return d.name
    27  }
    28  
    29  func (d MockDirEntry) IsDir() bool {
    30  	return d.isDir
    31  }
    32  
    33  func (d MockDirEntry) Type() os.FileMode {
    34  	return os.ModePerm
    35  }
    36  
    37  func (d MockDirEntry) Info() (os.FileInfo, error) {
    38  	return nil, nil
    39  }
    40  
    41  func TestRemoveTmpScratchOrHiddenFiles(t *testing.T) {
    42  	entries := []os.DirEntry{
    43  		MockDirEntry{name: "1682473161", isDir: false},
    44  		MockDirEntry{name: ".nfs6b46801cd962afbc00000005", isDir: false},
    45  		MockDirEntry{name: ".mystery-folder", isDir: false},
    46  		MockDirEntry{name: "1682473161.condensed", isDir: false},
    47  		MockDirEntry{name: "1682473161.scratch.tmp", isDir: false},
    48  	}
    49  
    50  	expected := []os.DirEntry{
    51  		MockDirEntry{name: "1682473161", isDir: false},
    52  		MockDirEntry{name: "1682473161.condensed", isDir: false},
    53  	}
    54  
    55  	result := removeTmpScratchOrHiddenFiles(entries)
    56  
    57  	if len(result) != len(expected) {
    58  		t.Errorf("Expected %d entries, got %d", len(expected), len(result))
    59  	}
    60  
    61  	for i, entry := range result {
    62  		if entry.Name() != expected[i].Name() {
    63  			t.Errorf("Expected entry %d to be %s, got %s", i, expected[i].Name(), entry.Name())
    64  		}
    65  	}
    66  }