File: toc_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 (47 lines) | stat: -rw-r--r-- 1,130 bytes parent folder | download | duplicates (4)
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
package toc

import (
	"testing"
)

func TestGetTOCDigest(t *testing.T) {
	t.Run("ValidTOCDigestAnnotation", func(t *testing.T) {
		expectedDigest := "sha256:8bc94b65d0b3ae8998cc0405a424ee7c3a04c72996f99eda9670374832dc9667"
		annotations := map[string]string{
			tocJSONDigestAnnotation: expectedDigest,
		}

		digestPtr, err := GetTOCDigest(annotations)
		if err != nil {
			t.Error(err)
		}
		if digestPtr == nil {
			t.Errorf("Expected a non-nil digest pointer")
		} else if digestPtr.String() != expectedDigest {
			t.Errorf("Expected digest %s, but got %s", expectedDigest, digestPtr.String())
		}
	})

	t.Run("InvalidTOCDigestAnnotation", func(t *testing.T) {
		annotations := map[string]string{
			tocJSONDigestAnnotation: "invalid-checksum",
		}

		_, err := GetTOCDigest(annotations)
		if err == nil {
			t.Fatal("Expected error")
		}
	})

	t.Run("NoValidAnnotations", func(t *testing.T) {
		annotations := map[string]string{}

		digestPtr, err := GetTOCDigest(annotations)
		if err != nil {
			t.Error(err)
		}
		if digestPtr != nil {
			t.Errorf("Expected nil digest pointer, but got %s", digestPtr.String())
		}
	})
}