mirror of
https://github.com/docker/buildx.git
synced 2024-11-22 15:37:16 +08:00
Support empty env var when it can't be unset
Signed-off-by: David Gageot <david.gageot@docker.com>
This commit is contained in:
parent
105c214d15
commit
be7e91899b
@ -15,8 +15,8 @@ import (
|
|||||||
const DockerfileLabel = "com.docker.image.source.entrypoint"
|
const DockerfileLabel = "com.docker.image.source.entrypoint"
|
||||||
|
|
||||||
func addGitProvenance(ctx context.Context, contextPath string, dockerfilePath string) (map[string]string, error) {
|
func addGitProvenance(ctx context.Context, contextPath string, dockerfilePath string) (map[string]string, error) {
|
||||||
v, ok := os.LookupEnv("BUILDX_GIT_LABELS")
|
v := os.Getenv("BUILDX_GIT_LABELS")
|
||||||
if !ok || contextPath == "" {
|
if (v != "1" && v != "full") || contextPath == "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
labels := make(map[string]string, 0)
|
labels := make(map[string]string, 0)
|
||||||
|
@ -64,6 +64,14 @@ func TestAddGitProvenanceDataWithoutEnv(t *testing.T) {
|
|||||||
assert.Nilf(t, labels, "No labels expected")
|
assert.Nilf(t, labels, "No labels expected")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAddGitProvenanceDataWitEmptyEnv(t *testing.T) {
|
||||||
|
defer setupTest(t)(t)
|
||||||
|
os.Setenv("BUILDX_GIT_LABELS", "")
|
||||||
|
labels, err := addGitProvenance(context.Background(), repoDir, filepath.Join(repoDir, "Dockerfile"))
|
||||||
|
assert.Nilf(t, err, "No error expected")
|
||||||
|
assert.Nilf(t, labels, "No labels expected")
|
||||||
|
}
|
||||||
|
|
||||||
func TestAddGitProvenanceDataWithoutLabels(t *testing.T) {
|
func TestAddGitProvenanceDataWithoutLabels(t *testing.T) {
|
||||||
defer setupTest(t)(t)
|
defer setupTest(t)(t)
|
||||||
os.Setenv("BUILDX_GIT_LABELS", "full")
|
os.Setenv("BUILDX_GIT_LABELS", "full")
|
||||||
|
Loading…
Reference in New Issue
Block a user