How to use PTS method of internal_test Package

Best Ginkgo code snippet using internal_test.PTS

testsuite_test.go

Source:testsuite_test.go Github

copy

Full Screen

...15 Precompiled: false,16 State: state,17 }18}19func PTS(path string, pkgName string, isGinkgo bool, pathToCompiledTest string, state TestSuiteState) TestSuite {20 return TestSuite{21 Path: path,22 PackageName: pkgName,23 IsGinkgo: isGinkgo,24 Precompiled: true,25 PathToCompiledTest: pathToCompiledTest,26 State: state,27 }28}29var _ = Describe("TestSuite", func() {30 Describe("Finding Suites", func() {31 var tmpDir string32 var origWd string33 var cliConf types.CLIConfig34 writeFile := func(folder string, filename string, content string, mode os.FileMode) {35 path := filepath.Join(tmpDir, folder)36 err := os.MkdirAll(path, 0700)37 Ω(err).ShouldNot(HaveOccurred())38 path = filepath.Join(path, filename)39 os.WriteFile(path, []byte(content), mode)40 }41 BeforeEach(func() {42 cliConf = types.CLIConfig{}43 var err error44 tmpDir, err = os.MkdirTemp("/tmp", "ginkgo")45 Ω(err).ShouldNot(HaveOccurred())46 origWd, err = os.Getwd()47 Ω(err).ShouldNot(HaveOccurred())48 Ω(os.Chdir(tmpDir)).Should(Succeed())49 //go files in the root directory (no tests)50 writeFile("/", "main.go", "package main", 0666)51 //non-go files in a nested directory52 writeFile("/redherring", "big_test.jpg", "package ginkgo", 0666)53 //ginkgo tests in ignored go files54 writeFile("/ignored", ".ignore_dot_test.go", `import "github.com/onsi/ginkgo/v2"`, 0666)55 writeFile("/ignored", "_ignore_underscore_test.go", `import "github.com/onsi/ginkgo/v2"`, 0666)56 //non-ginkgo tests in a nested directory57 writeFile("/professorplum", "professorplum_test.go", `import "testing"`, 0666)58 //ginkgo tests in a nested directory59 writeFile("/colonelmustard", "colonelmustard_test.go", `import "github.com/onsi/ginkgo/v2"`, 0666)60 //ginkgo tests in a deeply nested directory61 writeFile("/colonelmustard/library", "library_test.go", `import "github.com/onsi/ginkgo/v2"`, 0666)62 //ginkgo tests in a deeply nested directory63 writeFile("/colonelmustard/library/spanner", "spanner_test.go", `import "github.com/onsi/ginkgo/v2/dsl/core"`, 0666)64 //ginkgo tests deeply nested in a vendored dependency65 writeFile("/vendor/mrspeacock/lounge", "lounge_test.go", `import "github.com/onsi/ginkgo/v2"`, 0666)66 //a precompiled ginkgo test67 writeFile("/precompiled-dir", "precompiled.test", `fake-binary-file`, 0777)68 writeFile("/precompiled-dir", "some-other-binary", `fake-binary-file`, 0777)69 writeFile("/precompiled-dir", "windows.test.exe", `fake-binary-file`, 0666)70 writeFile("/precompiled-dir", "windows.exe", `fake-binary-file`, 0666)71 writeFile("/precompiled-dir", "nonexecutable.test", `fake-binary-file`, 0666)72 })73 AfterEach(func() {74 Ω(os.Chdir(origWd)).Should(Succeed())75 os.RemoveAll(tmpDir)76 })77 Context("when passed no args", func() {78 Context("when told to recurse", func() {79 BeforeEach(func() {80 cliConf.Recurse = true81 })82 It("recurses through the current directory, returning all identified tests and skipping vendored, ignored, and precompiled tests", func() {83 suites := FindSuites([]string{}, cliConf, false)84 Ω(suites).Should(ConsistOf(85 TS("./professorplum", "professorplum", false, TestSuiteStateUncompiled),86 TS("./colonelmustard", "colonelmustard", true, TestSuiteStateUncompiled),87 TS("./colonelmustard/library", "library", true, TestSuiteStateUncompiled),88 TS("./colonelmustard/library/spanner", "spanner", true, TestSuiteStateUncompiled),89 ))90 })91 })92 Context("when told to recurse and there is a skip-package filter", func() {93 BeforeEach(func() {94 cliConf.Recurse = true95 cliConf.SkipPackage = "professorplum,library,floop"96 })97 It("recurses through the current directory, returning all identified tests and skipping vendored, ignored, and precompiled tests", func() {98 suites := FindSuites([]string{}, cliConf, false)99 Ω(suites).Should(ConsistOf(100 TS("./professorplum", "professorplum", false, TestSuiteStateSkippedByFilter),101 TS("./colonelmustard", "colonelmustard", true, TestSuiteStateUncompiled),102 TS("./colonelmustard/library", "library", true, TestSuiteStateSkippedByFilter),103 TS("./colonelmustard/library/spanner", "spanner", true, TestSuiteStateSkippedByFilter),104 ))105 })106 })107 Context("when there are no tests in the current directory", func() {108 BeforeEach(func() {109 cliConf.Recurse = false110 })111 It("returns empty", func() {112 suites := FindSuites([]string{}, cliConf, false)113 Ω(suites).Should(BeEmpty())114 })115 })116 Context("when told not to recurse", func() {117 BeforeEach(func() {118 Ω(os.Chdir("./colonelmustard")).Should(Succeed())119 })120 It("returns tests in the current directory if present", func() {121 suites := FindSuites([]string{}, cliConf, false)122 Ω(suites).Should(ConsistOf(123 TS(".", "colonelmustard", true, TestSuiteStateUncompiled),124 ))125 })126 })127 })128 Context("when passed args", func() {129 Context("when told to recurse", func() {130 BeforeEach(func() {131 cliConf.Recurse = true132 })133 It("recurses through the passed-in directories, returning all identified tests and skipping vendored, ignored, and precompiled tests", func() {134 suites := FindSuites([]string{"precompiled-dir", "colonelmustard"}, cliConf, false)135 Ω(suites).Should(ConsistOf(136 TS("./colonelmustard", "colonelmustard", true, TestSuiteStateUncompiled),137 TS("./colonelmustard/library", "library", true, TestSuiteStateUncompiled),138 TS("./colonelmustard/library/spanner", "spanner", true, TestSuiteStateUncompiled),139 ))140 })141 })142 Context("when told to recurse and there is a skip-package filter", func() {143 BeforeEach(func() {144 cliConf.Recurse = true145 cliConf.SkipPackage = "library"146 })147 It("recurses through the passed-in directories, returning all identified tests and skipping vendored, ignored, and precompiled tests", func() {148 suites := FindSuites([]string{"precompiled-dir", "professorplum", "colonelmustard"}, cliConf, false)149 Ω(suites).Should(ConsistOf(150 TS("./professorplum", "professorplum", false, TestSuiteStateUncompiled),151 TS("./colonelmustard", "colonelmustard", true, TestSuiteStateUncompiled),152 TS("./colonelmustard/library", "library", true, TestSuiteStateSkippedByFilter),153 TS("./colonelmustard/library/spanner", "spanner", true, TestSuiteStateSkippedByFilter),154 ))155 })156 })157 Context("when told not to recurse", func() {158 BeforeEach(func() {159 cliConf.Recurse = false160 })161 It("returns test packages at the passed in arguments", func() {162 suites := FindSuites([]string{"precompiled-dir", "colonelmustard", "professorplum", "ignored"}, cliConf, false)163 Ω(suites).Should(ConsistOf(164 TS("./professorplum", "professorplum", false, TestSuiteStateUncompiled),165 TS("./colonelmustard", "colonelmustard", true, TestSuiteStateUncompiled),166 ))167 })168 })169 Context("when told not to recurse, but an arg has /...", func() {170 BeforeEach(func() {171 cliConf.Recurse = false172 })173 It("recurses through the directories it is told to recurse through, returning all identified tests and skipping vendored, ignored, and precompiled tests", func() {174 suites := FindSuites([]string{"precompiled-dir", "colonelmustard/...", "professorplum/...", "ignored/..."}, cliConf, false)175 Ω(suites).Should(ConsistOf(176 TS("./professorplum", "professorplum", false, TestSuiteStateUncompiled),177 TS("./colonelmustard", "colonelmustard", true, TestSuiteStateUncompiled),178 TS("./colonelmustard/library", "library", true, TestSuiteStateUncompiled),179 TS("./colonelmustard/library/spanner", "spanner", true, TestSuiteStateUncompiled),180 ))181 })182 })183 Context("when told not to recurse and there is a skip-package filter", func() {184 BeforeEach(func() {185 cliConf.Recurse = false186 cliConf.SkipPackage = "library,plum"187 })188 It("returns skips packages that match", func() {189 suites := FindSuites([]string{"colonelmustard", "professorplum", "colonelmustard/library"}, cliConf, false)190 Ω(suites).Should(ConsistOf(191 TS("./professorplum", "professorplum", false, TestSuiteStateSkippedByFilter),192 TS("./colonelmustard", "colonelmustard", true, TestSuiteStateUncompiled),193 TS("./colonelmustard/library", "library", true, TestSuiteStateSkippedByFilter),194 ))195 })196 })197 Context("when pointed at a directory containing a precompiled test suite", func() {198 It("returns nothing", func() {199 suites := FindSuites([]string{"precompiled-dir"}, cliConf, false)200 Ω(suites).Should(BeEmpty())201 })202 })203 Context("when pointed at a precompiled test suite specifically", func() {204 It("returns the precompiled suite", func() {205 path, err := filepath.Abs("./precompiled-dir/precompiled.test")206 Ω(err).ShouldNot(HaveOccurred())207 suites := FindSuites([]string{"precompiled-dir/precompiled.test"}, cliConf, true)208 Ω(suites).Should(ConsistOf(209 PTS("./precompiled-dir", "precompiled", true, path, TestSuiteStateCompiled),210 ))211 })212 })213 Context("when pointed at a precompiled test suite on windows", func() {214 It("returns the precompiled suite", func() {215 path, err := filepath.Abs("./precompiled-dir/windows.exe")216 Ω(err).ShouldNot(HaveOccurred())217 suites := FindSuites([]string{"precompiled-dir/windows.exe"}, cliConf, true)218 Ω(suites).Should(ConsistOf(219 PTS("./precompiled-dir", "windows", true, path, TestSuiteStateCompiled),220 ))221 path, err = filepath.Abs("./precompiled-dir/windows.test.exe")222 Ω(err).ShouldNot(HaveOccurred())223 suites = FindSuites([]string{"precompiled-dir/windows.test.exe"}, cliConf, true)224 Ω(suites).Should(ConsistOf(225 PTS("./precompiled-dir", "windows", true, path, TestSuiteStateCompiled),226 ))227 })228 })229 Context("when pointed at a fake precompiled test", func() {230 It("returns nothing", func() {231 suites := FindSuites([]string{"precompiled-dir/some-other-binary"}, cliConf, true)232 Ω(suites).Should(BeEmpty())233 suites = FindSuites([]string{"precompiled-dir/nonexecutable.test"}, cliConf, true)234 Ω(suites).Should(BeEmpty())235 })236 })237 Context("when pointed at a precompiled test suite specifically but allowPrecompiled is false", func() {238 It("returns nothing", func() {239 suites := FindSuites([]string{"precompiled-dir/some-other-binary"}, cliConf, false)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Ginkgo automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful