Skip to content

Commit

Permalink
fix linter issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Shell32-Natsu committed Aug 5, 2020
1 parent 8cdc97a commit 8cd7c13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion kyaml/fn/runtime/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ func (c *Filter) setupExec() {
c.Exec.Args = args
}

var tmpDirEnvKey string = "TMPDIR"

// getArgs returns the command + args to run to spawn the container
func (c *Filter) getCommand() (string, []string) {
// run the container using docker. this is simpler than using the docker
Expand Down Expand Up @@ -197,7 +199,7 @@ func (c *Filter) getCommand() (string, []string) {
// export the local environment vars to the container
for _, pair := range os.Environ() {
items := strings.Split(pair, "=")
if items[0] == "" || items[1] == "" || items[0] == "TMPDIR" {
if items[0] == "" || items[1] == "" || items[0] == tmpDirEnvKey {
continue
}
args = append(args, "-e", items[0])
Expand Down
8 changes: 4 additions & 4 deletions kyaml/fn/runtime/container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ metadata:
for _, e := range os.Environ() {
// the process env
parts := strings.Split(e, "=")
if parts[0] == "" || parts[1] == "" || parts[0] == "TMPDIR" {
if parts[0] == "" || parts[1] == "" || parts[0] == tmpDirEnvKey {
continue
}
tt.expectedArgs = append(tt.expectedArgs, "-e", parts[0])
Expand Down Expand Up @@ -212,13 +212,13 @@ func TestFilter_ExitCode(t *testing.T) {
}

func TestIgnoreEnv(t *testing.T) {
os.Setenv("TMPDIR", "")
os.Setenv(tmpDirEnvKey, "")

fltr := Filter{Image: "example.com:version"}
_, args := fltr.getCommand()
for _, arg := range args {
if arg == "TMPDIR" {
t.Fatalf("TMPDIR should not be exported to container")
if arg == tmpDirEnvKey {
t.Fatalf("%s should not be exported to container", tmpDirEnvKey)
}
}
}

0 comments on commit 8cd7c13

Please sign in to comment.