squakez commented on code in PR #5275:
URL: https://github.com/apache/camel-k/pull/5275#discussion_r1537591762


##########
pkg/trait/knative_test.go:
##########
@@ -348,6 +348,155 @@ func TestKnativePlatformHttpDependencies(t *testing.T) {
        }
 }
 
+func TestKnativeEnabled(t *testing.T) {
+       catalog, err := camel.DefaultCatalog()
+       require.NoError(t, err)
+
+       traitCatalog := NewCatalog(nil)
+
+       environment := Environment{
+               CamelCatalog: catalog,
+               Catalog:      traitCatalog,
+               Integration: &v1.Integration{
+                       ObjectMeta: metav1.ObjectMeta{
+                               Name:      "test",
+                               Namespace: "ns",
+                       },
+                       Status: v1.IntegrationStatus{
+                               Phase: v1.IntegrationPhaseInitialization,
+                       },
+                       Spec: v1.IntegrationSpec{
+                               Profile: v1.TraitProfileKnative,
+                               Sources: []v1.SourceSpec{
+                                       {
+                                               DataSpec: v1.DataSpec{
+                                                       Name:    "route.groovy",
+                                                       Content: 
`from('timer:foo').to('knative:channel/channel-source-1')`,
+                                               },
+                                               Language: v1.LanguageGroovy,
+                                       },
+                               },
+                       },
+               },
+               Platform: &v1.IntegrationPlatform{
+                       Spec: v1.IntegrationPlatformSpec{
+                               Cluster: v1.IntegrationPlatformClusterOpenShift,
+                               Build: v1.IntegrationPlatformBuildSpec{
+                                       PublishStrategy: 
v1.IntegrationPlatformBuildPublishStrategyS2I,
+                                       Registry:        
v1.RegistrySpec{Address: "registry"},
+                               },
+                               Profile: v1.TraitProfileKnative,
+                       },
+               },
+               EnvVars:        make([]corev1.EnvVar, 0),
+               ExecutedTraits: make([]Trait, 0),
+               Resources:      k8sutils.NewCollection(),
+       }
+       environment.Platform.ResyncStatusFullConfig()
+
+       // configure the init trait
+       init := NewInitTrait()
+       ok, condition, err := init.Configure(&environment)
+       require.NoError(t, err)
+       assert.True(t, ok)
+       assert.Nil(t, condition)
+
+       // apply the init trait
+       require.NoError(t, init.Apply(&environment))
+
+       // configure the knative trait
+       knTrait, _ := newKnativeTrait().(*knativeTrait)
+       ok, condition, err = knTrait.Configure(&environment)
+       require.NoError(t, err)
+       assert.True(t, ok)
+       assert.Nil(t, condition)
+
+       // apply the knative trait
+       require.NoError(t, knTrait.Apply(&environment))
+
+       // call the post step processors
+       for _, processor := range environment.PostStepProcessors {
+               assert.Nil(t, processor(&environment))
+       }
+
+       assert.True(t, *knTrait.Enabled)
+       assert.Contains(t, environment.Integration.Status.Capabilities, 
v1.CapabilityKnative)
+       assert.Contains(t, environment.Integration.Status.Dependencies, 
"mvn:org.apache.camel.k:camel-k-knative-impl")
+}
+
+func TestKnativeNotEnabled(t *testing.T) {
+       catalog, err := camel.DefaultCatalog()
+       require.NoError(t, err)
+
+       traitCatalog := NewCatalog(nil)
+
+       environment := Environment{
+               CamelCatalog: catalog,
+               Catalog:      traitCatalog,
+               Integration: &v1.Integration{
+                       ObjectMeta: metav1.ObjectMeta{
+                               Name:      "test",
+                               Namespace: "ns",
+                       },
+                       Status: v1.IntegrationStatus{
+                               Phase: v1.IntegrationPhaseInitialization,
+                       },
+                       Spec: v1.IntegrationSpec{
+                               Profile: v1.TraitProfileKnative,
+                               Sources: []v1.SourceSpec{
+                                       {
+                                               DataSpec: v1.DataSpec{
+                                                       Name:    "route.groovy",
+                                                       Content: 
`from('timer:foo').to('log:info')`,
+                                               },
+                                               Language: v1.LanguageGroovy,
+                                       },
+                               },
+                       },
+               },
+               Platform: &v1.IntegrationPlatform{
+                       Spec: v1.IntegrationPlatformSpec{
+                               Cluster: v1.IntegrationPlatformClusterOpenShift,
+                               Build: v1.IntegrationPlatformBuildSpec{
+                                       PublishStrategy: 
v1.IntegrationPlatformBuildPublishStrategyS2I,
+                                       Registry:        
v1.RegistrySpec{Address: "registry"},
+                               },
+                               Profile: v1.TraitProfileKnative,
+                       },
+               },
+               EnvVars:        make([]corev1.EnvVar, 0),
+               ExecutedTraits: make([]Trait, 0),
+               Resources:      k8sutils.NewCollection(),
+       }
+       environment.Platform.ResyncStatusFullConfig()
+
+       // configure the init trait
+       init := NewInitTrait()
+       ok, condition, err := init.Configure(&environment)
+       require.NoError(t, err)
+       assert.True(t, ok)
+       assert.Nil(t, condition)
+
+       // apply the init trait
+       require.NoError(t, init.Apply(&environment))
+
+       // configure the knative trait
+       knTrait, _ := newKnativeTrait().(*knativeTrait)
+       ok, condition, err = knTrait.Configure(&environment)
+       require.NoError(t, err)
+       assert.False(t, ok)
+       assert.Nil(t, condition)
+
+       // call the post step processors

Review Comment:
   Sure, but I don't think it's relevant for the scope of the unit test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to