fix tests

This commit is contained in:
Niko Storni 2025-05-13 14:37:51 +02:00
parent ba8d1ba67b
commit 8ec01bf1a7
5 changed files with 14 additions and 16 deletions

View file

@ -48,7 +48,7 @@ func getServer(t *testing.T, withBlobs bool) *Server {
}
}
}
return NewServer(st)
return NewServer(st, "127.0.0.1:50505")
}
func TestAvailabilityRequest_NoBlobs(t *testing.T) {
@ -83,7 +83,7 @@ func TestAvailabilityRequest_WithBlobs(t *testing.T) {
func TestRequestFromConnection(t *testing.T) {
s := getServer(t, true)
err := s.Start("127.0.0.1:50505")
err := s.Start()
defer s.Shutdown()
if err != nil {
t.Error("error starting server", err)
@ -113,12 +113,12 @@ func TestRequestFromConnection(t *testing.T) {
func TestInvalidData(t *testing.T) {
s := getServer(t, true)
err := s.Start("127.0.0.1:50503")
err := s.Start()
defer s.Shutdown()
if err != nil {
t.Error("error starting server", err)
}
conn, err := net.Dial("tcp", "127.0.0.1:50503")
conn, err := net.Dial("tcp", "127.0.0.1:50505")
if err != nil {
t.Error("error opening connection", err)
}

View file

@ -174,6 +174,4 @@ func (s *SlowBlobStore) Delete(hash string) error {
return s.mem.Delete(hash)
}
func (s *SlowBlobStore) Shutdown() {
return
}
func (s *SlowBlobStore) Shutdown() {}

View file

@ -132,14 +132,14 @@ func (d *DiskStore) dir(hash string) string {
}
return path.Join(d.blobDir, hash[:d.prefixLength])
}
func (d *DiskStore) tmpDir(hash string) string {
func (d *DiskStore) tmpDir() string {
return path.Join(d.blobDir, "tmp")
}
func (d *DiskStore) path(hash string) string {
return path.Join(d.dir(hash), hash)
}
func (d *DiskStore) tmpPath(hash string) string {
return path.Join(d.tmpDir(hash), hash)
return path.Join(d.tmpDir(), hash)
}
func (d *DiskStore) ensureDirExists(dir string) error {
return errors.Err(os.MkdirAll(dir, 0755))
@ -154,7 +154,7 @@ func (d *DiskStore) initOnce() error {
if err != nil {
return err
}
err = d.ensureDirExists(path.Join(d.blobDir, "tmp"))
err = d.ensureDirExists(d.tmpDir())
if err != nil {
return err
}

View file

@ -18,8 +18,8 @@ func TestDiskStore_Get(t *testing.T) {
defer func() { _ = os.RemoveAll(tmpDir) }()
d := NewDiskStore(DiskParams{
Name: "test",
Dir: tmpDir,
PrefixLength: 2,
MountPoint: tmpDir,
ShardingSize: 2,
})
hash := "f428b8265d65dad7f8ffa52922bba836404cbd62f3ecfe10adba6b444f8f658938e54f5981ac4de39644d5b93d89a94b"
@ -42,8 +42,8 @@ func TestDiskStore_GetNonexistentBlob(t *testing.T) {
defer func() { _ = os.RemoveAll(tmpDir) }()
d := NewDiskStore(DiskParams{
Name: "test",
Dir: tmpDir,
PrefixLength: 2,
MountPoint: tmpDir,
ShardingSize: 2,
})
blob, _, err := d.Get("nonexistent")

View file

@ -92,8 +92,8 @@ func TestGcacheStore_loadExisting(t *testing.T) {
defer func() { _ = os.RemoveAll(tmpDir) }()
d := NewDiskStore(DiskParams{
Name: "test",
Dir: tmpDir,
PrefixLength: 2,
MountPoint: tmpDir,
ShardingSize: 2,
})
hash := "hash"