How to use PackageNameFor method of integration_test Package

Best Ginkgo code snippet using integration_test.PackageNameFor

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

integration_suite_test.go

Source: integration_suite_test.go Github

copy
1package integration_test
2
3import (
4	"bytes"
5	"encoding/json"
6	"encoding/xml"
7	"flag"
8	"fmt"
9	"os"
10	"os/exec"
11	"path/filepath"
12	"runtime"
13
14	. "github.com/onsi/ginkgo/v2"
15	"github.com/onsi/ginkgo/v2/reporters"
16	"github.com/onsi/ginkgo/v2/types"
17	. "github.com/onsi/gomega"
18	"github.com/onsi/gomega/format"
19	"github.com/onsi/gomega/gexec"
20
21	"testing"
22	"time"
23)
24
25var pathToGinkgo string
26var DEBUG bool
27var fm FixtureManager
28
29func init() {
30	flag.BoolVar(&DEBUG, "debug", false, "keep assets around after test run")
31}
32
33func TestIntegration(t *testing.T) {
34	SetDefaultEventuallyTimeout(30 * time.Second)
35	format.TruncatedDiff = false
36	RegisterFailHandler(Fail)
37	RunSpecs(t, "Integration Suite", Label("integration"))
38}
39
40var _ = SynchronizedBeforeSuite(func() []byte {
41	DeferCleanup(gexec.CleanupBuildArtifacts)
42	pathToGinkgo, err := gexec.Build("../ginkgo")
43	Ω(err).ShouldNot(HaveOccurred())
44	return []byte(pathToGinkgo)
45}, func(computedPathToGinkgo []byte) {
46	pathToGinkgo = string(computedPathToGinkgo)
47})
48
49var _ = BeforeEach(OncePerOrdered, func() {
50	fm = NewFixtureManager(fmt.Sprintf("tmp_%d", GinkgoParallelProcess()))
51})
52
53var _ = AfterEach(OncePerOrdered, func() {
54	if DEBUG {
55		return
56	}
57	suiteConfig, _ := GinkgoConfiguration()
58	if CurrentSpecReport().Failed() && suiteConfig.FailFast {
59		return
60	}
61	fm.Cleanup()
62})
63
64type FixtureManager struct {
65	TmpDir string
66}
67
68func NewFixtureManager(tmpDir string) FixtureManager {
69	err := os.MkdirAll(tmpDir, 0700)
70	Ω(err).ShouldNot(HaveOccurred())
71	return FixtureManager{
72		TmpDir: tmpDir,
73	}
74}
75
76func (f FixtureManager) Cleanup() {
77	Ω(os.RemoveAll(f.TmpDir)).Should(Succeed())
78}
79
80func (f FixtureManager) MountFixture(fixture string, subPackage ...string) {
81	src := filepath.Join("_fixtures", fixture+"_fixture")
82	dst := filepath.Join(f.TmpDir, fixture)
83
84	if len(subPackage) > 0 {
85		src = filepath.Join(src, subPackage[0])
86		dst = filepath.Join(dst, subPackage[0])
87	}
88
89	f.copyAndRewrite(src, dst)
90}
91
92func (f FixtureManager) MkEmpty(pkg string) {
93	ExpectWithOffset(1, os.MkdirAll(f.PathTo(pkg), 0700)).Should(Succeed())
94}
95
96func (f FixtureManager) copyAndRewrite(src string, dst string) {
97	Expect(os.MkdirAll(dst, 0777)).To(Succeed())
98
99	files, err := os.ReadDir(src)
100	Expect(err).NotTo(HaveOccurred())
101
102	for _, file := range files {
103		srcPath := filepath.Join(src, file.Name())
104		dstPath := filepath.Join(dst, file.Name())
105		if file.IsDir() {
106			f.copyAndRewrite(srcPath, dstPath)
107			continue
108		}
109
110		srcContent, err := os.ReadFile(srcPath)
111		Ω(err).ShouldNot(HaveOccurred())
112		//rewrite import statements so that fixtures can work in the fixture folder when developing them, and in the tmp folder when under test
113		srcContent = bytes.ReplaceAll(srcContent, []byte("github.com/onsi/ginkgo/v2/integration/_fixtures"), []byte(f.PackageRoot()))
114		srcContent = bytes.ReplaceAll(srcContent, []byte("_fixture"), []byte(""))
115		Ω(os.WriteFile(dstPath, srcContent, 0666)).Should(Succeed())
116	}
117}
118
119func (f FixtureManager) AbsPathTo(pkg string, target ...string) string {
120	path, err := filepath.Abs(f.PathTo(pkg, target...))
121	ExpectWithOffset(1, err).NotTo(HaveOccurred())
122	return path
123}
124
125func (f FixtureManager) PathTo(pkg string, target ...string) string {
126	if len(target) == 0 {
127		return filepath.Join(f.TmpDir, pkg)
128	}
129	components := append([]string{f.TmpDir, pkg}, target...)
130	return filepath.Join(components...)
131}
132
133func (f FixtureManager) PathToFixtureFile(pkg string, target string) string {
134	return filepath.Join("_fixtures", pkg+"_fixture", target)
135}
136
137func (f FixtureManager) WriteFile(pkg string, target string, content string) {
138	dst := f.PathTo(pkg, target)
139	err := os.WriteFile(dst, []byte(content), 0666)
140	Ω(err).ShouldNot(HaveOccurred())
141}
142
143func (f FixtureManager) AppendToFile(pkg string, target string, content string) {
144	current := f.ContentOf(pkg, target)
145	f.WriteFile(pkg, target, current+content)
146}
147
148func (f FixtureManager) ContentOf(pkg string, target string) string {
149	content, err := os.ReadFile(f.PathTo(pkg, target))
150	ExpectWithOffset(1, err).NotTo(HaveOccurred())
151	return string(content)
152}
153
154func (f FixtureManager) ListDir(pkg string, target ...string) []string {
155	path := f.PathTo(pkg, target...)
156	files, err := os.ReadDir(path)
157	ExpectWithOffset(1, err).NotTo(HaveOccurred())
158	out := []string{}
159	for _, f := range files {
160		out = append(out, f.Name())
161	}
162	return out
163}
164
165func (f FixtureManager) LoadJSONReports(pkg string, target string) []types.Report {
166	data := []byte(f.ContentOf(pkg, target))
167	reports := []types.Report{}
168	ExpectWithOffset(1, json.Unmarshal(data, &reports)).Should(Succeed())
169	return reports
170}
171
172func (f FixtureManager) LoadJUnitReport(pkg string, target string) reporters.JUnitTestSuites {
173	data := []byte(f.ContentOf(pkg, target))
174	reports := reporters.JUnitTestSuites{}
175	ExpectWithOffset(1, xml.Unmarshal(data, &reports)).Should(Succeed())
176	return reports
177}
178
179func (f FixtureManager) ContentOfFixture(pkg string, target string) string {
180	content, err := os.ReadFile(f.PathToFixtureFile(pkg, target))
181	ExpectWithOffset(1, err).NotTo(HaveOccurred())
182	return string(content)
183}
184
185func (f FixtureManager) RemoveFile(pkg string, target string) {
186	Expect(os.RemoveAll(f.PathTo(pkg, target))).To(Succeed())
187}
188
189func (f FixtureManager) PackageRoot() string {
190	return "github.com/onsi/ginkgo/v2/integration/" + f.TmpDir
191}
192
193func (f FixtureManager) PackageNameFor(target string) string {
194	return f.PackageRoot() + "/" + target
195}
196
197func sameFile(filePath, otherFilePath string) bool {
198	content, readErr := os.ReadFile(filePath)
199	Expect(readErr).NotTo(HaveOccurred())
200	otherContent, readErr := os.ReadFile(otherFilePath)
201	Expect(readErr).NotTo(HaveOccurred())
202	Expect(string(content)).To(Equal(string(otherContent)))
203	return true
204}
205
206func sameFolder(sourcePath, destinationPath string) bool {
207	files, err := os.ReadDir(sourcePath)
208	Expect(err).NotTo(HaveOccurred())
209	for _, f := range files {
210		srcPath := filepath.Join(sourcePath, f.Name())
211		dstPath := filepath.Join(destinationPath, f.Name())
212		if f.IsDir() {
213			sameFolder(srcPath, dstPath)
214			continue
215		}
216		Expect(sameFile(srcPath, dstPath)).To(BeTrue())
217	}
218	return true
219}
220
221func ginkgoCommand(dir string, args ...string) *exec.Cmd {
222	cmd := exec.Command(pathToGinkgo, args...)
223	cmd.Dir = dir
224
225	return cmd
226}
227
228func startGinkgo(dir string, args ...string) *gexec.Session {
229	cmd := ginkgoCommand(dir, args...)
230	session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
231	Ω(err).ShouldNot(HaveOccurred())
232	return session
233}
234
235func raceDetectorSupported() bool {
236	// https://github.com/golang/go/blob/1a370950/src/cmd/internal/sys/supported.go#L12
237	switch runtime.GOOS {
238	case "linux":
239		return runtime.GOARCH == "amd64" || runtime.GOARCH == "ppc64le" || runtime.GOARCH == "arm64"
240	case "darwin":
241		return runtime.GOARCH == "amd64" || runtime.GOARCH == "arm64"
242	case "freebsd", "netbsd", "windows":
243		return runtime.GOARCH == "amd64"
244	default:
245		return false
246	}
247}
248
Full Screen

profiling_test.go

Source: profiling_test.go Github

copy
1package integration_test
2
3import (
4	"os"
5	"os/exec"
6	"regexp"
7	"strconv"
8	"strings"
9	"time"
10
11	"fmt"
12
13	. "github.com/onsi/ginkgo/v2"
14	. "github.com/onsi/gomega"
15	"github.com/onsi/gomega/gbytes"
16	"github.com/onsi/gomega/gexec"
17)
18
19type ProfileLine struct {
20	Index   int
21	Caller  string
22	CumStat float64
23}
24
25type ProfileLines []ProfileLine
26
27func (lines ProfileLines) FindCaller(caller string) ProfileLine {
28	for _, line := range lines {
29		if strings.Contains(line.Caller, caller) {
30			return line
31		}
32	}
33
34	Fail(fmt.Sprintf("Could not find caller %s among profile lines %+v.", caller, lines), 1)
35	return ProfileLine{}
36}
37
38var PROFILE_RE = regexp.MustCompile(`[\d\.]+[MBms]*\s*[\d\.]+\%\s*[\d\.]+\%\s*([\d\.]+[MBnms]*)\s*[\d\.]+\%\s*(.*)`)
39
40func ParseProfile(binary string, path string) ProfileLines {
41	cmd := exec.Command("go", "tool", "pprof", "-cum", "-top", binary, path)
42	output, err := cmd.CombinedOutput()
43	GinkgoWriter.Printf("Profile for: %s\n%s\n", path, string(output))
44	ExpectWithOffset(1, err).ShouldNot(HaveOccurred())
45	out := ProfileLines{}
46	idx := 0
47	for _, line := range strings.Split(string(output), "\n") {
48		matches := PROFILE_RE.FindStringSubmatch(line)
49		if matches == nil {
50			continue
51		}
52		cumStatEntry := matches[1]
53		var cumStat float64
54		if strings.Contains(cumStatEntry, "MB") {
55			var err error
56			cumStat, err = strconv.ParseFloat(strings.TrimRight(cumStatEntry, "MB"), 64)
57			ExpectWithOffset(1, err).ShouldNot(HaveOccurred())
58		} else {
59			duration, err := time.ParseDuration(cumStatEntry)
60			ExpectWithOffset(1, err).ShouldNot(HaveOccurred())
61			cumStat = float64(duration.Milliseconds())
62		}
63		out = append(out, ProfileLine{
64			Index:   idx,
65			Caller:  matches[2],
66			CumStat: cumStat,
67		})
68		idx += 1
69	}
70	return out
71}
72
73var _ = Describe("Profiling Specs", func() {
74	Describe("Measuring code coverage", func() {
75		BeforeEach(func() {
76			fm.MountFixture("coverage")
77		})
78
79		processCoverageProfile := func(path string) string {
80			profileOutput, err := exec.Command("go", "tool", "cover", fmt.Sprintf("-func=%s", path)).CombinedOutput()
81			ExpectWithOffset(1, err).ShouldNot(HaveOccurred())
82			return string(profileOutput)
83		}
84
85		Context("when running a single package in series or in parallel with -cover", func() {
86			It("emits the coverage pecentage and generates a cover profile", func() {
87				seriesSession := startGinkgo(fm.PathTo("coverage"), "--no-color", "-cover")
88				Eventually(seriesSession).Should(gexec.Exit(0))
89				Ω(seriesSession.Out).Should(gbytes.Say(`coverage: 80\.0% of statements`))
90				seriesCoverage := processCoverageProfile(fm.PathTo("coverage", "coverprofile.out"))
91				fm.RemoveFile("coverage", "coverprofile.out")
92
93				parallelSession := startGinkgo(fm.PathTo("coverage"), "--no-color", "--procs=2", "-cover")
94				Eventually(parallelSession).Should(gexec.Exit(0))
95				Ω(parallelSession.Out).Should(gbytes.Say(`coverage: 80\.0% of statements`))
96				parallelCoverage := processCoverageProfile(fm.PathTo("coverage", "coverprofile.out"))
97
98				Ω(parallelCoverage).Should(Equal(seriesCoverage))
99			})
100		})
101
102		Context("with -coverpkg", func() {
103			It("computes coverage of the passed-in additional packages", func() {
104				coverPkgFlag := fmt.Sprintf("-coverpkg=%s,%s", fm.PackageNameFor("coverage"), fm.PackageNameFor("coverage/external_coverage"))
105				seriesSession := startGinkgo(fm.PathTo("coverage"), coverPkgFlag)
106				Eventually(seriesSession).Should(gexec.Exit(0))
107				Ω(seriesSession.Out).Should(gbytes.Say("coverage: 71.4% of statements in"))
108				seriesCoverage := processCoverageProfile(fm.PathTo("coverage", "coverprofile.out"))
109				fm.RemoveFile("coverage", "coverprofile.out")
110
111				parallelSession := startGinkgo(fm.PathTo("coverage"), "--no-color", "--procs=2", coverPkgFlag)
112				Eventually(parallelSession).Should(gexec.Exit(0))
113				Ω(parallelSession.Out).Should(gbytes.Say(`coverage: 71\.4% of statements`))
114				parallelCoverage := processCoverageProfile(fm.PathTo("coverage", "coverprofile.out"))
115
116				Ω(parallelCoverage).Should(Equal(seriesCoverage))
117			})
118		})
119
120		Context("with a custom profile name", func() {
121			It("generates cover profiles with the specified name", func() {
122				session := startGinkgo(fm.PathTo("coverage"), "--no-color", "-coverprofile=myprofile.out")
123				Eventually(session).Should(gexec.Exit(0))
124				Ω(session.Out).Should(gbytes.Say(`coverage: 80\.0% of statements`))
125				Ω(fm.PathTo("coverage", "myprofile.out")).Should(BeAnExistingFile())
126				Ω(fm.PathTo("coverage", "coverprofile.out")).ShouldNot(BeAnExistingFile())
127			})
128		})
129
130		Context("when multiple suites are tested", func() {
131			BeforeEach(func() {
132				fm.MountFixture("combined_coverage")
133			})
134
135			It("generates a single cover profile", func() {
136				session := startGinkgo(fm.PathTo("combined_coverage"), "--no-color", "--cover", "-r", "--procs=2", "--covermode=atomic")
137				Eventually(session).Should(gexec.Exit(0))
138				Ω(fm.PathTo("combined_coverage", "coverprofile.out")).Should(BeAnExistingFile())
139				Ω(fm.PathTo("combined_coverage", "first_package/coverprofile.out")).ShouldNot(BeAnExistingFile())
140				Ω(fm.PathTo("combined_coverage", "second_package/coverprofile.out")).ShouldNot(BeAnExistingFile())
141				Ω(fm.PathTo("combined_coverage", "third_package/coverprofile.out")).ShouldNot(BeAnExistingFile())
142
143				Ω(session.Out).Should(gbytes.Say(`coverage: 80\.0% of statements`))
144				Ω(session.Out).Should(gbytes.Say(`coverage: 100\.0% of statements`))
145				Ω(session.Out).Should(gbytes.Say(`coverage: \[no statements\]`))
146
147				By("ensuring there is only one 'mode:' line")
148				re := regexp.MustCompile(`mode: atomic`)
149				content := fm.ContentOf("combined_coverage", "coverprofile.out")
150				matches := re.FindAllStringIndex(content, -1)
151				Ω(len(matches)).Should(Equal(1))
152
153				By("emitting a composite coverage score")
154				Ω(session.Out).Should(gbytes.Say(`composite coverage: 90\.0% of statements`))
155			})
156
157			Context("when -keep-separate-coverprofiles is set", func() {
158				It("generates separate coverprofiles", Label("slow"), func() {
159					session := startGinkgo(fm.PathTo("combined_coverage"), "--no-color", "--cover", "-r", "--procs=2", "--keep-separate-coverprofiles")
160					Eventually(session).Should(gexec.Exit(0))
161					Ω(fm.PathTo("combined_coverage", "coverprofile.out")).ShouldNot(BeAnExistingFile())
162					Ω(fm.PathTo("combined_coverage", "first_package/coverprofile.out")).Should(BeAnExistingFile())
163					Ω(fm.PathTo("combined_coverage", "second_package/coverprofile.out")).Should(BeAnExistingFile())
164					Ω(fm.PathTo("combined_coverage", "third_package/coverprofile.out")).Should(BeAnExistingFile())
165				})
166			})
167		})
168
169		Context("when -output-dir is set", func() {
170			BeforeEach(func() {
171				fm.MountFixture("combined_coverage")
172			})
173
174			It("puts the cover profile in -output-dir", func() {
175				session := startGinkgo(fm.PathTo("combined_coverage"), "--no-color", "--cover", "-r", "--procs=2", "--output-dir=./output")
176				Eventually(session).Should(gexec.Exit(0))
177				Ω(fm.PathTo("combined_coverage", "output/coverprofile.out")).Should(BeAnExistingFile())
178
179				By("emitting a composite coverage score")
180				Ω(session.Out).Should(gbytes.Say(`composite coverage: 90\.0% of statements`))
181			})
182
183			Context("when -keep-separate-coverprofiles is set", func() {
184				It("puts namespaced coverprofiels in the -output-dir", func() {
185					session := startGinkgo(fm.PathTo("combined_coverage"), "--no-color", "--cover", "-r", "--procs=2", "--output-dir=./output", "--keep-separate-coverprofiles")
186					Eventually(session).Should(gexec.Exit(0))
187					Ω(fm.PathTo("combined_coverage", "output/coverprofile.out")).ShouldNot(BeAnExistingFile())
188					Ω(fm.PathTo("combined_coverage", "output/first_package_coverprofile.out")).Should(BeAnExistingFile())
189					Ω(fm.PathTo("combined_coverage", "output/second_package_coverprofile.out")).Should(BeAnExistingFile())
190				})
191			})
192		})
193	})
194
195	Describe("measuring cpu, memory, block, and mutex profiles", func() {
196		BeforeEach(func() {
197			fm.MountFixture("profile")
198		})
199
200		DescribeTable("profile behavior",
201			func(pathToBinary func(string) string, pathToProfile func(string, string) string, args ...string) {
202				args = append([]string{"--no-color", "-r", "--cpuprofile=cpu.out", "--memprofile=mem.out", "--blockprofile=block.out", "--mutexprofile=mutex.out"}, args...)
203				session := startGinkgo(fm.PathTo("profile"), args...)
204				Eventually(session).Should(gexec.Exit(0))
205
206				// Verify that the binaries have been preserved and the profiles were generated
207				for _, pkg := range []string{"slow_memory_hog", "block_contest", "lock_contest"} {
208					Ω(pathToBinary(pkg)).Should(BeAnExistingFile())
209					for _, profile := range []string{"cpu.out", "mem.out", "block.out", "mutex.out"} {
210						Ω(pathToProfile(pkg, profile)).Should(BeAnExistingFile())
211					}
212				}
213
214				cpuProfile := ParseProfile(pathToBinary("slow_memory_hog"), pathToProfile("slow_memory_hog", "cpu.out"))
215				// The CPUProfile for the slow_memory_hog test should list the slow_memory_hog.SomethingExpensive functions as one of the most time-consuming functions
216				// we can't assert on time as that will vary from machine to machine, however we _can_ assert that the slow_memory_hog.SomethingExpensive
217				// function has a low index
218				Ω(cpuProfile.FindCaller("slow_memory_hog.SomethingExpensive").Index).Should(BeNumerically("<=", 10))
219
220				memProfile := ParseProfile(pathToBinary("slow_memory_hog"), pathToProfile("slow_memory_hog", "mem.out"))
221				// The MemProifle for the slow_memory_hog test should list the slow_memory_hog.SomethingExpensive functions as one of the most memory-consuming functions
222				// Assrting on the amount of memory consumed should be stable across tests as the function always builds a large array of this size
223				Ω(memProfile.FindCaller("slow_memory_hog.SomethingExpensive").CumStat).Should(BeNumerically(">=", 200))
224
225				blockProfile := ParseProfile(pathToBinary("block_contest"), pathToProfile("block_contest", "block.out"))
226				// The BlockProfile for the block_contest test should list two channel-reading functions:
227				// block_contest.ReadTheChannel is called 10 times and takes ~5ms per call
228				// block_contest.SlowReadTheChannel is called once and teakes ~500ms per call
229				// Asserting that both times are within a range should be stable across tests
230				// Note: these numbers are adjusted slightly to tolerate variance during test runs
231				Ω(blockProfile.FindCaller("block_contest.ReadTheChannel").CumStat).Should(BeNumerically(">=", 45))
232				Ω(blockProfile.FindCaller("block_contest.ReadTheChannel").CumStat).Should(BeNumerically("<", 500))
233				Ω(blockProfile.FindCaller("block_contest.SlowReadTheChannel").CumStat).Should(BeNumerically(">=", 450))
234
235				mutexProfile := ParseProfile(pathToBinary("lock_contest"), pathToProfile("lock_contest", "mutex.out"))
236				// The MutexProfile for the lock_contest test should list two functions that wait on a lock.
237				// Unfortunately go doesn't seem to capture the names of the functions - so they're listed here as
238				// lock_contest_test.glob..func1.1 is called 10 times and takes ~5ms per call
239				// lock_contest_test.glob..func2.1 is called once and teakes ~500ms per call
240				// Asserting that both times are within a range should be stable across tests.  The function names should be as well
241				// but that might become a source of failure in the future
242				// Note: these numbers are adjusted slightly to tolerate variance during test runs
243				Ω(mutexProfile.FindCaller("lock_contest_test.glob..func1.1").CumStat).Should(BeNumerically(">=", 45))
244				Ω(mutexProfile.FindCaller("lock_contest_test.glob..func1.1").CumStat).Should(BeNumerically("<", 500))
245				Ω(mutexProfile.FindCaller("lock_contest_test.glob..func2.1").CumStat).Should(BeNumerically(">=", 450))
246			},
247
248			Entry("when running in series",
249				func(pkg string) string { return fm.PathTo("profile", pkg+"/"+pkg+".test") },
250				func(pkg string, profile string) string { return fm.PathTo("profile", pkg+"/"+profile) },
251			),
252
253			Entry("when running in parallel",
254				func(pkg string) string { return fm.PathTo("profile", pkg+"/"+pkg+".test") },
255				func(pkg string, profile string) string { return fm.PathTo("profile", pkg+"/"+profile) },
256				"--procs=3",
257			),
258
259			Entry("when --output-dir is set", Label("slow"),
260				func(pkg string) string { return fm.PathTo("profile", "profiles/"+pkg+".test") },
261				func(pkg string, profile string) string { return fm.PathTo("profile", "profiles/"+pkg+"_"+profile) },
262				"--procs=3", "--output-dir=./profiles",
263			),
264		)
265
266		Context("when profiling a precompiled binary and output-dir is set", func() {
267			It("copies (not moves) the binary to output-dir", func() {
268				Eventually(startGinkgo(fm.PathTo("profile"), "build", "-r")).Should(gexec.Exit(0))
269				session := startGinkgo(fm.PathTo("profile"), "--cpuprofile=cpu.out", "--output-dir=./profiles", "./slow_memory_hog/slow_memory_hog.test", "./lock_contest/lock_contest.test", "./block_contest/block_contest.test")
270				Eventually(session).Should(gexec.Exit(0))
271
272				for _, pkg := range []string{"slow_memory_hog", "block_contest", "lock_contest"} {
273					Ω(fm.PathTo("profile", pkg, pkg+".test")).Should(BeAnExistingFile(), "preserve the precompiled binary in the package directory")
274					Ω(fm.PathTo("profile", "profiles", pkg+".test")).Should(BeAnExistingFile(), "copy the precompiled binary to the output-dir")
275					Ω(fm.PathTo("profile", "profiles", pkg+"_cpu.out")).Should(BeAnExistingFile(), "generate a correctly named cpu profile")
276				}
277			})
278		})
279	})
280
281	Context("with a read-only tree and a readable output-dir", func() {
282		BeforeEach(func() {
283			fm.MountFixture("profile")
284			sess := startGinkgo(fm.PathTo("profile"), "build", "-r", "-cover")
285			Eventually(sess).Should(gexec.Exit(0))
286			fm.MkEmpty("output")
287			Ω(os.Chmod(fm.PathTo("profile", "block_contest"), 0555)).Should(Succeed())
288			Ω(os.Chmod(fm.PathTo("profile", "lock_contest"), 0555)).Should(Succeed())
289			Ω(os.Chmod(fm.PathTo("profile", "slow_memory_hog"), 0555)).Should(Succeed())
290			Ω(os.Chmod(fm.PathTo("profile"), 0555)).Should(Succeed())
291		})
292
293		AfterEach(func() {
294			Ω(os.Chmod(fm.PathTo("profile"), 0755)).Should(Succeed())
295			Ω(os.Chmod(fm.PathTo("profile", "block_contest"), 0755)).Should(Succeed())
296			Ω(os.Chmod(fm.PathTo("profile", "lock_contest"), 0755)).Should(Succeed())
297			Ω(os.Chmod(fm.PathTo("profile", "slow_memory_hog"), 0755)).Should(Succeed())
298		})
299
300		It("never tries to write to the tree, and only emits to ouput-dir", func() {
301			sess := startGinkgo(fm.PathTo("profile"),
302				"--output-dir=../output",
303				"--cpuprofile=cpu.out",
304				"--memprofile=mem.out",
305				"--blockprofile=block.out",
306				"--mutexprofile=mutex.out",
307				"--coverprofile=cover.out",
308				"--json-report=report.json",
309				"--junit-report=report.xml",
310				"--teamcity-report=report.tm",
311				"--procs=2",
312				"./block_contest/block_contest.test",
313				"./lock_contest/lock_contest.test",
314				"./slow_memory_hog/slow_memory_hog.test",
315			)
316			Eventually(sess).Should(gexec.Exit(0))
317			Ω(fm.ListDir("output")).Should(ConsistOf(
318				"cover.out",
319				"report.json",
320				"report.xml",
321				"report.tm",
322				"block_contest_cpu.out",
323				"lock_contest_cpu.out",
324				"slow_memory_hog_cpu.out",
325				"block_contest_mem.out",
326				"lock_contest_mem.out",
327				"slow_memory_hog_mem.out",
328				"block_contest_block.out",
329				"lock_contest_block.out",
330				"slow_memory_hog_block.out",
331				"block_contest_mutex.out",
332				"lock_contest_mutex.out",
333				"slow_memory_hog_mutex.out",
334				"block_contest.test",
335				"lock_contest.test",
336				"slow_memory_hog.test",
337			))
338		})
339
340		It("also works when keeping separate reports and profiles and only emits to ouput-dir", func() {
341			sess := startGinkgo(fm.PathTo("profile"),
342				"--output-dir=../output",
343				"--cpuprofile=cpu.out",
344				"--memprofile=mem.out",
345				"--blockprofile=block.out",
346				"--mutexprofile=mutex.out",
347				"--coverprofile=cover.out",
348				"--json-report=report.json",
349				"--junit-report=report.xml",
350				"--teamcity-report=report.tm",
351				"--procs=2",
352				"--keep-separate-coverprofiles",
353				"--keep-separate-reports",
354				"./block_contest/block_contest.test",
355				"./lock_contest/lock_contest.test",
356				"./slow_memory_hog/slow_memory_hog.test",
357			)
358			Eventually(sess).Should(gexec.Exit(0))
359			Ω(fm.ListDir("output")).Should(ConsistOf(
360				"block_contest_cover.out",
361				"lock_contest_cover.out",
362				"slow_memory_hog_cover.out",
363				"block_contest_report.json",
364				"lock_contest_report.json",
365				"slow_memory_hog_report.json",
366				"block_contest_report.xml",
367				"lock_contest_report.xml",
368				"slow_memory_hog_report.xml",
369				"block_contest_report.tm",
370				"lock_contest_report.tm",
371				"slow_memory_hog_report.tm",
372				"block_contest_cpu.out",
373				"lock_contest_cpu.out",
374				"slow_memory_hog_cpu.out",
375				"block_contest_mem.out",
376				"lock_contest_mem.out",
377				"slow_memory_hog_mem.out",
378				"block_contest_block.out",
379				"lock_contest_block.out",
380				"slow_memory_hog_block.out",
381				"block_contest_mutex.out",
382				"lock_contest_mutex.out",
383				"slow_memory_hog_mutex.out",
384				"block_contest.test",
385				"lock_contest.test",
386				"slow_memory_hog.test",
387			))
388		})
389	})
390})
391
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger PackageNameFor code on LambdaTest Cloud Grid

Execute automation tests with PackageNameFor on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)