Skip to content

Commit

Permalink
Add scale activation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasgun committed Aug 26, 2022
1 parent 986ca91 commit 1a4b026
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
15 changes: 15 additions & 0 deletions pkg/kn/commands/service/configuration_edit_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"gotest.tools/v3/assert"
"knative.dev/client/pkg/kn/commands"
"knative.dev/client/pkg/util"
"knative.dev/serving/pkg/apis/autoscaling"
)

func TestApplyPullPolicyFlag(t *testing.T) {
Expand Down Expand Up @@ -60,3 +61,17 @@ func TestScaleMetric(t *testing.T) {
err := editFlags.Apply(&svc, nil, cmd)
assert.NilError(t, err)
}

func TestScaleActivation(t *testing.T) {
var editFlags ConfigurationEditFlags
knParams := &commands.KnParams{}
cmd, _, _ := commands.CreateTestKnCommand(NewServiceCreateCommand(knParams), knParams)

editFlags.AddCreateFlags(cmd)
svc := createTestService("test-svc", []string{"test-svc-00001"}, goodConditions())
cmd.SetArgs([]string{"--scale-activation", "2"})
cmd.Execute()
err := editFlags.Apply(&svc, nil, cmd)
assert.NilError(t, err)
assert.Equal(t, svc.Spec.Template.Annotations[autoscaling.ActivationScaleKey], "2")
}
20 changes: 19 additions & 1 deletion test/e2e/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"testing"

Expand All @@ -31,6 +32,7 @@ import (
"knative.dev/client/pkg/util"
network "knative.dev/networking/pkg/apis/networking"
pkgtest "knative.dev/pkg/test"
"knative.dev/serving/pkg/apis/autoscaling"
"knative.dev/serving/pkg/apis/serving"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
)
Expand Down Expand Up @@ -90,7 +92,10 @@ func TestService(t *testing.T) {
serviceDeleteAll(r)

t.Log("create services with volume mounts and subpaths")
serviceCreateWithMount(r)
//serviceCreateWithMount(r)

t.Log("create service with scale activation")
serviceCreateActivation(r, "svc1", 2)
}

func serviceCreatePrivate(r *test.KnRunResultCollector, serviceName string) {
Expand Down Expand Up @@ -274,3 +279,16 @@ func serviceDescribeMount(r *test.KnRunResultCollector, serviceName, hostPath, s
r.T().Log("check volume mount subpath is the same as given")
assert.Equal(r.T(), subPath, volumeMount.SubPath)
}

func serviceCreateActivation(r *test.KnRunResultCollector, serviceName string, activation int) {
out := r.KnTest().Kn().Run("service", "create", serviceName,
"--image", pkgtest.ImagePath("helloworld"), "--scale-activation", strconv.Itoa(activation))
r.AssertNoError(out)
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "service", serviceName, "creating", "namespace", r.KnTest().Kn().Namespace(), "ready"))

out = r.KnTest().Kn().Run("service", "describe", serviceName, "-o", "json")
r.AssertNoError(out)
var svc servingv1.Service
json.Unmarshal([]byte(out.Stdout), &svc)
assert.Check(r.T(), svc.Spec.Template.Annotations[autoscaling.ActivationScaleKey] == "2")
}

0 comments on commit 1a4b026

Please sign in to comment.