fnctl: fix regression on environment transcription (#232)

Reverts https://github.com/iron-io/functions/pull/225 and prove
correctness with a test.
This commit is contained in:
C Cirello
2016-11-07 19:21:58 +01:00
committed by Seif Lotfy سيف لطفي
parent cc38ccd253
commit 946cd85119
2 changed files with 26 additions and 1 deletions

View File

@@ -151,7 +151,7 @@ func envAsHeader(req *http.Request, selectedEnv []string) {
for _, e := range detectedEnv {
kv := strings.Split(e, "=")
name := kv[0]
req.Header.Set(name, kv[1])
req.Header.Set(name, os.Getenv(name))
}
}

25
fnctl/routes_test.go Normal file
View File

@@ -0,0 +1,25 @@
package main
import (
"net/http"
"os"
"testing"
)
func TestEnvAsHeader(t *testing.T) {
const expectedValue = "v=v"
os.Setenv("k", expectedValue)
cases := [][]string{
nil,
[]string{},
[]string{"k"},
}
for _, selectedEnv := range cases {
req, _ := http.NewRequest("GET", "http://www.example.com", nil)
envAsHeader(req, selectedEnv)
if found := req.Header.Get("k"); found != expectedValue {
t.Errorf("not found expected header: %v", found)
}
}
}