github.com/containers/podman/v4@v4.9.4/pkg/specgen/specgen_test.go (about)

     1  package specgen
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestNewSpecGeneratorWithRootfs(t *testing.T) {
    10  	idmap := "idmap"
    11  	idmapMappings := "idmap=uids=1-1-2000"
    12  	tests := []struct {
    13  		rootfs                string
    14  		expectedRootfsOverlay bool
    15  		expectedRootfs        string
    16  		expectedMapping       *string
    17  	}{
    18  		{"/root/a:b:O", true, "/root/a:b", nil},
    19  		{"/root/a:b/c:O", true, "/root/a:b/c", nil},
    20  		{"/root/a:b/c:", false, "/root/a:b/c:", nil},
    21  		{"/root/a/b", false, "/root/a/b", nil},
    22  		{"/root/a:b/c:idmap", false, "/root/a:b/c", &idmap},
    23  		{"/root/a:b/c:idmap=uids=1-1-2000", false, "/root/a:b/c", &idmapMappings},
    24  	}
    25  	for _, args := range tests {
    26  		val := NewSpecGenerator(args.rootfs, true)
    27  
    28  		assert.Equal(t, val.RootfsOverlay, args.expectedRootfsOverlay)
    29  		assert.Equal(t, val.Rootfs, args.expectedRootfs)
    30  		if args.expectedMapping == nil {
    31  			assert.Nil(t, val.RootfsMapping)
    32  		} else {
    33  			assert.NotNil(t, val.RootfsMapping)
    34  			assert.Equal(t, *val.RootfsMapping, *args.expectedMapping)
    35  		}
    36  	}
    37  }