Skip to content

Commit

Permalink
change untagRevision to return bool and add traffic e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhelfand committed Jun 10, 2020
1 parent 07a0e2f commit 3ae19db
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/kn/traffic/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ func (e ServiceTraffic) isTagPresent(tag string) bool {
return false
}

func (e ServiceTraffic) untagRevision(tag string, serviceName string) string {
func (e ServiceTraffic) untagRevision(tag string, serviceName string) bool {
for i, target := range e {
if target.Tag == tag {
e[i].Tag = ""
return ""
return true
}
}

return tag
return false
}

func (e ServiceTraffic) isRevisionPresent(revision string) bool {
Expand Down Expand Up @@ -281,9 +281,9 @@ func Compute(cmd *cobra.Command, targets []servingv1.TrafficTarget,
// First precedence: Untag revisions
var errTagNames []string
for _, tag := range trafficFlags.UntagRevisions {
tagName := traffic.untagRevision(tag, serviceName)
if tagName != "" {
errTagNames = append(errTagNames, tagName)
tagExists := traffic.untagRevision(tag, serviceName)
if !tagExists {
errTagNames = append(errTagNames, tag)
}
}

Expand Down
53 changes: 53 additions & 0 deletions test/e2e/traffic_split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,59 @@ func TestTrafficSplit(t *testing.T) {
// In spec of traffic block (not status) either latestReadyRevision:true or revisionName can be given per target
newTargetFields("latest", rev2, 0, false)}

verifyTargets(r, serviceName, expectedTargets)
test.ServiceDelete(r, serviceName)
},
)
t.Run("UntagNonExistentTag",
func(t *testing.T) {
t.Log("use --untag on a tag that does not exist")
r := test.NewKnRunResultCollector(t, it)
defer r.DumpIfFailed()

serviceName := test.GetNextServiceName(serviceBase)
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
serviceCreateWithOptions(r, serviceName, "--revision-name", rev1)

// existing state: a revision exist with latest tag
test.ServiceUpdate(r, serviceName, "--tag", fmt.Sprintf("%s=latest", rev1))

// desired state of revision tags: rev1=latest
// attempt to untag a tag that does not exist for the service's revisions
test.ServiceUpdate(r, serviceName, "--untag", "foo")

// state should remain the same as error from --untag will stop service update
expectedTargets := []TargetFields{
newTargetFields("latest", rev1, 0, false),
}

verifyTargets(r, serviceName, expectedTargets)
test.ServiceDelete(r, serviceName)
},
)
t.Run("UntagNonExistentTagAndValidTag",
func(t *testing.T) {
t.Log("use --untag on a tag that does not exist in addition to a tag that exists")
r := test.NewKnRunResultCollector(t, it)
defer r.DumpIfFailed()

serviceName := test.GetNextServiceName(serviceBase)
rev1 := fmt.Sprintf("%s-rev-1", serviceName)
serviceCreateWithOptions(r, serviceName, "--revision-name", rev1)

// existing state: a revision exist with latest tag
test.ServiceUpdate(r, serviceName, "--tag", fmt.Sprintf("%s=latest", rev1))

// desired state of revision tags: rev1=latest
// attempt to untag a tag that does not exist for the service's revisions (foo)
// and also untag a tag that exists (latest)
test.ServiceUpdate(r, serviceName, "--untag", "latest", "--untag", "foo")

// state should remain the same as error from --untag will stop service update
expectedTargets := []TargetFields{
newTargetFields("latest", rev1, 0, false),
}

verifyTargets(r, serviceName, expectedTargets)
test.ServiceDelete(r, serviceName)
},
Expand Down

0 comments on commit 3ae19db

Please sign in to comment.