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]>
  • Loading branch information
nitishkumar71 committed Dec 1, 2021
1 parent 3cc8f29 commit 453cf64
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 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
24 changes: 23 additions & 1 deletion tests/deploy_test.go
Original file line number Diff line number Diff line change
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 @@ -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", deploy.Limits.Memory, status.Limits.Memory)
}
}

if !reflect.DeepEqual(deploy.Requests, status.Requests) {
Expand Down
11 changes: 11 additions & 0 deletions 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 @@ -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

0 comments on commit 453cf64

Please sign in to comment.