@@ -15,17 +15,20 @@ import (
1515
1616var _ = Describe ("CF Python Buildpack" , func () {
1717 var (
18- app * cutlass.App
19- createdServices []string
20- dynatraceAPI * cutlass.App
21- dynatraceAPIURI string
18+ app * cutlass.App
19+ createdServices []string
20+ dynatraceAPI * cutlass.App
21+ dynatraceAPIURI string
22+ dynatraceBrokenAPI * cutlass.App
23+ dynatraceBrokenAPIURI string
2224 )
2325
2426 BeforeEach (func () {
2527 if isSerialTest {
2628 Skip ("Skipping parallel tests" )
2729 }
2830
31+ //API mocking App
2932 dynatraceAPI = cutlass .New (Fixtures ("fake_dynatrace_api" ))
3033 // TODO: remove this once go-buildpack runs on cflinuxfs4
3134 // This is done to have the dynatrace broker app written in go up and running
@@ -41,6 +44,23 @@ var _ = Describe("CF Python Buildpack", func() {
4144 dynatraceAPIURI , err = dynatraceAPI .GetUrl ("" )
4245 Expect (err ).NotTo (HaveOccurred ())
4346
47+ //API mocking App with broken processmoduleconfig Endpoint
48+ dynatraceBrokenAPI = cutlass .New (Fixtures ("fake_dynatrace_api" ))
49+
50+ // TODO: remove this once go-buildpack runs on cflinuxfs4
51+ // This is done to have the dynatrace broker app written in go up and running
52+ if os .Getenv ("CF_STACK" ) == "cflinuxfs4" {
53+ dynatraceBrokenAPI .Stack = "cflinuxfs3"
54+ }
55+ dynatraceBrokenAPI .SetEnv ("BP_DEBUG" , "true" )
56+ dynatraceBrokenAPI .SetEnv ("API_CONNECTION_FAIL" , "true" )
57+
58+ Expect (dynatraceBrokenAPI .Push ()).To (Succeed ())
59+ Eventually (func () ([]string , error ) { return dynatraceBrokenAPI .InstanceStates () }, 60 * time .Second ).Should (Equal ([]string {"RUNNING" }))
60+
61+ dynatraceBrokenAPIURI , err = dynatraceBrokenAPI .GetUrl ("" )
62+ Expect (err ).NotTo (HaveOccurred ())
63+
4464 app = cutlass .New (filepath .Join (bpDir , "fixtures" , "flask" ))
4565 app .SetEnv ("BP_DEBUG" , "true" )
4666 PushAppAndConfirm (app )
@@ -59,6 +79,16 @@ var _ = Describe("CF Python Buildpack", func() {
5979 _ , err := command .Output ()
6080 Expect (err ).To (BeNil ())
6181 }
82+
83+ if dynatraceAPI != nil {
84+ dynatraceAPI .Destroy ()
85+ }
86+ dynatraceAPI = nil
87+
88+ if dynatraceBrokenAPI != nil {
89+ dynatraceBrokenAPI .Destroy ()
90+ }
91+ dynatraceBrokenAPI = nil
6292 })
6393
6494 Context ("deploying a Python app with Dynatrace agent with single credentials service" , func () {
@@ -271,4 +301,46 @@ var _ = Describe("CF Python Buildpack", func() {
271301 })
272302 })
273303
304+ Context ("deploying a Python app with Dynatrace OneAgent being able to contact the API to fetch the updated OneAgent config" , func () {
305+ It ("checks if agent config update via API was successful" , func () {
306+ serviceName := "dynatrace-" + cutlass .RandStringRunes (20 ) + "-service"
307+ command := exec .Command ("cf" , "cups" , serviceName , "-p" , fmt .Sprintf ("'{\" apitoken\" :\" secretpaastoken\" ,\" apiurl\" :\" %s\" ,\" environmentid\" :\" envid\" }'" , dynatraceAPIURI ))
308+ _ , err := command .CombinedOutput ()
309+ Expect (err ).To (BeNil ())
310+ createdServices = append (createdServices , serviceName )
311+ command = exec .Command ("cf" , "bind-service" , app .Name , serviceName )
312+ _ , err = command .CombinedOutput ()
313+ Expect (err ).To (BeNil ())
314+
315+ command = exec .Command ("cf" , "restage" , app .Name )
316+ _ , err = command .Output ()
317+ Expect (err ).To (BeNil ())
318+
319+ Expect (app .ConfirmBuildpack (buildpackVersion )).To (Succeed ())
320+ Expect (app .Stdout .String ()).To (ContainSubstring ("Fetching updated OneAgent configuration from tenant..." ))
321+ Expect (app .Stdout .String ()).To (ContainSubstring ("Successfully fetched updated OneAgent config from the API" ))
322+ })
323+ })
324+
325+ Context ("deploying a Python app with Dynatrace OneAgent not being able to contact the API to fetch the updated OneAgent config" , func () {
326+ It ("checks if agent config update via API fails soft" , func () {
327+ serviceName := "dynatrace-" + cutlass .RandStringRunes (20 ) + "-service"
328+
329+ command := exec .Command ("cf" , "cups" , serviceName , "-p" , fmt .Sprintf ("'{\" apitoken\" :\" secretpaastoken\" ,\" apiurl\" :\" %s\" ,\" environmentid\" :\" envid\" }'" , dynatraceBrokenAPIURI ))
330+ _ , err := command .CombinedOutput ()
331+ Expect (err ).To (BeNil ())
332+ createdServices = append (createdServices , serviceName )
333+ command = exec .Command ("cf" , "bind-service" , app .Name , serviceName )
334+ _ , err = command .CombinedOutput ()
335+ Expect (err ).To (BeNil ())
336+
337+ command = exec .Command ("cf" , "restage" , app .Name )
338+ _ , err = command .Output ()
339+ Expect (err ).To (BeNil ())
340+
341+ Expect (app .ConfirmBuildpack (buildpackVersion )).To (Succeed ())
342+ Expect (app .Stdout .String ()).To (ContainSubstring ("Fetching updated OneAgent configuration from tenant..." ))
343+ Expect (app .Stdout .String ()).To (ContainSubstring ("Failed to fetch updated OneAgent config from the API" ))
344+ })
345+ })
274346})
0 commit comments