history: don't import build package

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2026-02-11 10:29:47 +01:00
parent 06f438a4c8
commit 7899695fa6
8 changed files with 156 additions and 35 deletions
+25
View File
@@ -0,0 +1,25 @@
package urlutil
import (
"strings"
"github.com/moby/buildkit/frontend/dockerfile/dfgitutil"
)
// IsHTTPURL returns true if the provided str is an HTTP(S) URL by checking if
// it has a http:// or https:// scheme. No validation is performed to verify if
// the URL is well-formed.
func IsHTTPURL(str string) bool {
return strings.HasPrefix(str, "https://") || strings.HasPrefix(str, "http://")
}
// IsRemoteURL returns true for HTTP(S) URLs and Git references.
func IsRemoteURL(c string) bool {
if IsHTTPURL(c) {
return true
}
if _, ok, _ := dfgitutil.ParseGitRef(c); ok {
return true
}
return false
}
+110
View File
@@ -0,0 +1,110 @@
package urlutil
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestIsHTTPURL(t *testing.T) {
tests := []struct {
name string
input string
want bool
}{
{
name: "https url",
input: "https://example.com/repo.git",
want: true,
},
{
name: "http url",
input: "http://example.com/repo.git",
want: true,
},
{
name: "http prefix only",
input: "http://",
want: true,
},
{
name: "non-http protocol",
input: "git://example.com/repo.git",
want: false,
},
{
name: "no protocol",
input: "example.com/repo.git",
want: false,
},
{
name: "uppercase protocol is not matched",
input: "HTTPS://example.com/repo.git",
want: false,
},
{
name: "leading whitespace does not match",
input: " https://example.com/repo.git",
want: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
require.Equal(t, tc.want, IsHTTPURL(tc.input))
})
}
}
func TestIsRemoteURL(t *testing.T) {
tests := []struct {
name string
input string
want bool
}{
{
name: "https url is remote",
input: "https://example.com/not-a-git-url",
want: true,
},
{
name: "http url is remote",
input: "http://example.com/path",
want: true,
},
{
name: "scp style git remote",
input: "git@github.com:moby/buildkit.git",
want: true,
},
{
name: "github shorthand git remote",
input: "github.com/moby/buildkit",
want: true,
},
{
name: "relative local path is not remote",
input: "./hack",
want: false,
},
{
name: "plain local path is not remote",
input: "hack/dockerfiles",
want: false,
},
{
name: "unknown protocol is not remote",
input: "docker-image://alpine",
want: false,
},
{
name: "empty is not remote",
input: "",
want: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
require.Equal(t, tc.want, IsRemoteURL(tc.input))
})
}
}