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]>
  • Loading branch information
nitishkumar71 committed Nov 5, 2021
1 parent e5e2de0 commit 0e55657
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ TEST_FUNCTIONS = \
test-scaling-disabled \
test-scaling-to-zero \
test-logger \
redirector-test
redirector-test \
memory-limit

TEST_SECRETS = \
secret-name
Expand Down
25 changes: 25 additions & 0 deletions tests/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ 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: "10M",
},
},
},
}

// Add Test case, if CERTIFIER_NAMESPACES defined
Expand Down Expand Up @@ -224,6 +238,17 @@ func compareDeployAndStatus(deploy types.FunctionDeployment, status types.Functi
return fmt.Errorf("got %v, expected Requests %v", status.Requests, deploy.Requests)
}

if deploy.Limits != nil {
if status.Limits == nil {
return fmt.Errorf("got nil Requested Limit, expected %v", *deploy.Limits)
}
deployLimits := *deploy.Limits
statusLimits := *status.Limits
if deployLimits.Memory != statusLimits.Memory {
return fmt.Errorf("got %s, expected Requested Limit %s", statusLimits.Memory, deployLimits.Memory)
}
}

if config.ProviderName != faasdProviderName {
// we expect all systems to add the `faas_function` label?
expectedLabels := copyStrMap(deploy.Labels)
Expand Down
10 changes: 10 additions & 0 deletions tests/function_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

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

Expand Down Expand Up @@ -99,5 +100,14 @@ 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,
},
}
}

return functionRequest
}

0 comments on commit 0e55657

Please sign in to comment.