@@ -29,7 +29,7 @@ import (
2929 "github.com/apache/camel-k/v2/pkg/internal"
3030)
3131
32- func TestFindIntegrationProfile (t * testing.T ) {
32+ func TestFindOrApplyIntegrationProfile (t * testing.T ) {
3333 profile := v1.IntegrationProfile {
3434 ObjectMeta : metav1.ObjectMeta {
3535 Name : "custom" ,
@@ -41,6 +41,9 @@ func TestFindIntegrationProfile(t *testing.T) {
4141 require .NoError (t , err )
4242
4343 integration := v1.Integration {
44+ TypeMeta : metav1.TypeMeta {
45+ Kind : v1 .IntegrationKind ,
46+ },
4447 ObjectMeta : metav1.ObjectMeta {
4548 Name : "test" ,
4649 Namespace : "ns" ,
@@ -56,4 +59,78 @@ func TestFindIntegrationProfile(t *testing.T) {
5659 found , err := findIntegrationProfile (context .TODO (), c , & integration )
5760 require .NoError (t , err )
5861 assert .NotNil (t , found )
62+
63+ found , err = ApplyIntegrationProfile (context .TODO (), c , & integration )
64+ require .NoError (t , err )
65+ assert .NotNil (t , found )
66+ }
67+
68+ func TestFindOrApplyIntegrationMissing (t * testing.T ) {
69+ profile := v1.IntegrationProfile {
70+ ObjectMeta : metav1.ObjectMeta {
71+ Name : "custom" ,
72+ Namespace : "ns" ,
73+ },
74+ }
75+
76+ c , err := internal .NewFakeClient (& profile )
77+ require .NoError (t , err )
78+
79+ integration := v1.Integration {
80+ TypeMeta : metav1.TypeMeta {
81+ Kind : v1 .IntegrationKind ,
82+ },
83+ ObjectMeta : metav1.ObjectMeta {
84+ Name : "test" ,
85+ Namespace : "ns" ,
86+ Annotations : map [string ]string {
87+ v1 .IntegrationProfileAnnotation : "missing" ,
88+ },
89+ },
90+ Status : v1.IntegrationStatus {
91+ Phase : v1 .IntegrationPhaseRunning ,
92+ },
93+ }
94+
95+ found , err := findIntegrationProfile (context .TODO (), c , & integration )
96+ require .Error (t , err )
97+ assert .Nil (t , found )
98+ assert .Contains (t , err .Error (), "\" missing\" not found" )
99+
100+ found , err = ApplyIntegrationProfile (context .TODO (), c , & integration )
101+ require .NoError (t , err )
102+ assert .Nil (t , found )
103+ }
104+
105+ func TestFindOrApplyIntegrationProfileError (t * testing.T ) {
106+ profile := v1.IntegrationProfile {
107+ ObjectMeta : metav1.ObjectMeta {
108+ Name : "custom" ,
109+ Namespace : "ns" ,
110+ },
111+ }
112+
113+ c , err := internal .NewFakeClient (& profile )
114+ require .NoError (t , err )
115+
116+ integrationKit := v1.IntegrationKit {
117+ TypeMeta : metav1.TypeMeta {
118+ Kind : v1 .IntegrationKitKind ,
119+ },
120+ ObjectMeta : metav1.ObjectMeta {
121+ Name : "test" ,
122+ Namespace : "ns" ,
123+ Annotations : map [string ]string {
124+ v1 .IntegrationProfileAnnotation : "custom" ,
125+ },
126+ },
127+ }
128+
129+ _ , err = findIntegrationProfile (context .TODO (), c , & integrationKit )
130+ require .Error (t , err )
131+ assert .Equal (t , "wrong format for IntegrationProfile, expected profile-namespace/profile-id" , err .Error ())
132+
133+ _ , err = ApplyIntegrationProfile (context .TODO (), c , & integrationKit )
134+ require .Error (t , err )
135+ assert .Equal (t , "wrong format for IntegrationProfile, expected profile-namespace/profile-id" , err .Error ())
59136}
0 commit comments