aboutsummaryrefslogtreecommitdiffstats
path: root/syz-cluster/pkg/blob/storage_test.go
blob: 51e7887bf46c51cf708df6aefd23d7dd2baab741 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2024 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package blob

import (
	"bytes"
	"fmt"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestLocalStorage(t *testing.T) {
	storage := NewLocalStorage(t.TempDir())
	var uris []string
	for i := 0; i < 2; i++ {
		content := fmt.Sprintf("object #%d", i)
		uri, err := storage.Write(bytes.NewReader([]byte(content)), fmt.Sprint(i))
		assert.NoError(t, err)
		uris = append(uris, uri)
	}
	for i, uri := range uris {
		readBytes, err := ReadAllBytes(storage, uri)
		assert.NoError(t, err)
		assert.EqualValues(t, fmt.Sprintf("object #%d", i), readBytes)
	}
	_, err := storage.Read(localStoragePrefix + "abcdef")
	assert.Error(t, err)
	_, err = storage.Read("abcdef")
	assert.Error(t, err)
}