Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Fixes evaluation of the file suffix for functions with base64 content…
Browse files Browse the repository at this point in the history
… type (#987)

* Fixes bug with evaluation of the file suffix for functions with base64 content type.

* Fixes gofmt issues
  • Loading branch information
me-viper authored and andresmgot committed Jan 24, 2019
1 parent 9a7482b commit daf1814
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/utils/kubelessutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func getFileName(handler, funcContentType, runtime string, lr *langruntime.Langr
return "", err
}
filename := modName
if funcContentType == "text" || funcContentType == "" || funcContentType == "url" {
if funcContentType == "text" || funcContentType == "" || funcContentType == "url" || funcContentType == "base64" {
// We can only guess the extension if the function is specified as plain text
runtimeInf, err := lr.GetRuntimeInfo(runtime)
if err == nil {
Expand Down
66 changes: 66 additions & 0 deletions pkg/utils/kubelessutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,72 @@ func TestAvoidConfigMapOverwrite(t *testing.T) {
}
}

func TestEnsureFileNames(t *testing.T) {
tests := []struct {
name string
contentType string
fileNameSuffix string
}{
{name: "text", contentType: "text", fileNameSuffix: ".py"},
{name: "empty", contentType: "", fileNameSuffix: ".py"},
{name: "base64", contentType: "base64", fileNameSuffix: ".py"},
{name: "url", contentType: "url", fileNameSuffix: ".py"},
{name: "text+zip", contentType: "text+zip", fileNameSuffix: ""},
{name: "base64+zip", contentType: "base64+zip", fileNameSuffix: ""},
{name: "url+zip", contentType: "url+zip", fileNameSuffix: ""},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
clientset := fake.NewSimpleClientset()
or := []metav1.OwnerReference{
{
Kind: "Function",
APIVersion: "kubeless.io/v1beta1",
},
}
ns := "default"
f1Name := "f1"
f1Runtime := "python"
f1 := &kubelessApi.Function{
ObjectMeta: metav1.ObjectMeta{
Name: f1Name,
Namespace: ns,
},
Spec: kubelessApi.FunctionSpec{
Function: "function",
Handler: "foo.bar",
FunctionContentType: test.contentType,
Runtime: f1Runtime,
},
}

langruntime.AddFakeConfig(clientset)
lr := langruntime.SetupLangRuntime(clientset)
lr.ReadConfigMap()

err := EnsureFuncConfigMap(clientset, f1, or, lr)
if err != nil {
t.Errorf("Unexpected error: %s", err)
}

cm, err := clientset.CoreV1().ConfigMaps(ns).Get(f1Name, metav1.GetOptions{})
if err != nil {
t.Errorf("Unexpected error: %s", err)
}

expectedData := map[string]string{
"requirements.txt": "",
"handler": "foo.bar",
"foo" + test.fileNameSuffix: "function",
}
if !reflect.DeepEqual(cm.Data, expectedData) {
t.Errorf("Unexpected ConfigMap:\n %+v\nExpecting:\n %+v", cm.Data, expectedData)
}
})
}
}

func TestEnsureService(t *testing.T) {
fakeSvc := v1.Service{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit daf1814

Please sign in to comment.