Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/apis/duck/v1/subscribable_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ var (
_ apis.Convertible = (*SubscribableStatus)(nil)

_ apis.Convertible = (*SubscriberSpec)(nil)
_ apis.Convertible = (*SubscriberStatus)(nil)
)

// GetFullType implements duck.Implementable
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/duck/v1/subscribable_types_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,13 @@ func (source *SubscriberSpec) ConvertTo(ctx context.Context, sink apis.Convertib
func (sink *SubscriberSpec) ConvertFrom(ctx context.Context, source apis.Convertible) error {
return fmt.Errorf("v1 is the highest known version, got: %T", source)
}

// ConvertTo implements apis.Convertible
func (source *SubscriberStatus) ConvertTo(ctx context.Context, sink apis.Convertible) error {
return fmt.Errorf("v1 is the highest known version, got: %T", sink)
}

// ConvertFrom implements apis.Convertible
func (sink *SubscriberStatus) ConvertFrom(ctx context.Context, source apis.Convertible) error {
return fmt.Errorf("v1 is the highest known version, got: %T", source)
}
12 changes: 12 additions & 0 deletions pkg/apis/duck/v1/subscribable_types_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,15 @@ func TestSubscriberSpecConversionBadType(t *testing.T) {
t.Errorf("ConvertFrom() = %#v, wanted error", good)
}
}

func TestSubscriberStatusConversionBadType(t *testing.T) {
good, bad := &SubscriberStatus{}, &SubscriberStatus{}

if err := good.ConvertTo(context.Background(), bad); err == nil {
t.Errorf("ConvertTo() = %#v, wanted error", bad)
}

if err := good.ConvertFrom(context.Background(), bad); err == nil {
t.Errorf("ConvertFrom() = %#v, wanted error", good)
}
}
4 changes: 2 additions & 2 deletions pkg/apis/duck/v1alpha1/subscribable_types_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func TestSubscribableTypeConversionWithV1Beta1(t *testing.T) {
}
}

func TestSubscribableTypeSpecStatusConversionBadType(t *testing.T) {
func TestSubscribableTypeSpecConversionBadType(t *testing.T) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed some wrong function name while at it

good, bad := &SubscribableTypeSpec{}, &SubscribableTypeSpec{}

if err := good.ConvertTo(context.Background(), bad); err == nil {
Expand All @@ -239,7 +239,7 @@ func TestSubscribableTypeStatusConversionBadType(t *testing.T) {
}
}

func TestSubscriberSpecStatusConversionBadType(t *testing.T) {
func TestSubscriberSpecConversionBadType(t *testing.T) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed some wrong function name while at it

good, bad := &SubscriberSpec{}, &SubscriberSpec{}

if err := good.ConvertTo(context.Background(), bad); err == nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/duck/v1beta1/subscribable_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ var (
_ apis.Convertible = (*SubscribableStatus)(nil)

_ apis.Convertible = (*SubscriberSpec)(nil)
_ apis.Convertible = (*SubscriberStatus)(nil)
)

// GetFullType implements duck.Implementable
Expand Down
44 changes: 34 additions & 10 deletions pkg/apis/duck/v1beta1/subscribable_types_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,9 @@ func (source *SubscribableStatus) ConvertTo(ctx context.Context, obj apis.Conver
if len(source.Subscribers) > 0 {
sink.Subscribers = make([]eventingduckv1.SubscriberStatus, len(source.Subscribers))
for i, ss := range source.Subscribers {
sink.Subscribers[i] = eventingduckv1.SubscriberStatus{
UID: ss.UID,
ObservedGeneration: ss.ObservedGeneration,
Ready: ss.Ready,
Message: ss.Message,
sink.Subscribers[i] = eventingduckv1.SubscriberStatus{}
if err := ss.ConvertTo(ctx, &sink.Subscribers[i]); err != nil {
return err
}
}
}
Expand All @@ -95,6 +93,20 @@ func (source *SubscribableStatus) ConvertTo(ctx context.Context, obj apis.Conver
return nil
}

// ConvertTo implements apis.Convertible
func (source *SubscriberStatus) ConvertTo(ctx context.Context, obj apis.Convertible) error {
switch sink := obj.(type) {
case *eventingduckv1.SubscriberStatus:
sink.UID = source.UID
sink.ObservedGeneration = source.ObservedGeneration
sink.Ready = source.Ready
sink.Message = source.Message
default:
return fmt.Errorf("unknown version, got: %T", sink)
}
return nil
}

// ConvertFrom implements apis.Convertible.
func (sink *Subscribable) ConvertFrom(ctx context.Context, from apis.Convertible) error {
switch source := from.(type) {
Expand Down Expand Up @@ -150,11 +162,9 @@ func (sink *SubscribableStatus) ConvertFrom(ctx context.Context, obj apis.Conver
if len(source.Subscribers) > 0 {
sink.Subscribers = make([]SubscriberStatus, len(source.Subscribers))
for i, ss := range source.Subscribers {
sink.Subscribers[i] = SubscriberStatus{
UID: ss.UID,
ObservedGeneration: ss.ObservedGeneration,
Ready: ss.Ready,
Message: ss.Message,
sink.Subscribers[i] = SubscriberStatus{}
if err := sink.Subscribers[i].ConvertFrom(ctx, &ss); err != nil {
return err
}
}
}
Expand All @@ -163,3 +173,17 @@ func (sink *SubscribableStatus) ConvertFrom(ctx context.Context, obj apis.Conver
}
return nil
}

// ConvertFrom implements apis.Convertible
func (sink *SubscriberStatus) ConvertFrom(ctx context.Context, obj apis.Convertible) error {
switch source := obj.(type) {
case *eventingduckv1.SubscriberStatus:
sink.UID = source.UID
sink.ObservedGeneration = source.ObservedGeneration
sink.Ready = source.Ready
sink.Message = source.Message
default:
return fmt.Errorf("unknown version, got: %T", sink)
}
return nil
}
12 changes: 12 additions & 0 deletions pkg/apis/duck/v1beta1/subscribable_types_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,15 @@ func TestSubscriberSpecConversionBadType(t *testing.T) {
t.Errorf("ConvertFrom() = %#v, wanted error", good)
}
}

func TestSubscriberStatusConversionBadType(t *testing.T) {
good, bad := &SubscriberStatus{}, &SubscriberStatus{}

if err := good.ConvertTo(context.Background(), bad); err == nil {
t.Errorf("ConvertTo() = %#v, wanted error", bad)
}

if err := good.ConvertFrom(context.Background(), bad); err == nil {
t.Errorf("ConvertFrom() = %#v, wanted error", good)
}
}