Repository: moby/moby
File: integration/container/inspect_test.go (Go)

Code before:
		{
			doc:      "no size",
			withSize: false,
		},
		{
			doc:      "with size",
			withSize: true,
		},
	}
	for _, tc := range tests {
		t.Run(tc.doc, func(t *testing.T) {
			ctrInspect, raw, err := apiClient.ContainerInspectWithRaw(ctx, ctrID, tc.withSize)
			assert.NilError(t, err)
			assert.Check(t, is.Equal(ctrInspect.ID, ctrID))

			var rawInspect map[string]interface{}
			err = json.Unmarshal(raw, &rawInspect)
			assert.NilError(t, err, "Should produce valid JSON")

			if tc.withSize {
				if assert.Check(t, ctrInspect.SizeRw != nil) {
					// RW-layer size can be zero.
					assert.Check(t, *ctrInspect.SizeRw >= 0, "Should have a size: %d", *ctrInspect.SizeRw)
				}
				if assert.Check(t, ctrInspect.SizeRootFs != nil) {
					assert.Check(t, *ctrInspect.SizeRootFs > 0, "Should have a size: %d", *ctrInspect.SizeRootFs)
				}
				_, ok := rawInspect["SizeRw"]
				assert.Check(t, ok)
				_, ok = rawInspect["SizeRootFs"]
				assert.Check(t, ok)
			} else {
				assert.Check(t, is.Nil(ctrInspect.SizeRw))
				assert.Check(t, is.Nil(ctrInspect.SizeRootFs))
				_, ok := rawInspect["SizeRw"]
				assert.Check(t, !ok, "Should not contain SizeRw:\n%s", string(raw))
				_, ok = rawInspect["SizeRootFs"]
				assert.Check(t, !ok, "Should not contain SizeRootFs:\n%s", string(raw))
			}
		})
	}
}


Review comment (bug):
Ha! Looks like on Windows this is `0`? Maybe not supported?

```
=== FAIL: github.com/docker/docker/integration/container TestContainerInspectWithRaw/with_size (0.00s)
    inspect_test.go:183: assertion failed: *ctrInspect.SizeRootFs is <= 0: Should have a size: 0
```

Code after:
		{
			doc:      "no size",
			withSize: false,
		},
		{
			doc:      "with size",
			withSize: true,
		},
	}
	for _, tc := range tests {
		t.Run(tc.doc, func(t *testing.T) {
			ctrInspect, raw, err := apiClient.ContainerInspectWithRaw(ctx, ctrID, tc.withSize)
			assert.NilError(t, err)
			assert.Check(t, is.Equal(ctrInspect.ID, ctrID))

			var rawInspect map[string]interface{}
			err = json.Unmarshal(raw, &rawInspect)
			assert.NilError(t, err, "Should produce valid JSON")

			if tc.withSize {
				if testEnv.DaemonInfo.OSType == "windows" {
					// FIXME(thaJeztah): Windows does not support size at all, so values would always be 0.
					// See https://github.com/moby/moby/blob/2837112c8ead55cdad36eaac61bafc713b4f669a/daemon/images/image_windows.go#L12-L16
					t.Log("skip checking SizeRw, SizeRootFs on windows as it's not yet implemented")
				} else {
					if assert.Check(t, ctrInspect.SizeRw != nil) {
						// RW-layer size can be zero.
						assert.Check(t, *ctrInspect.SizeRw >= 0, "Should have a size: %d", *ctrInspect.SizeRw)
					}
					if assert.Check(t, ctrInspect.SizeRootFs != nil) {
						assert.Check(t, *ctrInspect.SizeRootFs > 0, "Should have a size: %d", *ctrInspect.SizeRootFs)
					}
				}

				_, ok := rawInspect["SizeRw"]
				assert.Check(t, ok)
				_, ok = rawInspect["SizeRootFs"]
				assert.Check(t, ok)
			} else {
				assert.Check(t, is.Nil(ctrInspect.SizeRw))
				assert.Check(t, is.Nil(ctrInspect.SizeRootFs))
				_, ok := rawInspect["SizeRw"]
				assert.Check(t, !ok, "Should not contain SizeRw:\n%s", string(raw))
				_, ok = rawInspect["SizeRootFs"]
				assert.Check(t, !ok, "Should not contain SizeRootFs:\n%s", string(raw))
			}
		})
	}
}