@@ -5,6 +5,8 @@ package e2e_test
55import (
66 "bytes"
77 "context"
8+ "crypto/sha256"
9+ "encoding/hex"
810 "os"
911 "path/filepath"
1012 "testing"
@@ -110,7 +112,7 @@ func TestArtifactSyncTwoInstanceFolder(t *testing.T) {
110112 3 ,
111113 )
112114
113- writeCompleteCorruptCheckpoint (t , target )
115+ publishCompleteCorruptCheckpoint (t , target )
114116 afterCorruptionA := syncArtifactNode (t , nodeA , target )
115117 assert .Equal (t , 1 , afterCorruptionA .Quarantined )
116118 afterCorruptionB := syncArtifactNode (t , nodeB , target )
@@ -268,39 +270,60 @@ func writeArtifactSyncSource(
268270 require .NoError (t , os .WriteFile (path , content , 0o600 ))
269271}
270272
271- func writeCompleteCorruptCheckpoint (
273+ func publishCompleteCorruptCheckpoint (
272274 t * testing.T ,
273275 target string ,
274276) {
275277 t .Helper ()
276278 origin := "broken-a7b8c9"
279+ body := []byte (`{"v":1}` )
277280 ref , err := artifact .NewRef (
278281 origin ,
279282 artifact .KindCheckpoints ,
280283 "cp-0000000001.json" ,
281284 )
282285 require .NoError (t , err )
283- wire , err := artifact .ToWireRef (ref )
286+ sum := sha256 .Sum256 (body )
287+ identity , err := artifact .NewIdentity (
288+ hex .EncodeToString (sum [:]),
289+ int64 (len (body )),
290+ )
284291 require .NoError (t , err )
285- directory := filepath .Join (
286- target ,
287- origin ,
288- string (artifact .KindCheckpoints ),
292+ repository , err := artifact .OpenRepository (t .Context (), t .TempDir ())
293+ require .NoError (t , err )
294+ t .Cleanup (func () { require .NoError (t , repository .Close ()) })
295+ _ , err = repository .Content ().Create (
296+ t .Context (),
297+ ref ,
298+ identity ,
299+ "application/json" ,
300+ bytes .NewReader (body ),
289301 )
290- require .NoError (t , os . MkdirAll ( directory , 0o755 ) )
291- file , err := os . OpenFile (
292- filepath . Join ( directory , wire . Name ),
293- os . O_WRONLY | os . O_CREATE | os . O_EXCL ,
294- 0o600 ,
302+ require .NoError (t , err )
303+
304+ transport , err := artifact . OpenFolderTransport (
305+ target ,
306+ artifact. FolderTransportOptions {} ,
295307 )
296308 require .NoError (t , err )
297- encodeErr := artifact . EncodeWire (
298- context . Background (),
299- ref ,
300- bytes . NewBufferString ( `{"v":1}` ) ,
301- file ,
309+ t . Cleanup ( func () { require . NoError ( t , transport . Close ()) })
310+ result , err := transport . Exchange (
311+ t . Context () ,
312+ artifactSyncTransportStore { ArtifactStore : repository . Content ()} ,
313+ origin ,
302314 )
303- closeErr := file .Close ()
304- require .NoError (t , encodeErr )
305- require .NoError (t , closeErr )
315+ require .NoError (t , err )
316+ assert .Equal (t , 1 , result .Published )
317+ assert .False (t , result .More )
318+ }
319+
320+ type artifactSyncTransportStore struct {
321+ artifact.ArtifactStore
322+ }
323+
324+ func (artifactSyncTransportStore ) RecordTransportChanged (
325+ context.Context ,
326+ artifact.Entry ,
327+ ) error {
328+ return nil
306329}
0 commit comments