File: layers_test.go

package info (click to toggle)
golang-github-containers-storage 1.59.1%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,184 kB
  • sloc: sh: 630; ansic: 389; makefile: 143; awk: 12
file content (35 lines) | stat: -rw-r--r-- 662 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
package storage

import (
	"testing"
	"unsafe"

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

func TestLayerLocationFromIndex(t *testing.T) {
	tests := []struct {
		index    int
		expected layerLocations
	}{
		{0, 1},
		{1, 2},
		{2, 4},
		{3, 8},
		{4, 16},
	}
	for _, test := range tests {
		result := layerLocationFromIndex(test.index)
		assert.Equal(t, test.expected, result)
	}
}

func TestLayerLocationFromIndexAndToIndex(t *testing.T) {
	var l layerLocations
	for i := range int(unsafe.Sizeof(l) * 8) {
		location := layerLocationFromIndex(i)
		index := indexFromLayerLocation(location)
		require.Equal(t, i, index)
	}
}