Skip to content

Commit

Permalink
Support empty env var when it can't be unset
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <[email protected]>
  • Loading branch information
dgageot committed Oct 3, 2022
1 parent 105c214 commit be7e918
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
const DockerfileLabel = "com.docker.image.source.entrypoint"

func addGitProvenance(ctx context.Context, contextPath string, dockerfilePath string) (map[string]string, error) {
v, ok := os.LookupEnv("BUILDX_GIT_LABELS")
if !ok || contextPath == "" {
v := os.Getenv("BUILDX_GIT_LABELS")
if (v != "1" && v != "full") || contextPath == "" {
return nil, nil
}
labels := make(map[string]string, 0)
Expand Down
8 changes: 8 additions & 0 deletions build/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ func TestAddGitProvenanceDataWithoutEnv(t *testing.T) {
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) {
defer setupTest(t)(t)
os.Setenv("BUILDX_GIT_LABELS", "full")
Expand Down

0 comments on commit be7e918

Please sign in to comment.