MCPcopy
hub / github.com/NVIDIA/aistore / TestCompareObject

Function TestCompareObject

downloader/utils_test.go:46–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

44}
45
46func TestCompareObject(t *testing.T) {
47 tutils.CheckSkip(t, tutils.SkipTestArgs{Long: true})
48 var (
49 src = prepareObject(t)
50 dst = &downloader.DstElement{
51 Link: "https://storage.googleapis.com/minikube/iso/minikube-v0.23.2.iso.sha256",
52 }
53 )
54
55 // Modify local object to contain invalid (meta)data.
56 customMD := cos.SimpleKVs{
57 cmn.SourceObjMD: apc.ProviderAmazon,
58 cmn.VersionObjMD: "none",
59 cmn.CRC32CObjMD: "bad",
60 cmn.MD5ObjMD: "worse",
61 }
62 src.SetSize(10)
63 src.SetCustomMD(customMD)
64 equal, err := downloader.CompareObjects(src, dst)
65 tassert.CheckFatal(t, err)
66 tassert.Errorf(t, !equal, "expected the objects not to be equal")
67
68 // Check that objects are still not equal after size update.
69 src.SetSize(65)
70 equal, err = downloader.CompareObjects(src, dst)
71 tassert.CheckFatal(t, err)
72 tassert.Errorf(t, !equal, "expected the objects not to be equal")
73
74 // Check that correct CRC doesn't make them equal
75 customMD[cmn.CRC32CObjMD] = "30a991bd"
76 equal, err = downloader.CompareObjects(src, dst)
77 tassert.CheckFatal(t, err)
78 tassert.Errorf(t, !equal, "expected the objects not to be equal")
79
80 // Check that the same provider still doesn't make them equal
81 customMD[cmn.SourceObjMD] = apc.ProviderGoogle
82 equal, err = downloader.CompareObjects(src, dst)
83 tassert.CheckFatal(t, err)
84 tassert.Errorf(t, !equal, "expected the objects not to be equal")
85
86 // Finally, check that objects are equal when they have the same (provider, version)
87 src.SetCustomKey(cmn.VersionObjMD, "1503349750687573")
88 src.SetCustomKey(cmn.MD5ObjMD, "7b01d3eacc5869db6eb9137f15335d27")
89 customMD[cmn.VersionObjMD] = "1503349750687573"
90 equal, err = downloader.CompareObjects(src, dst)
91 tassert.CheckFatal(t, err)
92 tassert.Errorf(t, equal, "expected the objects to be equal")
93}
94
95func prepareObject(t *testing.T) *cluster.LOM {
96 out := tutils.PrepareObjects(t, tutils.ObjectsDesc{

Callers

nothing calls this directly

Calls 8

CheckSkipFunction · 0.92
CompareObjectsFunction · 0.92
CheckFatalFunction · 0.92
ErrorfFunction · 0.92
prepareObjectFunction · 0.85
SetCustomKeyMethod · 0.65
SetSizeMethod · 0.45
SetCustomMDMethod · 0.45

Tested by

no test coverage detected