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]>

Test case changed to binary SI from decimal SI

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

Included Suggestions

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

Prefixed Docker registery path

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

revrted wait part

Signed-off-by: Nitishkumar Singh <[email protected]>
  • Loading branch information
nitishkumar71 authored and LucasRoesler committed Apr 6, 2022
1 parent 08ab517 commit 2e39d05
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 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
37 changes: 33 additions & 4 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: "5Mi",
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 @@ -228,8 +243,22 @@ func compareDeployAndStatus(deploy types.FunctionDeployment, status types.Functi
return fmt.Errorf("incorrect Secrets: %s", err)
}

if !reflect.DeepEqual(deploy.Limits, status.Limits) {
return fmt.Errorf("got %v, expected Limits %v", status.Limits, deploy.Limits)
if 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 config.SupportCPULimits && deploy.Limits.CPU != status.Limits.CPU {
return fmt.Errorf("got %s, expected Requested Limit %s", status.Limits.CPU, deploy.Limits.CPU)
}
}

if deploy.Limits == nil && status.Limits != nil {
return fmt.Errorf("got %v, expected nil", status.Limits)
}

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 @@ -83,7 +84,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 @@ -103,6 +104,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
8 changes: 4 additions & 4 deletions tests/invoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ func invokeWithCustomEnvVarsAndQueryString(t *testing.T, functionRequest *sdk.De

func Test_Invoke(t *testing.T) {
t.Logf("Gateway: %s", config.Gateway)

imagePrefix := config.RegistryPrefix + "/"
cases := []FunctionTestCase{
{
name: "Invoke test with different verbs",
function: types.FunctionDeployment{
Image: "functions/alpine:latest",
Image: imagePrefix + "functions/alpine:latest",
Service: "env-test-verbs",
EnvProcess: "env",
EnvVars: map[string]string{},
Expand All @@ -89,7 +89,7 @@ func Test_Invoke(t *testing.T) {
{
name: "Invoke propogates redirect to the caller",
function: types.FunctionDeployment{
Image: "theaxer/redirector:latest",
Image: imagePrefix + "theaxer/redirector:latest",
Service: "redirector-test",
EnvProcess: "./handler",
EnvVars: map[string]string{"destination": "http://example.com"},
Expand All @@ -99,7 +99,7 @@ func Test_Invoke(t *testing.T) {
{
name: "Invoke with custom env vars and query string",
function: types.FunctionDeployment{
Image: "functions/alpine:latest",
Image: imagePrefix + "functions/alpine:latest",
Service: "env-test",
EnvProcess: "env",
EnvVars: map[string]string{"custom_env": "custom_env_value"},
Expand Down
4 changes: 4 additions & 0 deletions tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func TestMain(m *testing.M) {
config.SecretUpdate = false
}

config.SupportCPULimits = config.ProviderName != faasdProviderName

prettyConfig, err := json.MarshalIndent(config, "", "\t")
if err != nil {
log.Fatalf("Config Pretty Print Failed with %s", err)
Expand Down Expand Up @@ -132,6 +134,8 @@ type Config struct {

// registry prefix for private registry
RegistryPrefix string

SupportCPULimits bool
}

func FromEnv(config *Config) {
Expand Down

0 comments on commit 2e39d05

Please sign in to comment.