Skip to content

Commit 6790bca

Browse files
committed
fix: adapter register tests
1 parent e90bbc8 commit 6790bca

File tree

8 files changed

+18
-1340
lines changed

8 files changed

+18
-1340
lines changed

.test/reports/unit-test-coverage.out

Lines changed: 0 additions & 905 deletions
This file was deleted.

.test/reports/unit-test.xml

Lines changed: 0 additions & 401 deletions
This file was deleted.

pkg/adapter/adapter.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type dataExample struct {
3939

4040
func (a *Adapter) newEvent() cloudevents.Event {
4141
event := cloudevents.NewEvent()
42-
event.SetType("dev.knative.sample")
42+
event.SetType("com.zeiss.eventing.sources.sample")
4343
event.SetSource("sample.knative.dev/heartbeat-source")
4444

4545
if err := event.SetData(cloudevents.ApplicationJSON, &dataExample{
@@ -61,7 +61,7 @@ func (a *Adapter) Start(ctx context.Context) error {
6161
case <-time.After(a.interval):
6262
event := a.newEvent()
6363
a.logger.Infow("Sending new event", zap.String("event", event.String()))
64-
if result := a.client.Send(context.Background(), event); !cloudevents.IsACK(result) {
64+
if result := a.client.Send(ctx, event); !cloudevents.IsACK(result) {
6565
a.logger.Infow("failed to send event", zap.String("event", event.String()), zap.Error(result))
6666
// We got an error but it could be transient, try again next interval.
6767
continue
@@ -77,6 +77,7 @@ func NewAdapter(ctx context.Context, aEnv adapter.EnvConfigAccessor, ceClient cl
7777
env := aEnv.(*envConfig) // Will always be our own envConfig type
7878
logger := logging.FromContext(ctx)
7979
logger.Infow("Heartbeat example", zap.Duration("interval", env.Interval))
80+
8081
return &Adapter{
8182
interval: env.Interval,
8283
client: ceClient,

pkg/adapter/adapter_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func TestAdapter(t *testing.T) {
4343
func verify(t *testing.T, received chan cloudevents.Event) {
4444
for _, id := range []int{0, 1, 2} {
4545
e := <-received
46-
assert.Equal(t, "dev.knative.sample", e.Type())
47-
//m := map[string]json.RawMessage{}
46+
assert.Equal(t, "com.zeiss.eventing.sources.sample", e.Type())
47+
// m := map[string]json.RawMessage{}
4848
m := &dataExample{}
4949
assert.NoError(t, e.DataAs(&m))
5050
n := &dataExample{Sequence: id, Heartbeat: "1ms"}
@@ -97,7 +97,7 @@ type sink struct {
9797

9898
func newSink(t *testing.T) *sink {
9999
s := &sink{received: make(chan cloudevents.Event)}
100-
//s.ctx, s.close = context.WithTimeout(context.Background(), 5*time.Second)
100+
// s.ctx, s.close = context.WithTimeout(context.Background(), 5*time.Second)
101101
s.ctx, s.close = context.WithTimeout(context.Background(), 1500*time.Millisecond)
102102
var err error
103103
s.listener, err = net.Listen("tcp", ":0")

pkg/apis/sources/v1alpha1/register_test.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/*
2-
Copyright 2019 The Knative Authors
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
16-
171
package v1alpha1
182

193
import (
@@ -23,15 +7,15 @@ import (
237
)
248

259
func TestRegisterHelpers(t *testing.T) {
26-
if got, want := Kind("Foo"), "Foo.samples.knative.dev"; got.String() != want {
10+
if got, want := Kind("Foo"), "Foo.sources.eventing.zeiss.com"; got.String() != want {
2711
t.Errorf("Kind(Foo) = %v, want %v", got.String(), want)
2812
}
2913

30-
if got, want := Resource("Foo"), "Foo.samples.knative.dev"; got.String() != want {
14+
if got, want := Resource("Foo"), "Foo.sources.eventing.zeiss.com"; got.String() != want {
3115
t.Errorf("Resource(Foo) = %v, want %v", got.String(), want)
3216
}
3317

34-
if got, want := SchemeGroupVersion.String(), "samples.knative.dev/v1alpha1"; got != want {
18+
if got, want := SchemeGroupVersion.String(), "sources.eventing.zeiss.com/v1alpha1"; got != want {
3519
t.Errorf("SchemeGroupVersion() = %v, want %v", got, want)
3620
}
3721

pkg/apis/sources/v1alpha1/samplesource_defaults.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import (
2424

2525
// SetDefaults mutates SampleSource.
2626
func (s *SampleSource) SetDefaults(ctx context.Context) {
27-
//Add code for Mutating admission webhook.
27+
// Add code for Mutating admission webhook.
2828

29-
//example: If ServiceAccountName is unspecified, default to the "default" service account.
29+
// example: If ServiceAccountName is unspecified, default to the "default" service account.
3030
if s != nil && s.Spec.ServiceAccountName == "" {
3131
s.Spec.ServiceAccountName = "default"
3232
}
3333

34-
//example: If Interval is unspecified, default to "10s".
34+
// example: If Interval is unspecified, default to "10s".
3535
if s != nil && s.Spec.Interval == "" {
3636
s.Spec.Interval = "10s"
3737
}

pkg/apis/sources/v1alpha1/samplesource_validation.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,29 @@ import (
2727
func (s *SampleSource) Validate(ctx context.Context) *apis.FieldError {
2828
var errs *apis.FieldError
2929

30-
//example: validation for "spec" field.
30+
// example: validation for "spec" field.
3131
errs = errs.Also(s.Spec.Validate(ctx).ViaField("spec"))
3232

33-
//errs is nil if everything is fine.
33+
// errs is nil if everything is fine.
3434
return errs
3535
}
3636

3737
// Validate validates SampleSourceSpec.
3838
func (sspec *SampleSourceSpec) Validate(ctx context.Context) *apis.FieldError {
39-
//Add code for validation webhook for SampleSourceSpec.
39+
// Add code for validation webhook for SampleSourceSpec.
4040
var errs *apis.FieldError
4141

42-
//example: validation for sink field.
42+
// example: validation for sink field.
4343
if fe := sspec.Sink.Validate(ctx); fe != nil {
4444
errs = errs.Also(fe.ViaField("sink"))
4545
}
4646

47-
//example: validation for interval field.
47+
// example: validation for interval field.
4848
if _, fe := time.ParseDuration(sspec.Interval); fe != nil {
4949
errs = errs.Also(apis.ErrInvalidValue(fe, "interval"))
5050
}
5151

52-
//example: validation for serviceAccountName field.
52+
// example: validation for serviceAccountName field.
5353
if sspec.ServiceAccountName == "" {
5454
errs = errs.Also(apis.ErrMissingField("serviceAccountName"))
5555
}

pkg/reconciler/sample/samplesource.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ var _ reconcilersamplesource.Interface = (*Reconciler)(nil)
3737

3838
// ReconcileKind implements Interface.ReconcileKind.
3939
func (r *Reconciler) ReconcileKind(ctx context.Context, src *v1alpha1.SampleSource) pkgreconciler.Event {
40-
4140
ctx = sourcesv1.WithURIResolver(ctx, r.sinkResolver)
4241

4342
ra, sb, event := r.dr.ReconcileDeployment(ctx, src, makeSinkBinding(src),

0 commit comments

Comments
 (0)