[camel-k] 03/05: test(source): add tests for dataformat deps resolution

2022-11-29 Thread tsato
This is an automated email from the ASF dual-hosted git repository.

tsato pushed a commit to branch release-1.10.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit e12978dd95188ff7579a308fb84e47ed40bac2a1
Author: Tadayoshi Sato 
AuthorDate: Tue Nov 29 15:55:09 2022 +0900

test(source): add tests for dataformat deps resolution
---
 pkg/util/source/inspector_groovy_test.go  | 131 ---
 pkg/util/source/inspector_java_script_test.go | 122 +++---
 pkg/util/source/inspector_java_source_test.go | 128 ---
 pkg/util/source/inspector_kotlin_test.go  | 122 +++---
 pkg/util/source/inspector_xml_test.go | 143 +---
 pkg/util/source/inspector_yaml_test.go| 315 +-
 pkg/util/source/test_support.go   |  58 +
 7 files changed, 700 insertions(+), 319 deletions(-)

diff --git a/pkg/util/source/inspector_groovy_test.go 
b/pkg/util/source/inspector_groovy_test.go
index d0d2a5e80..e082d9d74 100644
--- a/pkg/util/source/inspector_groovy_test.go
+++ b/pkg/util/source/inspector_groovy_test.go
@@ -21,34 +21,46 @@ import (
"fmt"
"testing"
 
-   v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
-
"github.com/stretchr/testify/assert"
+   "github.com/stretchr/testify/require"
 
"github.com/apache/camel-k/pkg/util/camel"
 )
 
-const GroovyKameletEip = `
+func newTestGroovyInspector(t *testing.T) GroovyInspector {
+   t.Helper()
+
+   catalog, err := camel.DefaultCatalog()
+   require.NoError(t, err)
+
+   return GroovyInspector{
+   baseInspector: baseInspector{
+   catalog: catalog,
+   },
+   }
+}
+
+const groovyKameletEip = `
 from("direct:start")
 .kamelet("foo/bar?baz=test")
 `
 
-const GroovyKameletEipSingleQuote = `
+const groovyKameletEipSingleQuote = `
 from("direct:start")
 .kamelet('foo/bar?baz=test')
 `
 
-const GroovyKameletEndpoint = `
+const groovyKameletEndpoint = `
 from("direct:start")
 .to("kamelet:foo/bar?baz=test")
 `
 
-const GroovyKameletEndpointSingleQuote = `
+const groovyKameletEndpointSingleQuote = `
 from("direct:start")
 .to('kamelet:foo/bar?baz=test')
 `
 
-const GroovyWireTapEipSingleQuote = `
+const groovyWireTapEipSingleQuote = `
 from("direct:start")
 .wireTap('kamelet:foo/bar?baz=test')
 `
@@ -59,53 +71,102 @@ func TestGroovyKamelet(t *testing.T) {
kamelets []string
}{
{
-   source:   GroovyKameletEip,
+   source:   groovyKameletEip,
kamelets: []string{"foo/bar"},
},
{
-   source:   GroovyKameletEndpoint,
+   source:   groovyKameletEndpoint,
kamelets: []string{"foo/bar"},
},
{
-   source:   GroovyKameletEipSingleQuote,
+   source:   groovyKameletEipSingleQuote,
kamelets: []string{"foo/bar"},
},
{
-   source:   GroovyKameletEndpointSingleQuote,
+   source:   groovyKameletEndpointSingleQuote,
kamelets: []string{"foo/bar"},
},
{
-   source:   GroovyWireTapEipSingleQuote,
+   source:   groovyWireTapEipSingleQuote,
kamelets: []string{"foo/bar"},
},
}
 
+   inspector := newTestGroovyInspector(t)
for i := range tc {
test := tc[i]
t.Run(fmt.Sprintf("TestGroovyKamelet-%d", i), func(t 
*testing.T) {
-   code := v1.SourceSpec{
-   DataSpec: v1.DataSpec{
-   Content: test.source,
-   },
-   }
-
-   catalog, err := camel.DefaultCatalog()
-   assert.Nil(t, err)
-
-   meta := NewMetadata()
-   inspector := GroovyInspector{
-   baseInspector: baseInspector{
-   catalog: catalog,
-   },
-   }
-
-   err = inspector.Extract(code, )
-   assert.Nil(t, err)
-   assert.True(t, meta.RequiredCapabilities.IsEmpty())
-
-   for _, k := range test.kamelets {
-   assert.Contains(t, meta.Kamelets, k)
-   }
+   assertExtract(t, inspector, test.source, func(meta 
*Metadata) {
+   assert.True(t, 
meta.RequiredCapabilities.IsEmpty())
+   for _, k := range test.kamelets {
+   assert.Contains(t, 

[camel-k] 03/05: test(source): add tests for dataformat deps resolution

2022-11-29 Thread tsato
This is an automated email from the ASF dual-hosted git repository.

tsato pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit e9b8dd5d1369f6984b4241350afcb31257b26ead
Author: Tadayoshi Sato 
AuthorDate: Tue Nov 29 15:55:09 2022 +0900

test(source): add tests for dataformat deps resolution
---
 pkg/util/source/inspector_groovy_test.go  | 131 ---
 pkg/util/source/inspector_java_script_test.go | 122 +++---
 pkg/util/source/inspector_java_source_test.go | 128 ---
 pkg/util/source/inspector_kotlin_test.go  | 122 +++---
 pkg/util/source/inspector_xml_test.go | 143 +---
 pkg/util/source/inspector_yaml_test.go| 315 +-
 pkg/util/source/test_support.go   |  58 +
 7 files changed, 700 insertions(+), 319 deletions(-)

diff --git a/pkg/util/source/inspector_groovy_test.go 
b/pkg/util/source/inspector_groovy_test.go
index d0d2a5e80..e082d9d74 100644
--- a/pkg/util/source/inspector_groovy_test.go
+++ b/pkg/util/source/inspector_groovy_test.go
@@ -21,34 +21,46 @@ import (
"fmt"
"testing"
 
-   v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
-
"github.com/stretchr/testify/assert"
+   "github.com/stretchr/testify/require"
 
"github.com/apache/camel-k/pkg/util/camel"
 )
 
-const GroovyKameletEip = `
+func newTestGroovyInspector(t *testing.T) GroovyInspector {
+   t.Helper()
+
+   catalog, err := camel.DefaultCatalog()
+   require.NoError(t, err)
+
+   return GroovyInspector{
+   baseInspector: baseInspector{
+   catalog: catalog,
+   },
+   }
+}
+
+const groovyKameletEip = `
 from("direct:start")
 .kamelet("foo/bar?baz=test")
 `
 
-const GroovyKameletEipSingleQuote = `
+const groovyKameletEipSingleQuote = `
 from("direct:start")
 .kamelet('foo/bar?baz=test')
 `
 
-const GroovyKameletEndpoint = `
+const groovyKameletEndpoint = `
 from("direct:start")
 .to("kamelet:foo/bar?baz=test")
 `
 
-const GroovyKameletEndpointSingleQuote = `
+const groovyKameletEndpointSingleQuote = `
 from("direct:start")
 .to('kamelet:foo/bar?baz=test')
 `
 
-const GroovyWireTapEipSingleQuote = `
+const groovyWireTapEipSingleQuote = `
 from("direct:start")
 .wireTap('kamelet:foo/bar?baz=test')
 `
@@ -59,53 +71,102 @@ func TestGroovyKamelet(t *testing.T) {
kamelets []string
}{
{
-   source:   GroovyKameletEip,
+   source:   groovyKameletEip,
kamelets: []string{"foo/bar"},
},
{
-   source:   GroovyKameletEndpoint,
+   source:   groovyKameletEndpoint,
kamelets: []string{"foo/bar"},
},
{
-   source:   GroovyKameletEipSingleQuote,
+   source:   groovyKameletEipSingleQuote,
kamelets: []string{"foo/bar"},
},
{
-   source:   GroovyKameletEndpointSingleQuote,
+   source:   groovyKameletEndpointSingleQuote,
kamelets: []string{"foo/bar"},
},
{
-   source:   GroovyWireTapEipSingleQuote,
+   source:   groovyWireTapEipSingleQuote,
kamelets: []string{"foo/bar"},
},
}
 
+   inspector := newTestGroovyInspector(t)
for i := range tc {
test := tc[i]
t.Run(fmt.Sprintf("TestGroovyKamelet-%d", i), func(t 
*testing.T) {
-   code := v1.SourceSpec{
-   DataSpec: v1.DataSpec{
-   Content: test.source,
-   },
-   }
-
-   catalog, err := camel.DefaultCatalog()
-   assert.Nil(t, err)
-
-   meta := NewMetadata()
-   inspector := GroovyInspector{
-   baseInspector: baseInspector{
-   catalog: catalog,
-   },
-   }
-
-   err = inspector.Extract(code, )
-   assert.Nil(t, err)
-   assert.True(t, meta.RequiredCapabilities.IsEmpty())
-
-   for _, k := range test.kamelets {
-   assert.Contains(t, meta.Kamelets, k)
-   }
+   assertExtract(t, inspector, test.source, func(meta 
*Metadata) {
+   assert.True(t, 
meta.RequiredCapabilities.IsEmpty())
+   for _, k := range test.kamelets {
+   assert.Contains(t, meta.Kamelets,