mirror of
				https://github.com/containers/podman.git
				synced 2025-11-04 08:56:05 +08:00 
			
		
		
		
	Instead switch to github.com/moby/sys/user, which we already had as an indirect dependency. Signed-off-by: Matt Heon <mheon@redhat.com>
		
			
				
	
	
		
			159 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			159 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package rootless
 | 
						|
 | 
						|
import (
 | 
						|
	"reflect"
 | 
						|
	"testing"
 | 
						|
 | 
						|
	"github.com/moby/sys/user"
 | 
						|
	spec "github.com/opencontainers/runtime-spec/specs-go"
 | 
						|
)
 | 
						|
 | 
						|
func TestMaybeSplitMappings(t *testing.T) {
 | 
						|
	mappings := []spec.LinuxIDMapping{
 | 
						|
		{
 | 
						|
			ContainerID: 0,
 | 
						|
			HostID:      0,
 | 
						|
			Size:        2,
 | 
						|
		},
 | 
						|
	}
 | 
						|
	desiredMappings := []spec.LinuxIDMapping{
 | 
						|
		{
 | 
						|
			ContainerID: 0,
 | 
						|
			HostID:      0,
 | 
						|
			Size:        1,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			ContainerID: 1,
 | 
						|
			HostID:      1,
 | 
						|
			Size:        1,
 | 
						|
		},
 | 
						|
	}
 | 
						|
	availableMappings := []user.IDMap{
 | 
						|
		{
 | 
						|
			ID:       1,
 | 
						|
			ParentID: 1000000,
 | 
						|
			Count:    65536,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			ID:       0,
 | 
						|
			ParentID: 1000,
 | 
						|
			Count:    1,
 | 
						|
		},
 | 
						|
	}
 | 
						|
	newMappings := MaybeSplitMappings(mappings, availableMappings)
 | 
						|
	if !reflect.DeepEqual(newMappings, desiredMappings) {
 | 
						|
		t.Fatal("wrong mappings generated")
 | 
						|
	}
 | 
						|
 | 
						|
	mappings = []spec.LinuxIDMapping{
 | 
						|
		{
 | 
						|
			ContainerID: 0,
 | 
						|
			HostID:      0,
 | 
						|
			Size:        2,
 | 
						|
		},
 | 
						|
	}
 | 
						|
	desiredMappings = []spec.LinuxIDMapping{
 | 
						|
		{
 | 
						|
			ContainerID: 0,
 | 
						|
			HostID:      0,
 | 
						|
			Size:        2,
 | 
						|
		},
 | 
						|
	}
 | 
						|
	availableMappings = []user.IDMap{
 | 
						|
		{
 | 
						|
			ID:       0,
 | 
						|
			ParentID: 1000000,
 | 
						|
			Count:    65536,
 | 
						|
		},
 | 
						|
	}
 | 
						|
	newMappings = MaybeSplitMappings(mappings, availableMappings)
 | 
						|
 | 
						|
	if !reflect.DeepEqual(newMappings, desiredMappings) {
 | 
						|
		t.Fatal("wrong mappings generated")
 | 
						|
	}
 | 
						|
 | 
						|
	mappings = []spec.LinuxIDMapping{
 | 
						|
		{
 | 
						|
			ContainerID: 0,
 | 
						|
			HostID:      0,
 | 
						|
			Size:        1,
 | 
						|
		},
 | 
						|
	}
 | 
						|
	desiredMappings = []spec.LinuxIDMapping{
 | 
						|
		{
 | 
						|
			ContainerID: 0,
 | 
						|
			HostID:      0,
 | 
						|
			Size:        1,
 | 
						|
		},
 | 
						|
	}
 | 
						|
	availableMappings = []user.IDMap{
 | 
						|
		{
 | 
						|
			ID:       10000,
 | 
						|
			ParentID: 10000,
 | 
						|
			Count:    65536,
 | 
						|
		},
 | 
						|
	}
 | 
						|
 | 
						|
	newMappings = MaybeSplitMappings(mappings, availableMappings)
 | 
						|
	if !reflect.DeepEqual(newMappings, desiredMappings) {
 | 
						|
		t.Fatal("wrong mappings generated")
 | 
						|
	}
 | 
						|
 | 
						|
	mappings = []spec.LinuxIDMapping{
 | 
						|
		{
 | 
						|
			ContainerID: 0,
 | 
						|
			HostID:      0,
 | 
						|
			Size:        4,
 | 
						|
		},
 | 
						|
	}
 | 
						|
	desiredMappings = []spec.LinuxIDMapping{
 | 
						|
		{
 | 
						|
			ContainerID: 0,
 | 
						|
			HostID:      0,
 | 
						|
			Size:        1,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			ContainerID: 1,
 | 
						|
			HostID:      1,
 | 
						|
			Size:        1,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			ContainerID: 2,
 | 
						|
			HostID:      2,
 | 
						|
			Size:        1,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			ContainerID: 3,
 | 
						|
			HostID:      3,
 | 
						|
			Size:        1,
 | 
						|
		},
 | 
						|
	}
 | 
						|
	availableMappings = []user.IDMap{
 | 
						|
		{
 | 
						|
			ID:       0,
 | 
						|
			ParentID: 0,
 | 
						|
			Count:    1,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			ID:       1,
 | 
						|
			ParentID: 1,
 | 
						|
			Count:    1,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			ID:       2,
 | 
						|
			ParentID: 2,
 | 
						|
			Count:    1,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			ID:       3,
 | 
						|
			ParentID: 3,
 | 
						|
			Count:    1,
 | 
						|
		},
 | 
						|
	}
 | 
						|
 | 
						|
	newMappings = MaybeSplitMappings(mappings, availableMappings)
 | 
						|
	if !reflect.DeepEqual(newMappings, desiredMappings) {
 | 
						|
		t.Fatal("wrong mappings generated")
 | 
						|
	}
 | 
						|
}
 |