mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
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:
committed by
Seif Lotfy سيف لطفي
parent
cc38ccd253
commit
946cd85119
@@ -151,7 +151,7 @@ func envAsHeader(req *http.Request, selectedEnv []string) {
|
|||||||
for _, e := range detectedEnv {
|
for _, e := range detectedEnv {
|
||||||
kv := strings.Split(e, "=")
|
kv := strings.Split(e, "=")
|
||||||
name := kv[0]
|
name := kv[0]
|
||||||
req.Header.Set(name, kv[1])
|
req.Header.Set(name, os.Getenv(name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
25
fnctl/routes_test.go
Normal file
25
fnctl/routes_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user