@@ -21,6 +21,7 @@ import (
2121 "github.com/docker/docker/oci"
2222 "github.com/docker/docker/pkg/stringid"
2323 "github.com/docker/docker/testutil"
24+ "github.com/docker/go-units"
2425 ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2526 "gotest.tools/v3/assert"
2627 is "gotest.tools/v3/assert/cmp"
@@ -790,3 +791,42 @@ func TestContainerdContainerImageInfo(t *testing.T) {
790791 assert .Equal (t , ctr .Image , "" )
791792 }
792793}
794+
795+ func TestContainerdSnapshotQuota (t * testing.T ) {
796+ skip .If (t , ! testEnv .RuntimeIsWindowsContainerd () || ! testEnv .UsingSnapshotter (), "Only testing windows snapshotter runtime" )
797+
798+ ctx := setupTest (t )
799+
800+ apiClient := testEnv .APIClient ()
801+ defer apiClient .Close ()
802+
803+ info , err := apiClient .Info (ctx )
804+ assert .NilError (t , err )
805+
806+ skip .If (t , info .Containerd == nil , "requires containerd" )
807+
808+ const containerSize = "32G"
809+ expectedSize , err := units .RAMInBytes (containerSize )
810+ assert .NilError (t , err )
811+
812+ id := testContainer .Create (ctx , t , apiClient , func (cfg * testContainer.TestContainerConfig ) {
813+ cfg .Config .Image = "mcr.microsoft.com/windows/servercore:ltsc2022"
814+ cfg .HostConfig .StorageOpt = make (map [string ]string )
815+ cfg .HostConfig .StorageOpt ["size" ] = containerSize
816+ })
817+ defer apiClient .ContainerRemove (ctx , id , container.RemoveOptions {Force : true })
818+
819+ err = apiClient .ContainerStart (ctx , id , container.StartOptions {})
820+ assert .NilError (t , err )
821+
822+ c8dClient , err := containerd .New (info .Containerd .Address , containerd .WithDefaultNamespace (info .Containerd .Namespaces .Containers ))
823+ assert .NilError (t , err )
824+ defer c8dClient .Close ()
825+
826+ snapshotInfo , err := c8dClient .SnapshotService ("windows" ).Stat (ctx , id )
827+ assert .NilError (t , err )
828+
829+ rootfsLabel , ok := snapshotInfo .Labels ["containerd.io/snapshot/windows/rootfs.sizebytes" ]
830+ assert .Assert (t , ok , "Snapshot does not cotain rootfs quota label" )
831+ assert .Equal (t , rootfsLabel , expectedSize , "Container snapshot size does not match" )
832+ }
0 commit comments