Skip to content

Commit

Permalink
Add missing api and tests for sink and run codegen
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Wessendorf <[email protected]>
  • Loading branch information
matzew committed Oct 16, 2024
1 parent ad4a9d2 commit 7ea017f
Show file tree
Hide file tree
Showing 9 changed files with 584 additions and 449 deletions.
447 changes: 0 additions & 447 deletions docs/eventing-api.md

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions pkg/apis/sinks/v1alpha1/integration_sink_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2024 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"context"
"fmt"

"knative.dev/pkg/apis"
)

// ConvertTo implements apis.Convertible
// Converts source from v1alpha1.IntegrationSink into a higher version.
func (sink *IntegrationSink) ConvertTo(ctx context.Context, obj apis.Convertible) error {
return fmt.Errorf("v1alpha1 is the highest known version, got: %T", sink)
}

// ConvertFrom implements apis.Convertible
// Converts source from a higher version into v1beta2.IntegrationSink
func (sink *IntegrationSink) ConvertFrom(ctx context.Context, obj apis.Convertible) error {
return fmt.Errorf("v1alpha1 is the highest known version, got: %T", sink)
}
34 changes: 34 additions & 0 deletions pkg/apis/sinks/v1alpha1/integration_sink_conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2024 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"context"
"testing"
)

func TestIntegrationSinkConversionBadType(t *testing.T) {
good, bad := &IntegrationSink{}, &testObject{}

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)
}
}
38 changes: 38 additions & 0 deletions pkg/apis/sinks/v1alpha1/integration_sink_defaults_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*

Check failure on line 1 in pkg/apis/sinks/v1alpha1/integration_sink_defaults_test.go

View workflow job for this annotation

GitHub Actions / style / Golang / Auto-format and Check

Please run goimports. diff --git a/pkg/apis/sinks/v1alpha1/integration_sink_defaults_test.go b/pkg/apis/sinks/v1alpha1/integration_sink_defaults_test.go index 41bdc31..fd60580 100644 --- a/pkg/apis/sinks/v1alpha1/integration_sink_defaults_test.go +++ b/pkg/apis/sinks/v1alpha1/integration_sink_defaults_test.go @@ -18,8 +18,9 @@ package v1alpha1 import ( "context" - "github.com/google/go-cmp/cmp" "testing" + + "github.com/google/go-cmp/cmp" ) func TestIntegrationSinkSetDefaults(t *testing.T) {
Copyright 2020 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"context"
"github.com/google/go-cmp/cmp"
"testing"
)

func TestIntegrationSinkSetDefaults(t *testing.T) {
testCases := map[string]struct {
initial IntegrationSink
expected IntegrationSink
}{}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {
tc.initial.SetDefaults(context.TODO())
if diff := cmp.Diff(tc.expected, tc.initial); diff != "" {
t.Fatal("Unexpected defaults (-want, +got):", diff)
}
})
}
}
115 changes: 115 additions & 0 deletions pkg/apis/sinks/v1alpha1/integration_sink_lifecycle_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*

Check failure on line 1 in pkg/apis/sinks/v1alpha1/integration_sink_lifecycle_test.go

View workflow job for this annotation

GitHub Actions / style / Golang / Auto-format and Check

Please run goimports. diff --git a/pkg/apis/sinks/v1alpha1/integration_sink_lifecycle_test.go b/pkg/apis/sinks/v1alpha1/integration_sink_lifecycle_test.go index 4cb2902..a7cfeee 100644 --- a/pkg/apis/sinks/v1alpha1/integration_sink_lifecycle_test.go +++ b/pkg/apis/sinks/v1alpha1/integration_sink_lifecycle_test.go @@ -17,11 +17,12 @@ limitations under the License. package v1alpha1 import ( + "testing" + "github.com/google/go-cmp/cmp" corev1 "k8s.io/api/core/v1" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" - "testing" ) func TestIntegrationSinkGetConditionSet(t *testing.T) {
Copyright 2020 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
"testing"
)

func TestIntegrationSinkGetConditionSet(t *testing.T) {
r := &IntegrationSink{}

if got, want := r.GetConditionSet().GetTopLevelConditionType(), apis.ConditionReady; got != want {
t.Errorf("GetTopLevelCondition=%v, want=%v", got, want)
}
}

func TestIntegrationSinkInitializeConditions(t *testing.T) {
tests := []struct {
name string
js *IntegrationSinkStatus
want *IntegrationSinkStatus
}{{
name: "empty",
js: &IntegrationSinkStatus{},
want: &IntegrationSinkStatus{
Status: duckv1.Status{
Conditions: []apis.Condition{{
Type: IntegrationSinkConditionAddressable,
Status: corev1.ConditionUnknown,
}, {
Type: IntegrationSinkConditionEventPoliciesReady,
Status: corev1.ConditionUnknown,
}, {
Type: IntegrationSinkConditionReady,
Status: corev1.ConditionUnknown,
}},
},
},
}, {
name: "one false",
js: &IntegrationSinkStatus{
Status: duckv1.Status{
Conditions: []apis.Condition{{
Type: IntegrationSinkConditionAddressable,
Status: corev1.ConditionFalse,
}},
},
},
want: &IntegrationSinkStatus{
Status: duckv1.Status{
Conditions: []apis.Condition{{
Type: IntegrationSinkConditionAddressable,
Status: corev1.ConditionFalse,
}, {
Type: IntegrationSinkConditionEventPoliciesReady,
Status: corev1.ConditionUnknown,
}, {
Type: IntegrationSinkConditionReady,
Status: corev1.ConditionUnknown,
}},
},
},
}, {
name: "one true",
js: &IntegrationSinkStatus{
Status: duckv1.Status{
Conditions: []apis.Condition{{
Type: IntegrationSinkConditionAddressable,
Status: corev1.ConditionTrue,
}},
},
},
want: &IntegrationSinkStatus{
Status: duckv1.Status{
Conditions: []apis.Condition{{
Type: IntegrationSinkConditionAddressable,
Status: corev1.ConditionTrue,
}, {
Type: IntegrationSinkConditionEventPoliciesReady,
Status: corev1.ConditionUnknown,
}, {
Type: IntegrationSinkConditionReady,
Status: corev1.ConditionUnknown,
}},
},
},
}}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
test.js.InitializeConditions()
if diff := cmp.Diff(test.want, test.js, ignoreAllButTypeAndStatus); diff != "" {
t.Error("unexpected conditions (-want, +got) =", diff)
}
})
}
}
2 changes: 1 addition & 1 deletion pkg/apis/sinks/v1alpha1/integration_sink_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var (
_ apis.Defaultable = (*IntegrationSink)(nil)
_ apis.HasSpec = (*IntegrationSink)(nil)
_ duckv1.KRShaped = (*IntegrationSink)(nil)
// _ apis.Convertible = (*IntegrationSink)(nil)
_ apis.Convertible = (*JobSink)(nil)
)

type IntegrationSinkSpec struct {
Expand Down
110 changes: 110 additions & 0 deletions pkg/apis/sinks/v1alpha1/integration_sink_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*

Check failure on line 1 in pkg/apis/sinks/v1alpha1/integration_sink_types_test.go

View workflow job for this annotation

GitHub Actions / style / Golang / Auto-format and Check

Please run goimports. diff --git a/pkg/apis/sinks/v1alpha1/integration_sink_types_test.go b/pkg/apis/sinks/v1alpha1/integration_sink_types_test.go index d148aa2..c35bf59 100644 --- a/pkg/apis/sinks/v1alpha1/integration_sink_types_test.go +++ b/pkg/apis/sinks/v1alpha1/integration_sink_types_test.go @@ -17,8 +17,9 @@ limitations under the License. package v1alpha1 import ( - "knative.dev/eventing/pkg/apis/common" "testing" + + "knative.dev/eventing/pkg/apis/common" ) func TestIntegrationSink_GetStatus(t *testing.T) {
Copyright 2024 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"knative.dev/eventing/pkg/apis/common"
"testing"
)

func TestIntegrationSink_GetStatus(t *testing.T) {
r := &IntegrationSink{
Status: IntegrationSinkStatus{},
}
if got, want := r.GetStatus(), &r.Status.Status; got != want {
t.Errorf("GetStatus=%v, want=%v", got, want)
}
}

func TestIntegrationSink_GetGroupVersionKind(t *testing.T) {
src := &IntegrationSink{}
gvk := src.GetGroupVersionKind()

if gvk.Kind != "IntegrationSink" {
t.Errorf("Should be IntegrationSink.")
}
}

func TestLog(t *testing.T) {
log := Log{
Level: "info",
ShowHeaders: true,
}

if log.Level != "info" {
t.Errorf("Log.Level = %v, want 'info'", log.Level)
}
if log.ShowHeaders != true {
t.Errorf("Log.ShowHeaders = %v, want 'false'", log.ShowHeaders)
}
}

func TestAWS(t *testing.T) {
s3 := common.AWSS3{
AWSCommon: common.AWSCommon{
Region: "eu-north-1",
},
BucketNameOrArn: "example-bucket",
}

if s3.Region != "eu-north-1" {
t.Errorf("AWSS3.Region = %v, want 'eu-north-1'", s3.Region)
}

sqs := common.AWSSQS{
AWSCommon: common.AWSCommon{
Region: "eu-north-1",
},
QueueNameOrArn: "example-queue",
}

if sqs.Region != "eu-north-1" {
t.Errorf("AWSSQS.Region = %v, want 'eu-north-1'", sqs.Region)
}

ddbStreams := common.AWSDDBStreams{
AWSCommon: common.AWSCommon{
Region: "eu-north-1",
},
Table: "example-table",
}

if ddbStreams.Region != "eu-north-1" {
t.Errorf("AWSDDBStreams.Region = %v, want 'eu-north-1'", ddbStreams.Region)
}
}

// TestAuthFieldAccess tests the HasAuth method and field access in Auth struct
func TestAuthFieldAccess(t *testing.T) {
auth := common.Auth{
Secret: &common.Secret{
Ref: &common.SecretReference{
Name: "aws-secret",
},
},
AccessKey: "access-key",
SecretKey: "secret-key",
}

if !auth.HasAuth() {
t.Error("Auth.HasAuth() = false, want true")
}

if auth.Secret.Ref.Name != "aws-secret" {
t.Errorf("Auth.Secret.Ref.Name = %v, want 'aws-secret'", auth.Secret.Ref.Name)
}
}
Loading

0 comments on commit 7ea017f

Please sign in to comment.