File: path_windows_test.go

package info (click to toggle)
docker-buildx 0.19.3%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,852 kB
  • sloc: sh: 318; makefile: 73
file content (29 lines) | stat: -rw-r--r-- 762 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package gitutil

import (
	"os"
	"testing"

	"github.com/docker/buildx/util/osutil"
	"github.com/stretchr/testify/assert"
)

func TestSanitizePathWindows(t *testing.T) {
	expected := "C:\\Users\\foobar"
	if isGitBash() {
		expected = "C:/Users/foobar"
	}
	assert.Equal(t, expected, osutil.SanitizePath("C:/Users/foobar"))
}

func isGitBash() bool {
	// The MSYSTEM environment variable is used in MSYS2 environments,
	// including Git Bash, to select the active environment. This variable
	// dictates the environment in which the shell operates, influencing
	// factors like the path prefixes, default compilers, and system libraries
	// used: https://www.msys2.org/docs/environments/
	if _, ok := os.LookupEnv("MSYSTEM"); ok {
		return true
	}
	return false
}