mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00

This adds a build duration metric for the build command with attributes related to the buildx driver, the error type (if any), and which options were used to perform the build from a subset of the options. This also refactors some of the utility methods used by the git tool to determine filepaths into its own separate package so they can be reused in another place. Also adds a test to ensure the resource is initialized correctly and doesn't error. The otel handler logging message is suppressed on buildx invocations so we never see the error if there's a problem with the schema url. It's so easy to mess up the schema url when upgrading OTEL that we need a proper test to make sure we haven't broken the functionality. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
30 lines
762 B
Go
30 lines
762 B
Go
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
|
|
}
|