File: manifest_test.go

package info (click to toggle)
golang-github-gophercloud-utils 0.0~git20231010.80377ec-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 816 kB
  • sloc: sh: 20; makefile: 7
file content (72 lines) | stat: -rw-r--r-- 1,807 bytes parent folder | download | duplicates (3)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package testing

import (
	"testing"

	o "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects"
	th "github.com/gophercloud/gophercloud/testhelper"
	fake "github.com/gophercloud/gophercloud/testhelper/client"
	"github.com/gophercloud/utils/openstack/objectstorage/v1/objects"
)

func TestIsIdentical(t *testing.T) {
	cd := []objects.Manifest{
		{
			Bytes: 2,
			Hash:  "60b725f10c9c85c70d97880dfe8191b3",
		},
		{
			Bytes: 2,
			Hash:  "3b5d5c3712955042212316173ccf37be",
		},
		{
			Bytes: 2,
			Hash:  "2cd6ee2c70b0bde53fbe6cac3c8b8bb1",
		},
		{
			Bytes: 2,
			Hash:  "e29311f6f1bf1af907f9ef9f44b8328b",
		},
	}

	actual, err := objects.IsIdentical(cd, "t.txt")
	th.AssertNoErr(t, err)
	th.AssertEquals(t, true, actual)
}

func TestMultipartManifest(t *testing.T) {
	actual, err := objects.ExtractMultipartManifest([]byte(multipartManifest))
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, expectedMultipartManifest, actual)
}

func TestChunkData(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleDownloadManifestSuccessfully(t)

	downloadOpts := o.DownloadOpts{
		MultipartManifest: "get",
	}

	res := o.Download(fake.ServiceClient(), "testContainer", "testObject", downloadOpts)
	defer res.Body.Close()
	th.AssertNoErr(t, res.Err)

	body, err := res.ExtractContent()
	th.AssertNoErr(t, err)

	actualMultipartManifest, err := objects.ExtractMultipartManifest(body)
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, actualMultipartManifest, expectedMultipartManifest)

	gmo := objects.GetManifestOpts{
		ContainerName:     "testContainer",
		ObjectName:        "testObject",
		StaticLargeObject: true,
	}

	actualChunkData, err := objects.GetManifest(fake.ServiceClient(), gmo)
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, actualChunkData, expectedMultipartManifest)
}