mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 01:53:42 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			60 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
//go:build !windows
 | 
						|
// +build !windows
 | 
						|
 | 
						|
package confutil
 | 
						|
 | 
						|
import (
 | 
						|
	"testing"
 | 
						|
 | 
						|
	"github.com/stretchr/testify/assert"
 | 
						|
	"github.com/stretchr/testify/require"
 | 
						|
)
 | 
						|
 | 
						|
func TestIsSubPath(t *testing.T) {
 | 
						|
	tests := []struct {
 | 
						|
		name     string
 | 
						|
		basePath string
 | 
						|
		subPath  string
 | 
						|
		expected bool
 | 
						|
	}{
 | 
						|
		{
 | 
						|
			name:     "SubPath is a direct subdirectory",
 | 
						|
			basePath: "/home/user",
 | 
						|
			subPath:  "/home/user/docs",
 | 
						|
			expected: true,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			name:     "SubPath is the same as basePath",
 | 
						|
			basePath: "/home/user",
 | 
						|
			subPath:  "/home/user",
 | 
						|
			expected: false,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			name:     "SubPath is not a subdirectory",
 | 
						|
			basePath: "/home/user",
 | 
						|
			subPath:  "/home/otheruser",
 | 
						|
			expected: false,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			name:     "SubPath is a nested subdirectory",
 | 
						|
			basePath: "/home/user",
 | 
						|
			subPath:  "/home/user/docs/reports",
 | 
						|
			expected: true,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			name:     "SubPath is a sibling directory",
 | 
						|
			basePath: "/home/user",
 | 
						|
			subPath:  "/home/user2",
 | 
						|
			expected: false,
 | 
						|
		},
 | 
						|
	}
 | 
						|
	for _, tt := range tests {
 | 
						|
		tt := tt
 | 
						|
		t.Run(tt.name, func(t *testing.T) {
 | 
						|
			ok, err := isSubPath(tt.basePath, tt.subPath)
 | 
						|
			require.NoError(t, err)
 | 
						|
			assert.Equal(t, tt.expected, ok)
 | 
						|
		})
 | 
						|
	}
 | 
						|
}
 |