|
| 1 | +package bindings |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "io" |
| 6 | + "net/http" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/containers/podman/v5/pkg/domain/entities/types" |
| 10 | + . "github.com/onsi/ginkgo/v2" |
| 11 | + . "github.com/onsi/gomega" |
| 12 | +) |
| 13 | + |
| 14 | +func TestBindings(t *testing.T) { |
| 15 | + RegisterFailHandler(Fail) |
| 16 | + RunSpecs(t, "Bindings Suite") |
| 17 | +} |
| 18 | + |
| 19 | +var _ = Describe("APIResponse Process method", func() { |
| 20 | + |
| 21 | + createMockResponse := func(jsonResponse string, statusCode int) *APIResponse { |
| 22 | + response := &http.Response{ |
| 23 | + StatusCode: statusCode, |
| 24 | + Body: io.NopCloser(bytes.NewBufferString(jsonResponse)), |
| 25 | + Header: make(http.Header), |
| 26 | + } |
| 27 | + response.Header.Set("Content-Type", "application/json") |
| 28 | + return &APIResponse{Response: response} |
| 29 | + } |
| 30 | + |
| 31 | + Describe("when processing SystemPruneReport", func() { |
| 32 | + Context("with the exact JSON that caused the original marshalling error", func() { |
| 33 | + It("should successfully unmarshal the response", func() { |
| 34 | + // This is the exact JSON that was causing the unmarshalling error |
| 35 | + jsonResponse := `{ |
| 36 | + "PodPruneReport": null, |
| 37 | + "ContainerPruneReports": [ |
| 38 | + { |
| 39 | + "Id": "aec04392e9b2fe7c4a36bc0cfa206dee35d7e403f7189df658ce909ccd598db7", |
| 40 | + "Size": 8219 |
| 41 | + }, |
| 42 | + { |
| 43 | + "Id": "3d8a8789524a0c44a61baa49ceedda7be069b0b3d01255b24013d2fb82168c7e", |
| 44 | + "Err": "replacing mount point \"/tmp/CI_7Qsy/podman-e2e-213135586/subtest-1767990215/p/root/overlay/d9f554276b923c07bf708858b5f35774f9d2924fa4094b1583e56b33ae357af1/merged\": directory not empty", |
| 45 | + "Size": 7238 |
| 46 | + }, |
| 47 | + { |
| 48 | + "Id": "e9ef46f3a3cd43c929b19a01013be4d052bcb228333e61dcb8eb7dd270ae44c2", |
| 49 | + "Size": 0 |
| 50 | + } |
| 51 | + ], |
| 52 | + "ImagePruneReports": null, |
| 53 | + "NetworkPruneReports": null, |
| 54 | + "VolumePruneReports": null, |
| 55 | + "ReclaimedSpace": 15457 |
| 56 | + }` |
| 57 | + |
| 58 | + apiResponse := createMockResponse(jsonResponse, 200) |
| 59 | + var report types.SystemPruneReport |
| 60 | + |
| 61 | + err := apiResponse.Process(&report) |
| 62 | + Expect(err).ToNot(HaveOccurred()) |
| 63 | + |
| 64 | + Expect(report.ContainerPruneReports).To(HaveLen(3)) |
| 65 | + Expect(report.ReclaimedSpace).To(Equal(uint64(15457))) |
| 66 | + |
| 67 | + first := report.ContainerPruneReports[0] |
| 68 | + Expect(first.Id).To(Equal("aec04392e9b2fe7c4a36bc0cfa206dee35d7e403f7189df658ce909ccd598db7")) |
| 69 | + Expect(first.Size).To(Equal(uint64(8219))) |
| 70 | + Expect(first.Err).To(BeNil()) |
| 71 | + |
| 72 | + second := report.ContainerPruneReports[1] |
| 73 | + Expect(second.Id).To(Equal("3d8a8789524a0c44a61baa49ceedda7be069b0b3d01255b24013d2fb82168c7e")) |
| 74 | + Expect(second.Size).To(Equal(uint64(7238))) |
| 75 | + Expect(second.Err).ToNot(BeNil()) |
| 76 | + expectedErr := `replacing mount point "/tmp/CI_7Qsy/podman-e2e-213135586/subtest-1767990215/p/root/overlay/d9f554276b923c07bf708858b5f35774f9d2924fa4094b1583e56b33ae357af1/merged": directory not empty` |
| 77 | + Expect(second.Err.Error()).To(Equal(expectedErr)) |
| 78 | + |
| 79 | + third := report.ContainerPruneReports[2] |
| 80 | + Expect(third.Id).To(Equal("e9ef46f3a3cd43c929b19a01013be4d052bcb228333e61dcb8eb7dd270ae44c2")) |
| 81 | + Expect(third.Size).To(Equal(uint64(0))) |
| 82 | + Expect(third.Err).To(BeNil()) |
| 83 | + }) |
| 84 | + }) |
| 85 | + }) |
| 86 | +}) |
0 commit comments