Skip to content

Commit 8782d2e

Browse files
Converts integration tests to use switchblade
1 parent 2f03373 commit 8782d2e

File tree

556 files changed

+110816
-772
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

556 files changed

+110816
-772
lines changed

config.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
{
2-
"stack": "cflinuxfs3",
2+
"stack": "cflinuxfs4",
33
"oses": [
44
"linux"
55
],
66
"integration": {
7-
"harness": "gotest",
7+
"harness": "switchblade",
88
"matrix": [
9-
{ "cached": false, "parallel": true },
10-
{ "cached": true, "parallel": true }
9+
{
10+
"cached": false,
11+
"parallel": true
12+
},
13+
{
14+
"cached": true,
15+
"parallel": true
16+
}
1117
]
1218
}
1319
}

fixtures/util/dynatrace/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module myapp
22

3-
go 1.17
3+
go 1.19

go.mod

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/Sealights/libbuildpack-sealights v1.5.0
99
github.com/blang/semver v3.5.1+incompatible
1010
github.com/cloudfoundry/libbuildpack v0.0.0-20240717165421-f2ae8069fcba
11+
github.com/cloudfoundry/switchblade v0.9.0
1112
github.com/go-ini/ini v1.67.0
1213
github.com/golang/mock v1.6.0
1314
github.com/gravityblast/go-jsmin v0.0.0-20141027113318-a32d741b3595
@@ -20,19 +21,34 @@ require (
2021

2122
require (
2223
code.cloudfoundry.org/lager v2.0.0+incompatible // indirect
24+
github.com/Microsoft/go-winio v0.6.0 // indirect
2325
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
26+
github.com/docker/distribution v2.8.1+incompatible // indirect
27+
github.com/docker/docker v24.0.9+incompatible // indirect
28+
github.com/docker/go-connections v0.4.0 // indirect
29+
github.com/docker/go-units v0.5.0 // indirect
2430
github.com/elazarl/goproxy v1.2.8 // indirect
2531
github.com/fsnotify/fsnotify v1.8.0 // indirect
32+
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
33+
github.com/gogo/protobuf v1.3.2 // indirect
2634
github.com/google/go-cmp v0.6.0 // indirect
2735
github.com/nxadm/tail v1.4.11 // indirect
36+
github.com/opencontainers/go-digest v1.0.0 // indirect
37+
github.com/opencontainers/image-spec v1.1.0 // indirect
2838
github.com/paketo-buildpacks/packit v1.3.1 // indirect
39+
github.com/paketo-buildpacks/packit/v2 v2.16.0 // indirect
2940
github.com/pilu/miniassert v0.0.0-20140522125902-bee63581261a // indirect
41+
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569 // indirect
3042
github.com/tidwall/gjson v1.18.0 // indirect
3143
github.com/tidwall/match v1.1.1 // indirect
3244
github.com/tidwall/pretty v1.2.1 // indirect
45+
github.com/ulikunitz/xz v0.5.12 // indirect
46+
golang.org/x/mod v0.22.0 // indirect
3347
golang.org/x/net v0.34.0 // indirect
48+
golang.org/x/sync v0.10.0 // indirect
3449
golang.org/x/sys v0.29.0 // indirect
3550
golang.org/x/text v0.21.0 // indirect
51+
golang.org/x/tools v0.29.0 // indirect
3652
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
3753
gopkg.in/yaml.v2 v2.4.0 // indirect
3854
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 3044 additions & 5 deletions
Large diffs are not rendered by default.

manifest.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ dependencies:
5050
source: https://registry.npmjs.org/bower/-/bower-1.8.14.tgz
5151
source_sha256: 00df3dcc6e8b3a4dd7668934a20e60e6fc0c4269790192179388c928553a3f7e
5252
- name: dotnet-aspnetcore
53-
version: 8.0.13
54-
uri: https://buildpacks.cloudfoundry.org/dependencies/dotnet-aspnetcore/dotnet-aspnetcore_8.0.13_linux_x64_any-stack_8ee97d6c.tar.xz
55-
sha256: 8ee97d6c493008ebf94cb7b30ec9426151fdadddfc51af418aa46b57cad0784c
53+
version: 8.0.14
54+
uri: https://buildpacks.cloudfoundry.org/dependencies/dotnet-aspnetcore/dotnet-aspnetcore_8.0.14_linux_x64_any-stack_c251b9de.tar.xz
55+
sha256: c251b9de2aa51440a13b5dcb2be31df7c0d78fe1c08cf2f842a9a3117b7393de
5656
cf_stacks:
5757
- cflinuxfs4
5858
- cflinuxfs3
59-
source: https://download.visualstudio.microsoft.com/download/pr/2115caf0-c47f-448a-8ad6-107a742d2b9e/52036588ffe8f8abd87a3d033fd93b67/aspnetcore-runtime-8.0.13-linux-x64.tar.gz
60-
source_sha256: b438f4e8f5f23b247ad56146505ce853bb09505b9af8294d0293bfce806663da
59+
source: https://download.visualstudio.microsoft.com/download/pr/b901af61-a4e5-41db-9402-f6a035bf3ffc/af3e800d44ced22133fd88f8b7bc4ac0/aspnetcore-runtime-8.0.14-linux-x64.tar.gz
60+
source_sha256: beb58baaf8aeab23a7a77caa25547f7d5adb9a1d397d5a84e81860a069966039
6161
- name: dotnet-aspnetcore
6262
version: 9.0.3
6363
uri: https://buildpacks.cloudfoundry.org/dependencies/dotnet-aspnetcore/dotnet-aspnetcore_9.0.3_linux_x64_any-stack_ddadf26c.tar.xz

old-integration/dynatrace_test.go

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
package integration_test
2+
3+
import (
4+
"fmt"
5+
"os/exec"
6+
"path/filepath"
7+
"testing"
8+
"time"
9+
10+
"github.com/cloudfoundry/libbuildpack/cutlass"
11+
"github.com/sclevine/spec"
12+
13+
. "github.com/onsi/gomega"
14+
)
15+
16+
func testDynatrace(t *testing.T, context spec.G, it spec.S) {
17+
var (
18+
Expect = NewWithT(t).Expect
19+
Eventually = NewWithT(t).Eventually
20+
21+
app *cutlass.App
22+
services []string
23+
)
24+
25+
it.Before(func() {
26+
app = cutlass.New(filepath.Join(settings.FixturesPath, "source_apps", "simple"))
27+
app.SetEnv("BP_DEBUG", "true")
28+
PushAppAndConfirm(t, app)
29+
})
30+
31+
it.After(func() {
32+
app = DestroyApp(t, app)
33+
34+
for _, service := range services {
35+
command := exec.Command("cf", "delete-service", "-f", service)
36+
_, err := command.Output()
37+
Expect(err).NotTo(HaveOccurred())
38+
}
39+
})
40+
41+
context("deploying a .NET Core app with Dynatrace agent with single credentials service", func() {
42+
it("checks if Dynatrace injection was successful", func() {
43+
service := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
44+
command := exec.Command("cf", "cups", service, "-p", fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI))
45+
output, err := command.CombinedOutput()
46+
Expect(err).NotTo(HaveOccurred(), string(output))
47+
services = append(services, service)
48+
49+
command = exec.Command("cf", "bind-service", app.Name, service)
50+
output, err = command.CombinedOutput()
51+
Expect(err).NotTo(HaveOccurred(), string(output))
52+
53+
command = exec.Command("cf", "restage", app.Name)
54+
output, err = command.CombinedOutput()
55+
Expect(err).NotTo(HaveOccurred(), string(output))
56+
57+
Expect(app.ConfirmBuildpack(settings.Buildpack.Version)).To(Succeed())
58+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace OneAgent"))
59+
Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace OneAgent installer"))
60+
Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh"))
61+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent installed."))
62+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent injection is set up."))
63+
})
64+
})
65+
66+
context("deploying a .Net Core app with Dynatrace agent with configured network zone", func() {
67+
it("checks if Dynatrace injection was successful", func() {
68+
serviceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
69+
command := exec.Command("cf", "cups", serviceName, "-p", fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\", \"networkzone\":\"testzone\"}'", settings.Dynatrace.URI))
70+
_, err := command.CombinedOutput()
71+
Expect(err).To(BeNil())
72+
services = append(services, serviceName)
73+
74+
command = exec.Command("cf", "bind-service", app.Name, serviceName)
75+
_, err = command.CombinedOutput()
76+
Expect(err).To(BeNil())
77+
command = exec.Command("cf", "restage", app.Name)
78+
_, err = command.Output()
79+
Expect(err).To(BeNil())
80+
81+
Expect(app.ConfirmBuildpack(settings.Buildpack.Version)).To(Succeed())
82+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace OneAgent"))
83+
Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace OneAgent installer"))
84+
Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh"))
85+
Expect(app.Stdout.String()).To(ContainSubstring("Setting DT_NETWORK_ZONE..."))
86+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent installed."))
87+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent injection is set up."))
88+
})
89+
})
90+
91+
context("deploying a .NET Core app with Dynatrace agent with two credentials services", func() {
92+
it("checks if detection of second service with credentials works", func() {
93+
credentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
94+
command := exec.Command("cf", "cups", credentialsServiceName, "-p",
95+
fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI))
96+
_, err := command.CombinedOutput()
97+
Expect(err).To(BeNil())
98+
services = append(services, credentialsServiceName)
99+
100+
duplicateCredentialsServiceName := "dynatrace-dupe-" + cutlass.RandStringRunes(20) + "-service"
101+
command = exec.Command("cf", "cups", duplicateCredentialsServiceName, "-p",
102+
fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI))
103+
_, err = command.CombinedOutput()
104+
Expect(err).To(BeNil())
105+
services = append(services, duplicateCredentialsServiceName)
106+
107+
command = exec.Command("cf", "bind-service", app.Name, credentialsServiceName)
108+
_, err = command.CombinedOutput()
109+
Expect(err).To(BeNil())
110+
command = exec.Command("cf", "bind-service", app.Name, duplicateCredentialsServiceName)
111+
_, err = command.CombinedOutput()
112+
Expect(err).To(BeNil())
113+
114+
command = exec.Command("cf", "restage", app.Name)
115+
_, err = command.Output()
116+
Expect(err).To(BeNil())
117+
118+
Expect(app.Stdout.String()).To(ContainSubstring("More than one matching service found!"))
119+
})
120+
})
121+
122+
context("deploying a .NET Core app with Dynatrace agent with failing agent download and ignoring errors", func() {
123+
it("checks if skipping download errors works", func() {
124+
credentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
125+
command := exec.Command("cf", "cups", credentialsServiceName, "-p",
126+
fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s/no-such-endpoint\",\"environmentid\":\"envid\",\"skiperrors\":\"true\"}'", settings.Dynatrace.URI))
127+
_, err := command.CombinedOutput()
128+
Expect(err).To(BeNil())
129+
services = append(services, credentialsServiceName)
130+
131+
command = exec.Command("cf", "bind-service", app.Name, credentialsServiceName)
132+
_, err = command.CombinedOutput()
133+
Expect(err).To(BeNil())
134+
135+
command = exec.Command("cf", "restage", app.Name)
136+
_, err = command.Output()
137+
Expect(err).To(BeNil())
138+
139+
Expect(app.Stdout.String()).To(ContainSubstring("Download returned with status 404"))
140+
Expect(app.Stdout.String()).To(ContainSubstring("Error during installer download, skipping installation"))
141+
})
142+
})
143+
144+
context("deploying a .NET Core app with Dynatrace agent with two dynatrace services", func() {
145+
it("check if service detection isn't disturbed by a service with tags", func() {
146+
credentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
147+
command := exec.Command("cf", "cups", credentialsServiceName, "-p",
148+
fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI))
149+
_, err := command.CombinedOutput()
150+
Expect(err).To(BeNil())
151+
services = append(services, credentialsServiceName)
152+
153+
tagsServiceName := "dynatrace-tags-" + cutlass.RandStringRunes(20) + "-service"
154+
command = exec.Command("cf", "cups", tagsServiceName, "-p", "'{\"tag:dttest\":\"dynatrace_test\"}'")
155+
_, err = command.CombinedOutput()
156+
Expect(err).To(BeNil())
157+
services = append(services, tagsServiceName)
158+
159+
command = exec.Command("cf", "bind-service", app.Name, credentialsServiceName)
160+
_, err = command.CombinedOutput()
161+
Expect(err).To(BeNil())
162+
command = exec.Command("cf", "bind-service", app.Name, tagsServiceName)
163+
_, err = command.CombinedOutput()
164+
Expect(err).To(BeNil())
165+
166+
command = exec.Command("cf", "restage", app.Name)
167+
_, err = command.Output()
168+
Expect(err).To(BeNil())
169+
170+
Expect(app.ConfirmBuildpack(settings.Buildpack.Version)).To(Succeed())
171+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace OneAgent."))
172+
Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace OneAgent installer"))
173+
Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh"))
174+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent installed."))
175+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent injection is set up."))
176+
})
177+
})
178+
179+
context("deploying a .NET Core app with Dynatrace agent with single credentials service and without manifest.json", func() {
180+
it("checks if Dynatrace injection was successful", func() {
181+
serviceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
182+
command := exec.Command("cf", "cups", serviceName, "-p",
183+
fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI))
184+
_, err := command.CombinedOutput()
185+
Expect(err).To(BeNil())
186+
services = append(services, serviceName)
187+
188+
command = exec.Command("cf", "bind-service", app.Name, serviceName)
189+
_, err = command.CombinedOutput()
190+
Expect(err).To(BeNil())
191+
command = exec.Command("cf", "restage", app.Name)
192+
_, err = command.Output()
193+
Expect(err).To(BeNil())
194+
195+
Expect(app.ConfirmBuildpack(settings.Buildpack.Version)).To(Succeed())
196+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace OneAgent."))
197+
Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace OneAgent installer"))
198+
Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh"))
199+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent installed."))
200+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent injection is set up."))
201+
})
202+
})
203+
204+
context("deploying a .NET Core app with Dynatrace agent with failing agent download and checking retry", func() {
205+
it.Before(func() {
206+
SetDefaultEventuallyTimeout(5 * time.Second)
207+
})
208+
209+
it("checks if retrying downloads works", func() {
210+
credentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
211+
command := exec.Command("cf", "cups", credentialsServiceName, "-p",
212+
fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s/no-such-endpoint\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI))
213+
_, err := command.CombinedOutput()
214+
Expect(err).To(BeNil())
215+
services = append(services, credentialsServiceName)
216+
217+
command = exec.Command("cf", "bind-service", app.Name, credentialsServiceName)
218+
_, err = command.CombinedOutput()
219+
Expect(err).To(BeNil())
220+
221+
command = exec.Command("cf", "restage", app.Name)
222+
_, err = command.CombinedOutput()
223+
224+
Eventually(app.Stdout.String).Should(ContainSubstring("Error during installer download, retrying in 4s"))
225+
Eventually(app.Stdout.String).Should(ContainSubstring("Error during installer download, retrying in 5s"))
226+
Eventually(app.Stdout.String).Should(ContainSubstring("Error during installer download, retrying in 7s"))
227+
Eventually(app.Stdout.String).Should(ContainSubstring("Download returned with status 404"))
228+
229+
Eventually(app.Stdout.String).Should(ContainSubstring("Failed to compile droplet"))
230+
})
231+
})
232+
233+
context("deploying a .NET Core app with Dynatrace agent with single credentials service and a redis service", func() {
234+
it("checks if Dynatrace injection was successful", func() {
235+
serviceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
236+
command := exec.Command("cf", "cups", serviceName, "-p",
237+
fmt.Sprintf("'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"%s\",\"environmentid\":\"envid\"}'", settings.Dynatrace.URI))
238+
_, err := command.CombinedOutput()
239+
Expect(err).To(BeNil())
240+
services = append(services, serviceName)
241+
command = exec.Command("cf", "bind-service", app.Name, serviceName)
242+
_, err = command.CombinedOutput()
243+
Expect(err).To(BeNil())
244+
245+
redisServiceName := "redis-" + cutlass.RandStringRunes(20) + "-service"
246+
command = exec.Command("cf", "cups", redisServiceName, "-p", "'{\"name\":\"redis\", \"credentials\":{\"db_type\":\"redis\", \"instance_administration_api\":{\"deployment_id\":\"12345asdf\", \"instance_id\":\"12345asdf\", \"root\":\"https://doesnotexi.st\"}}}'")
247+
_, err = command.CombinedOutput()
248+
Expect(err).To(BeNil())
249+
services = append(services, redisServiceName)
250+
command = exec.Command("cf", "bind-service", app.Name, redisServiceName)
251+
_, err = command.CombinedOutput()
252+
Expect(err).To(BeNil())
253+
254+
command = exec.Command("cf", "restage", app.Name)
255+
_, err = command.Output()
256+
Expect(err).To(BeNil())
257+
258+
Expect(app.ConfirmBuildpack(settings.Buildpack.Version)).To(Succeed())
259+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace OneAgent."))
260+
Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace OneAgent installer"))
261+
Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh"))
262+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent installed."))
263+
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace OneAgent injection is set up."))
264+
})
265+
})
266+
}

0 commit comments

Comments
 (0)