@@ -16,6 +16,7 @@ import (
16
16
"github.com/dragonflyoss/nydus/contrib/nydusify/pkg/snapshotter/external/backend"
17
17
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
18
18
"github.com/stretchr/testify/assert"
19
+ "github.com/stretchr/testify/require"
19
20
)
20
21
21
22
type MockRemote struct {
@@ -95,13 +96,32 @@ func TestRemoteHandler_Handle(t *testing.T) {
95
96
MaybeWithHTTPFunc : func (error ) {},
96
97
}
97
98
99
+ fileCrcInfo := & FileCrcInfo {
100
+ ChunkCrcs : "0x1234,0x5678" ,
101
+ FilePath : "file1.txt" ,
102
+ }
103
+ fileCrcList := & FileCrcList {
104
+ Files : []FileCrcInfo {
105
+ * fileCrcInfo ,
106
+ },
107
+ }
108
+ crcs , err := json .Marshal (fileCrcList )
109
+ require .NoError (t , err )
110
+ annotations := map [string ]string {
111
+ filePathKey : "file1.txt" ,
112
+ crcsKey : string (crcs ),
113
+ }
98
114
handler := & RemoteHandler {
99
115
ctx : context .Background (),
100
116
imageRef : "test-image" ,
101
117
remoter : mockRemote ,
102
118
manifest : ocispec.Manifest {
103
119
Layers : []ocispec.Descriptor {
104
- {MediaType : "test-media-type" , Digest : "test-digest" },
120
+ {
121
+ MediaType : "test-media-type" ,
122
+ Digest : "test-digest" ,
123
+ Annotations : annotations ,
124
+ },
105
125
},
106
126
},
107
127
blobs : []backend.Blob {
@@ -119,6 +139,15 @@ func TestRemoteHandler_Handle(t *testing.T) {
119
139
assert .NotNil (t , backend )
120
140
assert .NotEmpty (t , fileAttrs )
121
141
assert .Equal (t , 3 , len (fileAttrs ))
142
+ assert .Equal (t , fileCrcInfo .ChunkCrcs , fileAttrs [0 ].Crcs )
143
+ assert .Equal (t , "" , fileAttrs [1 ].Crcs )
144
+
145
+ handler .manifest .Layers [0 ].Annotations = map [string ]string {
146
+ filePathKey : "file1.txt" ,
147
+ crcsKey : "0x1234,0x5678" ,
148
+ }
149
+ _ , _ , err = handler .Handle (context .Background ())
150
+ assert .Error (t , err )
122
151
}
123
152
124
153
func TestGetModelConfig (t * testing.T ) {
0 commit comments