Skip to content

Commit

Permalink
provision sequence audience using channel audience
Browse files Browse the repository at this point in the history
  • Loading branch information
md-saif-husain committed Oct 21, 2023
1 parent 16a3986 commit c2226f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/flows/v1/sequence_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (ss *SequenceStatus) setAddress(address *duckv1.Addressable) {
ss.Address = duckv1.Addressable{}
sCondSet.Manage(ss).MarkUnknown(SequenceConditionAddressable, "emptyAddress", "addressable is nil")
} else {
ss.Address = duckv1.Addressable{URL: address.URL}
ss.Address = duckv1.Addressable{URL: address.URL, Audience: address.Audience}
sCondSet.Manage(ss).MarkTrue(SequenceConditionAddressable)
}
}
34 changes: 27 additions & 7 deletions pkg/apis/flows/v1/sequence_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1

import (
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -69,6 +70,7 @@ func getSubscription(name string, ready bool) *messagingv1.Subscription {

func getChannelable(ready bool) *eventingduckv1.Channelable {
URL := apis.HTTP("example.com")
channelAudience := fmt.Sprintf("messaging.knative.dev/inmemorychannel/%s/%s", "testNS", "test-imc")
c := eventingduckv1.Channelable{
TypeMeta: metav1.TypeMeta{
APIVersion: "messaging.knative.dev/v1",
Expand All @@ -83,7 +85,7 @@ func getChannelable(ready bool) *eventingduckv1.Channelable {
Type: apis.ConditionReady,
Status: corev1.ConditionTrue,
}})
c.Status.Address = &duckv1.Addressable{URL: URL}
c.Status.Address = &duckv1.Addressable{URL: URL, Audience: &channelAudience}
} else {
c.Status.SetConditions([]apis.Condition{{
Type: apis.ConditionReady,
Expand Down Expand Up @@ -369,13 +371,15 @@ func TestSequenceReady(t *testing.T) {
func TestSequencePropagateSetAddress(t *testing.T) {
URL := apis.HTTP("example.com")
URL2 := apis.HTTP("another.example.com")
channelAudience := fmt.Sprintf("messaging.knative.dev/inmemorychannel/%s/%s", "testNS", "test-imc")
tests := []struct {
name string
status SequenceStatus
address *duckv1.Addressable
want duckv1.Addressable
wantStatus corev1.ConditionStatus
wantAddress string
name string
status SequenceStatus
address *duckv1.Addressable
want duckv1.Addressable
wantStatus corev1.ConditionStatus
wantAddress string
wantAudience string
}{{
name: "nil",
status: SequenceStatus{},
Expand Down Expand Up @@ -422,6 +426,14 @@ func TestSequencePropagateSetAddress(t *testing.T) {
address: &duckv1.Addressable{URL: nil},
want: duckv1.Addressable{},
wantStatus: corev1.ConditionUnknown,
}, {
name: "audience",
status: SequenceStatus{},
address: &duckv1.Addressable{URL: URL, Audience: &channelAudience},
want: duckv1.Addressable{URL: URL, Audience: &channelAudience},
wantStatus: corev1.ConditionTrue,
wantAddress: "http://example.com",
wantAudience: "messaging.knative.dev/inmemorychannel/testNS/test-imc",
}}

for _, tt := range tests {
Expand All @@ -440,9 +452,17 @@ func TestSequencePropagateSetAddress(t *testing.T) {
if got.URL != nil {
gotAddress = got.URL.String()
}

if diff := cmp.Diff(tt.wantAddress, gotAddress); diff != "" {
t.Error("unexpected address.url (-want, +got) =", diff)
}
gotAudience := ""
if got.Audience != nil {
gotAudience = *got.Audience
}
if diff := cmp.Diff(tt.wantAudience, gotAudience); diff != "" {
t.Error("unexpected address.audience (-want, +got) =", diff)
}
})
}
}

0 comments on commit c2226f2

Please sign in to comment.