Skip to content

Commit

Permalink
chore: fix test after deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed May 10, 2023
1 parent 992d771 commit e04fbbb
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 79 deletions.
4 changes: 2 additions & 2 deletions e2e/common/misc/kamelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestKameletClasspathLoading(t *testing.T) {

// Store a configmap on the cluster
var cmData = make(map[string]string)
cmData["my-kamelet"] = `
cmData["my-timer-source.kamelet.yaml"] = `
# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
Expand Down Expand Up @@ -112,7 +112,7 @@ spec:
// Basic
t.Run("test basic case", func(t *testing.T) {
Expect(KamelRunWithID(operatorID, ns, "files/TimerKameletIntegration.java", "-t", "kamelets.enabled=false",
"--resource", "configmap:my-kamelet-cm@/kamelets/my-timer-source.kamelet.yaml",
"--resource", "configmap:my-kamelet-cm@/kamelets",
"-p camel.component.kamelet.location=file:/kamelets",
"-d", "camel:yaml-dsl",
// kamelet dependencies
Expand Down
45 changes: 11 additions & 34 deletions e2e/common/misc/pipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,12 @@ func TestPipe(t *testing.T) {
t.Run("test error handler", func(t *testing.T) {
Expect(createErrorProducerKamelet(ns, "my-own-error-producer-source")()).To(Succeed())
Expect(CreateLogKamelet(ns, "my-own-log-sink")()).To(Succeed())
from := corev1.ObjectReference{
Kind: "Kamelet",
Name: "my-own-error-producer-source",
APIVersion: v1.SchemeGroupVersion.String(),
}

to := corev1.ObjectReference{
Kind: "Kamelet",
Name: "my-own-log-sink",
APIVersion: v1.SchemeGroupVersion.String(),
}

t.Run("throw error test", func(t *testing.T) {
Expect(KamelBind(ns,
from.Name,
to.Name,
"--error-handler", "sink:"+to.Name,
Expect(KamelBindWithID(operatorID, ns,
"my-own-error-producer-source",
"my-own-log-sink",
"--error-handler", "sink:my-own-log-sink",
"-p", "source.message=throw Error",
"-p", "sink.loggerName=integrationLogger",
"-p", "error-handler.loggerName=kameletErrorHandler",
Expand All @@ -71,10 +60,10 @@ func TestPipe(t *testing.T) {
})

t.Run("don't throw error test", func(t *testing.T) {
Expect(KamelBind(ns,
from.Name,
to.Name,
"--error-handler", "sink:"+to.Name,
Expect(KamelBindWithID(operatorID, ns,
"my-own-error-producer-source",
"my-own-log-sink",
"--error-handler", "sink:my-own-log-sink",
"-p", "source.message=true",
"-p", "sink.loggerName=integrationLogger",
"-p", "error-handler.loggerName=kameletErrorHandler",
Expand All @@ -93,21 +82,9 @@ func TestPipe(t *testing.T) {
Expect(CreateTimerKamelet(ns, "my-own-timer-source")()).To(Succeed())
// Log sink kamelet exists from previous test

from := corev1.ObjectReference{
Kind: "Kamelet",
Name: "my-own-timer-source",
APIVersion: v1.SchemeGroupVersion.String(),
}

to := corev1.ObjectReference{
Kind: "Kamelet",
Name: "my-own-log-sink",
APIVersion: v1.SchemeGroupVersion.String(),
}

Expect(KamelBind(ns,
from.Name,
to.Name,
Expect(KamelBindWithID(operatorID, ns,
"my-own-timer-source",
"my-own-log-sink",
"-p", "source.message=hello from test",
"-p", "sink.loggerName=integrationLogger",
"--annotation", "trait.camel.apache.org/camel.properties=[\"camel.prop1=a\",\"camel.prop2=b\"]",
Expand Down
25 changes: 6 additions & 19 deletions e2e/common/misc/pipe_with_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,19 @@ import (
corev1 "k8s.io/api/core/v1"

. "github.com/apache/camel-k/v2/e2e/support"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
)

func TestPipeWithImage(t *testing.T) {
RegisterTestingT(t)

from := corev1.ObjectReference{
Kind: "Kamelet",
Name: "my-own-timer-source",
APIVersion: v1.SchemeGroupVersion.String(),
}

to := corev1.ObjectReference{
Kind: "Kamelet",
Name: "my-own-log-sink",
APIVersion: v1.SchemeGroupVersion.String(),
}

bindingID := "with-image-binding"

t.Run("run with initial image", func(t *testing.T) {
expectedImage := "docker.io/jmalloc/echo-server:0.3.2"

Expect(KamelBind(ns,
from.Name,
to.Name,
Expect(KamelBindWithID(operatorID, ns,
"my-own-timer-source",
"my-own-log-sink",
"--annotation", "trait.camel.apache.org/container.image="+expectedImage,
"--annotation", "trait.camel.apache.org/jvm.enabled=false",
"--annotation", "trait.camel.apache.org/kamelets.enabled=false",
Expand All @@ -82,9 +69,9 @@ func TestPipeWithImage(t *testing.T) {
t.Run("run with new image", func(t *testing.T) {
expectedImage := "docker.io/jmalloc/echo-server:0.3.3"

Expect(KamelBind(ns,
from.Name,
to.Name,
Expect(KamelBindWithID(operatorID, ns,
"my-own-timer-source",
"my-own-log-sink",
"--annotation", "trait.camel.apache.org/container.image="+expectedImage,
"--annotation", "trait.camel.apache.org/jvm.enabled=false",
"--annotation", "trait.camel.apache.org/kamelets.enabled=false",
Expand Down
22 changes: 5 additions & 17 deletions e2e/common/traits/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,12 @@ func TestHealthTrait(t *testing.T) {
t.Run("Readiness condition with stopped binding", func(t *testing.T) {
name := "stopped-binding"

Expect(CreateTimerKamelet(ns, "my-own-timer-source")).To(Succeed())
Expect(CreateLogKamelet(ns, "my-own-log-sink")).To(Succeed())
Expect(CreateTimerKamelet(ns, "my-health-timer-source")()).To(Succeed())
Expect(CreateLogKamelet(ns, "my-health-log-sink")()).To(Succeed())

from := corev1.ObjectReference{
Kind: "Kamelet",
Name: "my-stopped-binding-timer-source",
APIVersion: camelv1.SchemeGroupVersion.String(),
}

to := corev1.ObjectReference{
Kind: "Kamelet",
Name: "my-stopped-binding-log-sink",
APIVersion: camelv1.SchemeGroupVersion.String(),
}

Expect(KamelBind(ns,
from.Name,
to.Name,
Expect(KamelBindWithID(operatorID, ns,
"my-health-timer-source",
"my-health-log-sink",
"-p", "source.message=Magicstring!",
"-p", "sink.loggerName=binding",
"--annotation", "trait.camel.apache.org/health.enabled=true",
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,7 @@ func (o *runCmdOptions) parseAndConvertToTrait(cmd *cobra.Command,
if err != nil {
return err
}
// We try to autogenerate a configmap
if _, err := parseConfigAndGenCm(o.Context, cmd, c, config, integration); err != nil {
if err := parseConfig(o.Context, cmd, c, config, integration); err != nil {
return err
}
o.Traits = append(o.Traits, convertToTrait(convert(config), traitParam))
Expand Down
9 changes: 4 additions & 5 deletions pkg/cmd/run_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"github.com/magiconair/properties"
"github.com/pkg/errors"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
)

func addDependency(cmd *cobra.Command, it *v1.Integration, dependency string, catalog *camel.RuntimeCatalog) {
Expand All @@ -48,14 +47,14 @@ func addDependency(cmd *cobra.Command, it *v1.Integration, dependency string, ca
it.Spec.AddDependency(normalized)
}

func parseConfigAndGenCm(ctx context.Context, cmd *cobra.Command, c client.Client, config *resource.Config, integration *v1.Integration) (*corev1.ConfigMap, error) {
func parseConfig(ctx context.Context, cmd *cobra.Command, c client.Client, config *resource.Config, integration *v1.Integration) error {
switch config.StorageType() {
case resource.StorageTypeConfigmap:
cm := kubernetes.LookupConfigmap(ctx, c, integration.Namespace, config.Name())
if cm == nil {
fmt.Fprintln(cmd.ErrOrStderr(), "Warn:", config.Name(), "Configmap not found in", integration.Namespace, "namespace, make sure to provide it before the Integration can run")
} else if config.ContentType() != resource.ContentTypeData && cm.BinaryData != nil {
return nil, fmt.Errorf("you cannot provide a binary config, use a text file instead")
return fmt.Errorf("you cannot provide a binary config, use a text file instead")
}
case resource.StorageTypeSecret:
secret := kubernetes.LookupSecret(ctx, c, integration.Namespace, config.Name())
Expand All @@ -64,10 +63,10 @@ func parseConfigAndGenCm(ctx context.Context, cmd *cobra.Command, c client.Clien
}
default:
// Should never reach this
return nil, fmt.Errorf("invalid option type %s", config.StorageType())
return fmt.Errorf("invalid option type %s", config.StorageType())
}

return nil, nil
return nil
}

func filterFileLocation(maybeFileLocations []string) []string {
Expand Down

0 comments on commit e04fbbb

Please sign in to comment.