File: blob_test.go

package info (click to toggle)
gittuf 0.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,692 kB
  • sloc: python: 85; makefile: 58; sh: 1
file content (50 lines) | stat: -rw-r--r-- 1,217 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright The gittuf Authors
// SPDX-License-Identifier: Apache-2.0

package gitinterface

import (
	"testing"

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

func TestRepositoryReadBlob(t *testing.T) {
	tempDir := t.TempDir()
	repo := CreateTestGitRepository(t, tempDir, false)

	contents := []byte("test file read")
	expectedBlobID, err := NewHash("2ecdd330475d93568ed27f717a84a7fe207d1c58")
	require.Nil(t, err)

	blobID, err := repo.WriteBlob(contents)
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, expectedBlobID, blobID)

	t.Run("read existing blob", func(t *testing.T) {
		readContents, err := repo.ReadBlob(blobID)
		assert.Nil(t, err)
		assert.Equal(t, contents, readContents)
	})

	t.Run("read non-existing blob", func(t *testing.T) {
		_, err := repo.ReadBlob(ZeroHash)
		assert.NotNil(t, err)
	})
}

func TestRepositoryWriteBlob(t *testing.T) {
	tempDir := t.TempDir()
	repo := CreateTestGitRepository(t, tempDir, false)

	contents := []byte("test file write")
	expectedBlobID, err := NewHash("999c05e9578e5d244920306842f516789a2498f7")
	require.Nil(t, err)

	blobID, err := repo.WriteBlob(contents)
	assert.Nil(t, err)
	assert.Equal(t, expectedBlobID, blobID)
}