Skip to content

Commit

Permalink
Add containersource smoke test (#5331)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Moss authored Apr 30, 2021
1 parent 0278f6e commit a5db0e1
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/rekt/features/containersource/readyness.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright 2021 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 containersource

import (
"knative.dev/eventing/test/rekt/resources/containersource"
"knative.dev/eventing/test/rekt/resources/pingsource"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/manifest"
"knative.dev/reconciler-test/resources/svc"
)

// GoesReady returns a feature testing if a containersource becomes ready.
func GoesReady(name string, cfg ...manifest.CfgFn) *feature.Feature {
f := feature.NewFeatureNamed("ContainerSource goes ready.")

sink := feature.MakeRandomK8sName("sink")
f.Setup("install a service", svc.Install(sink, "app", "rekt"))

cfg = append(cfg, pingsource.WithSink(&duckv1.KReference{
Kind: "Service",
Name: sink,
APIVersion: "v1",
}, ""))

f.Setup("install a ContainerSource", containersource.Install(name, cfg...))

f.Requirement("ContainerSource is ready", containersource.IsReady(name))

f.Stable("ContainerSource")

return f
}
57 changes: 57 additions & 0 deletions test/rekt/resources/containersource/containersource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2021 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 containersource

import (
"context"
"time"

"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/reconciler-test/pkg/environment"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/k8s"
"knative.dev/reconciler-test/pkg/manifest"
)

func init() {
environment.RegisterPackage(manifest.ImagesLocalYaml()...)
}

func Gvr() schema.GroupVersionResource {
return schema.GroupVersionResource{Group: "sources.knative.dev", Version: "v1", Resource: "containersources"}
}

// IsReady tests to see if a ContainerSource becomes ready within the time given.
func IsReady(name string, timing ...time.Duration) feature.StepFn {
return k8s.IsReady(Gvr(), name, timing...)
}

// Install will create a ContainerSource resource, augmented with the config fn options.
func Install(name string, opts ...manifest.CfgFn) feature.StepFn {
cfg := map[string]interface{}{
"name": name,
}
for _, fn := range opts {
fn(cfg)
}

return func(ctx context.Context, t feature.T) {
if _, err := manifest.InstallLocalYaml(ctx, cfg); err != nil {
t.Fatal(err)
}
}
}
43 changes: 43 additions & 0 deletions test/rekt/resources/containersource/containersource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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.

apiVersion: sources.knative.dev/v1
kind: ContainerSource
metadata:
name: {{ .name }}
namespace: {{ .namespace }}
spec:
sink:
{{ if .sink.ref }}
ref:
kind: {{ .sink.ref.kind }}
namespace: {{ .namespace }}
name: {{ .sink.ref.name }}
apiVersion: {{ .sink.ref.apiVersion }}
{{ end }}
{{ if .sink.uri }}
uri: {{ .sink.uri }}
{{ end }}
template:
spec:
containers:
- name: heartbeats
image: ko://knative.dev/eventing/test/test_images/heartbeats
args:
- --period=1
env:
- name: POD_NAME
value: heartbeats
- name: POD_NAMESPACE
value: {{ .namespace }}
20 changes: 20 additions & 0 deletions test/rekt/smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"knative.dev/eventing/pkg/apis/eventing"
"knative.dev/eventing/test/rekt/features/broker"
"knative.dev/eventing/test/rekt/features/containersource"
"knative.dev/eventing/test/rekt/features/pingsource"
b "knative.dev/eventing/test/rekt/resources/broker"
ps "knative.dev/eventing/test/rekt/resources/pingsource"
Expand Down Expand Up @@ -107,3 +108,22 @@ func TestSmoke_PingSource(t *testing.T) {
}
}
}

// TestSmoke_ContainerSource
func TestSmoke_ContainerSource(t *testing.T) {
t.Parallel()

ctx, env := global.Environment()
t.Cleanup(env.Finish)

names := []string{
"customname",
"name-with-dash",
"name1with2numbers3",
"name63-0123456789012345678901234567890123456789012345678901234",
}

for _, name := range names {
env.Test(ctx, t, containersource.GoesReady(name))
}
}

0 comments on commit a5db0e1

Please sign in to comment.