@@ -20,6 +20,7 @@ import (
2020 "fmt"
2121 "os"
2222 "os/exec"
23+ "path/filepath"
2324 "time"
2425
2526 functionsdevv1alpha1 "github.com/functions-dev/func-operator/api/v1alpha1"
@@ -126,6 +127,101 @@ var _ = Describe("Operator", func() {
126127 Eventually (funcBecomeReady , 6 * time .Minute ).Should (Succeed ())
127128 })
128129 })
130+ Context ("with a function in a subdirectory in a monorepo" , func () {
131+ var repoURL string
132+ var repoDir string
133+ const subPath = "function-subdir"
134+ var functionName , functionNamespace string
135+
136+ BeforeEach (func () {
137+ // Create repository provider resources with automatic cleanup
138+ username , password , _ , cleanup , err := repoProvider .CreateRandomUser ()
139+ Expect (err ).NotTo (HaveOccurred ())
140+ DeferCleanup (cleanup )
141+
142+ _ , repoURL , cleanup , err = repoProvider .CreateRandomRepo (username , false )
143+ Expect (err ).NotTo (HaveOccurred ())
144+ DeferCleanup (cleanup )
145+
146+ // Initialize repository with function code
147+ repoDir , err = utils .InitializeRepoWithFunctionInSubDir (repoURL , subPath , username , password , "go" )
148+ Expect (err ).NotTo (HaveOccurred ())
149+ DeferCleanup (os .RemoveAll , repoDir )
150+
151+ functionNamespace , err = utils .GetTestNamespace ()
152+ Expect (err ).NotTo (HaveOccurred ())
153+ DeferCleanup (cleanupNamespaces , functionNamespace )
154+
155+ functionDir := filepath .Join (repoDir , subPath )
156+
157+ // Deploy function using func CLI
158+ out , err := utils .RunFunc ("deploy" ,
159+ "--namespace" , functionNamespace ,
160+ "--path" , functionDir ,
161+ "--registry" , registry ,
162+ fmt .Sprintf ("--registry-insecure=%t" , registryInsecure ))
163+ Expect (err ).NotTo (HaveOccurred ())
164+ _ , _ = fmt .Fprint (GinkgoWriter , out )
165+
166+ // Cleanup func deployment
167+ DeferCleanup (func () {
168+ _ , _ = utils .RunFunc ("delete" , "--path" , functionDir , "--namespace" , functionNamespace )
169+ })
170+
171+ // Commit func.yaml changes
172+ err = utils .CommitAndPush (repoDir , "Update func.yaml after deploy" , filepath .Join (subPath , "func.yaml" ))
173+ Expect (err ).NotTo (HaveOccurred ())
174+ })
175+
176+ AfterEach (func () {
177+ logFailedTestDetails (functionName , functionNamespace )
178+
179+ // Cleanup function resource
180+ if functionName != "" {
181+ cmd := exec .Command ("kubectl" , "delete" , "function" , functionName , "-n" , functionNamespace , "--ignore-not-found" )
182+ _ , err := utils .Run (cmd )
183+ Expect (err ).NotTo (HaveOccurred ())
184+ }
185+ })
186+
187+ It ("should mark the function as ready" , func () {
188+ // Create a Function resource
189+ function := & functionsdevv1alpha1.Function {
190+ ObjectMeta : metav1.ObjectMeta {
191+ GenerateName : "my-function-" ,
192+ Namespace : functionNamespace ,
193+ },
194+ Spec : functionsdevv1alpha1.FunctionSpec {
195+ Repository : functionsdevv1alpha1.FunctionSpecRepository {
196+ URL : repoURL ,
197+ Path : subPath ,
198+ },
199+ },
200+ }
201+
202+ err := k8sClient .Create (ctx , function )
203+ Expect (err ).NotTo (HaveOccurred ())
204+
205+ functionName = function .Name
206+
207+ funcBecomeReady := func (g Gomega ) {
208+ fn := & functionsdevv1alpha1.Function {}
209+ err := k8sClient .Get (ctx , types.NamespacedName {Name : function .Name , Namespace : function .Namespace }, fn )
210+ g .Expect (err ).NotTo (HaveOccurred ())
211+
212+ for _ , cond := range fn .Status .Conditions {
213+ if cond .Type == functionsdevv1alpha1 .TypeReady {
214+ g .Expect (cond .Status ).To (Equal (metav1 .ConditionTrue ))
215+ return
216+ }
217+ }
218+ g .Expect (false ).To (BeTrue (), "Ready condition not found" )
219+ }
220+
221+ // redeploy could take a bit longer therefore give a bit more time
222+ Eventually (funcBecomeReady , 6 * time .Minute ).Should (Succeed ())
223+ })
224+ })
129225 Context ("with a not yet deployed function" , func () {
130226 var repoURL string
131227 var repoDir string
0 commit comments