Skip to content

Commit

Permalink
Include Test case for Limits
Browse files Browse the repository at this point in the history
Signed-off-by: Nitishkumar Singh <[email protected]>

Changed Memory test logic

Signed-off-by: Nitishkumar Singh <[email protected]>

Fixed makefile

Signed-off-by: Nitishkumar Singh <[email protected]>

fixed Listing functions and cases copy issue

Signed-off-by: Nitishkumar Singh <[email protected]>

corrected test values

Signed-off-by: Nitishkumar Singh <[email protected]>
  • Loading branch information
nitishkumar71 committed Dec 16, 2021
1 parent bf11f3a commit 731e6a0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ TEST_FUNCTIONS = \
test-logger \
redirector-test \
secret-string \
secret-bytes
secret-bytes \
memory-limit

TEST_SECRETS = \
secret-string \
Expand Down
28 changes: 25 additions & 3 deletions tests/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const someAnnotationJson = `{
}`

func Test_Deploy_MetaData(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

imagePath := config.RegistryPrefix + "/" + "functions/alpine:latest"
Expand Down Expand Up @@ -92,6 +92,21 @@ func Test_Deploy_MetaData(t *testing.T) {
Namespace: config.DefaultNamespace,
},
},
{
name: "Deploy with memory limit",
function: types.FunctionDeployment{
Image: imagePath,
Service: "memory-limit",
EnvProcess: "env",
Annotations: &map[string]string{},
Labels: &map[string]string{},
Namespace: config.DefaultNamespace,
Limits: &types.FunctionResources{
Memory: "5M",
CPU: "100m",
},
},
},
}

// Add Test case, if CERTIFIER_NAMESPACES defined
Expand Down Expand Up @@ -133,7 +148,7 @@ func Test_Deploy_MetaData(t *testing.T) {
for namespace, expected := range listCases {
actual, err := config.Client.ListFunctions(ctx, namespace)
if err != nil {
t.Fatalf("unable to List function in namspace: %s", err)
t.Fatalf("unable to List function in namspace %s: %s", namespace, err)
}

for _, actualF := range actual {
Expand Down Expand Up @@ -216,8 +231,15 @@ func compareDeployAndStatus(deploy types.FunctionDeployment, status types.Functi
return fmt.Errorf("incorrect Secrets: %s", err)
}

if !reflect.DeepEqual(deploy.Limits, status.Limits) {
if config.ProviderName != faasdProviderName && !reflect.DeepEqual(deploy.Limits, status.Limits) {
return fmt.Errorf("got %v, expected Limits %v", status.Limits, deploy.Limits)
} else if config.ProviderName == faasdProviderName && deploy.Limits != nil {
if status.Limits == nil {
return fmt.Errorf("got nil, expected Limits %v", deploy.Limits)
}
if deploy.Limits.Memory != status.Limits.Memory {
return fmt.Errorf("got %s, expected Requested Limit %s", status.Limits.Memory, deploy.Limits.Memory)
}
}

if !reflect.DeepEqual(deploy.Requests, status.Requests) {
Expand Down
13 changes: 12 additions & 1 deletion tests/function_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

sdk "github.com/openfaas/faas-cli/proxy"
"github.com/openfaas/faas-cli/stack"
"github.com/openfaas/faas-provider/types"
)

Expand Down Expand Up @@ -80,7 +81,7 @@ func copyNamespacesTest(cases []FunctionTestCase) []FunctionTestCase {
cases = append(cases, cnCases...)
return cases
}
return make([]FunctionTestCase, 0)
return cases
}

func createDeploymentSpec(test FunctionTestCase) *sdk.DeployFunctionSpec {
Expand All @@ -100,6 +101,16 @@ func createDeploymentSpec(test FunctionTestCase) *sdk.DeployFunctionSpec {
functionRequest.Labels = *test.function.Labels
}

if test.function.Limits != nil {
limits := *test.function.Limits
functionRequest.FunctionResourceRequest = sdk.FunctionResourceRequest{
Limits: &stack.FunctionResources{
Memory: limits.Memory,
CPU: limits.CPU,
},
}
}

return functionRequest
}

Expand Down
2 changes: 0 additions & 2 deletions tests/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ func Test_FunctionLogs(t *testing.T) {
t.Fatalf("got invoke response %s, expected %s", string(data), ns)
}

time.Sleep(30 * time.Second)

logRequest := logs.Request{
Name: c.function.FunctionName,
Namespace: c.function.Namespace,
Expand Down

0 comments on commit 731e6a0

Please sign in to comment.