How to use Not method of gomock Package

Best Mock code snippet using gomock.Not

supply_test.go

Source:supply_test.go Github

copy

Full Screen

...174 })175 It("creates runtime.txt from Pipfile.lock contents if none exists", func() {176 Expect(supplier.HandlePipfile()).To(Succeed())177 runtimeContents, err := ioutil.ReadFile(filepath.Join(depDir, "runtime.txt"))178 Expect(err).ToNot(HaveOccurred())179 Expect(string(runtimeContents)).To(ContainSubstring("python-3.6"))180 })181 })182 Describe("InstallPipPop", func() {183 It("installs pip-pop", func() {184 mockInstaller.EXPECT().InstallOnlyVersion("pip-pop", "/tmp/pip-pop")185 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "pip-pop", "--exists-action=w", "--no-index", "--find-links=/tmp/pip-pop")186 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(filepath.Join(depDir, "python"), "bin"), "bin")187 Expect(supplier.InstallPipPop()).To(Succeed())188 })189 })190 // Add the expects for what the installFfi function uses191 expectInstallFfi := func() string {192 ffiDir := filepath.Join(depDir, "libffi")193 mockManifest.EXPECT().AllDependencyVersions("libffi").Return([]string{"1.2.3"})194 mockInstaller.EXPECT().InstallOnlyVersion("libffi", ffiDir)195 mockStager.EXPECT().WriteEnvFile("LIBFFI", ffiDir)196 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(ffiDir, "lib"), "lib")197 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(ffiDir, "lib", "pkgconfig"), "pkgconfig")198 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(ffiDir, "lib", "libffi-1.2.3", "include"), "include")199 return ffiDir200 }201 // Add the expects for functions used to install pipenv202 // returns ffidir for convenience203 expectInstallPipEnv := func() string {204 // install pipenv binary from bp manifest205 mockInstaller.EXPECT().InstallOnlyVersion("pipenv", "/tmp/pipenv")206 // install pipenv dependencies207 ffiDir := expectInstallFfi()208 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "setuptools_scm", "--exists-action=w", "--no-index", "--find-links=/tmp/pipenv")209 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "pytest-runner", "--exists-action=w", "--no-index", "--find-links=/tmp/pipenv")210 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "parver", "--exists-action=w", "--no-index", "--find-links=/tmp/pipenv")211 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "invoke", "--exists-action=w", "--no-index", "--find-links=/tmp/pipenv")212 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "pipenv", "--exists-action=w", "--no-index", "--find-links=/tmp/pipenv")213 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "wheel", "--exists-action=w", "--no-index", "--find-links=/tmp/pipenv")214 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(filepath.Join(depDir, "python"), "bin"), "bin")215 return ffiDir216 }217 Describe("InstallPipEnv", func() {218 BeforeEach(func() {219 Expect(os.MkdirAll(depDir, 0755)).To(Succeed())220 })221 Context("when Pipfile.lock and requirements.txt both exist", func() {222 BeforeEach(func() {223 Expect(ioutil.WriteFile(filepath.Join(buildDir, "Pipfile.lock"), []byte("This is pipfile"), 0644)).To(Succeed())224 Expect(ioutil.WriteFile(filepath.Join(buildDir, "requirements.txt"), []byte("blah"), 0644)).To(Succeed())225 })226 It("does not install Pipenv", func() {227 Expect(supplier.InstallPipEnv()).To(Succeed())228 })229 })230 Context("when Pipfile.lock exists but requirements.txt does not exist", func() {231 BeforeEach(func() {232 const lockFileContnet string = `{"_meta":{"sources":[{"url":"https://pypi.org/simple"},{"url":"https://pypi.example.org/simple"}]},"default":{"test":{"version":"==1.2.3"}}}`233 Expect(ioutil.WriteFile(filepath.Join(buildDir, "Pipfile"), []byte("some content"), 0644)).To(Succeed())234 Expect(ioutil.WriteFile(filepath.Join(buildDir, "Pipfile.lock"), []byte(lockFileContnet), 0644)).To(Succeed())235 })236 It("manually generates the requirements.txt", func() {237 Expect(supplier.InstallPipEnv()).To(Succeed())238 requirementsContents, err := ioutil.ReadFile(filepath.Join(buildDir, "requirements.txt"))239 Expect(err).ToNot(HaveOccurred())240 Expect(requirementsContents).To(ContainSubstring("-i https://pypi.org/simple"))241 Expect(requirementsContents).To(ContainSubstring("--extra-index-url https://pypi.example.org/simple"))242 Expect(requirementsContents).To(ContainSubstring("test==1.2.3"))243 })244 })245 Context("when Pipfile exists but requirements.txt and Pipfile.lock do not exist", func() {246 BeforeEach(func() {247 Expect(ioutil.WriteFile(filepath.Join(buildDir, "Pipfile"), []byte("some content"), 0644)).To(Succeed())248 })249 It("manually generates the requirements.txt", func() {250 expectInstallPipEnv()251 mockCommand.EXPECT().RunWithOutput(gomock.Any()).Return([]byte("Using /tmp/deps/0/bin/python3.6m to create virtualenv…\nline 1\nline 2\n"), nil)252 Expect(supplier.InstallPipEnv()).To(Succeed())253 requirementsContents, err := ioutil.ReadFile(filepath.Join(buildDir, "requirements.txt"))254 Expect(err).ToNot(HaveOccurred())255 By("removes extraneous pipenv lock output")256 Expect(string(requirementsContents)).To(Equal("line 1\nline 2\n"))257 })258 })259 })260 Describe("HandlePylibmc", func() {261 AfterEach(func() {262 os.Setenv("LIBMEMCACHED", "")263 })264 Context("when the app uses pylibmc", func() {265 BeforeEach(func() {266 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "pip-grep", "-s", "requirements.txt", "pylibmc").Return(nil)267 })268 It("installs libmemcache", func() {269 memcachedDir := filepath.Join(depDir, "libmemcache")270 mockInstaller.EXPECT().InstallOnlyVersion("libmemcache", memcachedDir)271 mockStager.EXPECT().WriteEnvFile("LIBMEMCACHED", memcachedDir)272 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(memcachedDir, "lib"), "lib")273 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(memcachedDir, "lib", "sasl2"), "lib")274 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(memcachedDir, "lib", "pkgconfig"), "pkgconfig")275 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(memcachedDir, "include"), "include")276 Expect(supplier.HandlePylibmc()).To(Succeed())277 Expect(os.Getenv("LIBMEMCACHED")).To(Equal(memcachedDir))278 })279 })280 Context("when the app does not use pylibmc", func() {281 BeforeEach(func() {282 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "pip-grep", "-s", "requirements.txt", "pylibmc").Return(fmt.Errorf("not found"))283 })284 It("does not install libmemcache", func() {285 Expect(supplier.HandlePylibmc()).To(Succeed())286 Expect(os.Getenv("LIBMEMCACHED")).To(Equal(""))287 })288 })289 })290 Describe("CopyRuntimeTxt", func() {291 BeforeEach(func() {292 Expect(os.MkdirAll(depDir, 0755)).To(Succeed())293 })294 It("succeeds without requirements.txt and runtime.txt in build dir", func() {295 Expect(supplier.CopyRuntimeTxt()).To(Succeed())296 })297 Context("requirements.txt and runtime.txt in build dir", func() {298 BeforeEach(func() {299 Expect(ioutil.WriteFile(filepath.Join(buildDir, "runtime.txt"), []byte("blah blah"), 0644)).To(Succeed())300 })301 It("copies requirements.txt and runtime.txt", func() {302 Expect(supplier.CopyRuntimeTxt()).To(Succeed())303 fileContents, err := ioutil.ReadFile(filepath.Join(depDir, "runtime.txt"))304 Expect(err).ToNot(HaveOccurred())305 Expect(fileContents).To(Equal([]byte("blah blah")))306 })307 })308 })309 Describe("HandleRequirementstxt", func() {310 BeforeEach(func() {311 Expect(os.MkdirAll(depDir, 0755)).To(Succeed())312 })313 Context("when requirements.txt does not exist", func() {314 Context("when setup.py exists", func() {315 BeforeEach(func() {316 Expect(ioutil.WriteFile(filepath.Join(buildDir, "setup.py"), []byte{}, 0644)).To(Succeed())317 })318 It("create requirements.txt with '-e .'", func() {319 Expect(supplier.HandleRequirementstxt()).To(Succeed())320 Expect(filepath.Join(buildDir, "requirements.txt")).To(BeARegularFile())321 fileContents, err := ioutil.ReadFile(filepath.Join(buildDir, "requirements.txt"))322 Expect(err).ToNot(HaveOccurred())323 Expect(fileContents).To(Equal([]byte("-e .")))324 })325 })326 Context("when setup.py does not exist", func() {327 It("does not create requirements.txt file", func() {328 Expect(supplier.HandleRequirementstxt()).To(Succeed())329 Expect(filepath.Join(buildDir, "requirements.txt")).ToNot(BeARegularFile())330 })331 })332 })333 Context("when requirements.txt exists", func() {334 BeforeEach(func() {335 Expect(ioutil.WriteFile(filepath.Join(buildDir, "requirements.txt"), []byte("blah"), 0644)).To(Succeed())336 })337 It("does nothing", func() {338 Expect(supplier.HandleRequirementstxt()).To(Succeed())339 fileContents, err := ioutil.ReadFile(filepath.Join(buildDir, "requirements.txt"))340 Expect(err).ToNot(HaveOccurred())341 Expect(fileContents).To(Equal([]byte("blah")))342 })343 })344 })345 Describe("HandleFfi", func() {346 AfterEach(func() {347 os.Setenv("LIBFFI", "")348 })349 Context("when the app uses ffi", func() {350 BeforeEach(func() {351 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "pip-grep", "-s", "requirements.txt", "pymysql", "argon2-cffi", "bcrypt", "cffi", "cryptography", "django[argon2]", "Django[argon2]", "django[bcrypt]", "Django[bcrypt]", "PyNaCl", "pyOpenSSL", "PyOpenSSL", "requests[security]", "misaka").Return(nil)352 })353 It("installs ffi", func() {354 ffiDir := expectInstallFfi()355 Expect(supplier.HandleFfi()).To(Succeed())356 Expect(os.Getenv("LIBFFI")).To(Equal(ffiDir))357 })358 Context("when pipenv is installed", func() {359 var ffiDir string360 BeforeEach(func() {361 // expect pipenv to be installed, and for it to install ffi362 Expect(os.MkdirAll(depDir, 0755)).To(Succeed())363 Expect(ioutil.WriteFile(filepath.Join(buildDir, "Pipfile"), []byte("This is pipfile"), 0644)).To(Succeed())364 ffiDir = expectInstallPipEnv()365 mockCommand.EXPECT().RunWithOutput(gomock.Any()).Return([]byte("test"), nil)366 // install pipenv367 Expect(supplier.InstallPipEnv()).To(Succeed())368 })369 It("it doesn't install ffi a second time", func() {370 Expect(supplier.HandleFfi()).To(Succeed())371 Expect(os.Getenv("LIBFFI")).To(Equal(ffiDir))372 })373 })374 })375 Context("when the app does not use libffi", func() {376 BeforeEach(func() {377 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "pip-grep", "-s", "requirements.txt", "pymysql", "argon2-cffi", "bcrypt", "cffi", "cryptography", "django[argon2]", "Django[argon2]", "django[bcrypt]", "Django[bcrypt]", "PyNaCl", "pyOpenSSL", "PyOpenSSL", "requests[security]", "misaka").Return(fmt.Errorf("not found"))378 })379 It("does not install libffi", func() {380 Expect(supplier.HandleFfi()).To(Succeed())381 Expect(os.Getenv("LIBFFI")).To(Equal(""))382 })383 })384 })385 Describe("HandleMercurial", func() {386 Context("has mercurial dependencies", func() {387 BeforeEach(func() {388 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "grep", "-Fiq", "hg+", "requirements.txt")389 })390 Context("the buildpack is not cached", func() {391 BeforeEach(func() {392 mockManifest.EXPECT().IsCached().Return(false)393 })394 It("installs mercurial", func() {395 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "mercurial")396 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(depDir, "python", "bin"), "bin")397 Expect(supplier.HandleMercurial()).To(Succeed())398 })399 })400 Context("the buildpack is cached", func() {401 BeforeEach(func() {402 mockManifest.EXPECT().IsCached().Return(true)403 })404 It("installs mercurial and provides a warning", func() {405 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "mercurial")406 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(depDir, "python", "bin"), "bin")407 Expect(supplier.HandleMercurial()).To(Succeed())408 Expect(buffer.String()).To(ContainSubstring("Cloud Foundry does not support Pip Mercurial dependencies while in offline-mode. Vendor your dependencies if they do not work."))409 })410 })411 })412 Context("does not have mercurial dependencies", func() {413 BeforeEach(func() {414 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "grep", "-Fiq", "hg+", "requirements.txt").Return(fmt.Errorf("Mercurial not found"))415 })416 It("succeeds without installing mercurial", func() {417 Expect(supplier.HandleMercurial()).To(Succeed())418 })419 })420 })421 Describe("RewriteShebangs", func() {422 BeforeEach(func() {423 Expect(os.MkdirAll(filepath.Join(depDir, "bin"), 0755)).To(Succeed())424 Expect(ioutil.WriteFile(filepath.Join(depDir, "bin", "somescript"), []byte("#!/usr/bin/python\n\n\n"), 0755)).To(Succeed())425 Expect(ioutil.WriteFile(filepath.Join(depDir, "bin", "anotherscript"), []byte("#!//bin/python\n\n\n"), 0755)).To(Succeed())426 Expect(os.MkdirAll(filepath.Join(depDir, "bin", "__pycache__"), 0755)).To(Succeed())427 Expect(os.Symlink(filepath.Join(depDir, "bin", "__pycache__"), filepath.Join(depDir, "bin", "__pycache__SYMLINK"))).To(Succeed())428 })429 It("changes them to #!/usr/bin/env python", func() {430 Expect(supplier.RewriteShebangs()).To(Succeed())431 fileContents, err := ioutil.ReadFile(filepath.Join(depDir, "bin", "somescript"))432 Expect(err).ToNot(HaveOccurred())433 secondFileContents, err := ioutil.ReadFile(filepath.Join(depDir, "bin", "anotherscript"))434 Expect(err).ToNot(HaveOccurred())435 Expect(string(fileContents)).To(HavePrefix("#!/usr/bin/env python"))436 Expect(string(secondFileContents)).To(HavePrefix("#!/usr/bin/env python"))437 })438 })439 Describe("UninstallUnusedDependencies", func() {440 Context("when requirements-declared.txt exists", func() {441 requirementsDeclared :=442 `Flask==0.10.1443Jinja2==2.7.2444MarkupSafe==0.21445Werkzeug==0.10.4446gunicorn==19.3.0447itsdangerous==0.24448pylibmc==1.4.2449cffi==0.9.2450`451 requirements :=452 `Flask==0.10.1453Jinja2==2.7.2454MarkupSafe==0.21455`456 requirementsStale :=457 `Werkzeug==0.10.4458gunicorn==19.3.0459itsdangerous==0.24460pylibmc==1.4.2461cffi==0.9.2462`463 BeforeEach(func() {464 Expect(os.MkdirAll(filepath.Join(depDir, "python"), 0755)).To(Succeed())465 Expect(ioutil.WriteFile(filepath.Join(depDir, "python", "requirements-declared.txt"), []byte(requirementsDeclared), 0644)).To(Succeed())466 Expect(ioutil.WriteFile(filepath.Join(buildDir, "requirements.txt"), []byte(requirements), 0644)).To(Succeed())467 })468 It("creates requirements-stale.txt and uninstalls unused dependencies", func() {469 mockCommand.EXPECT().Output(buildDir, "pip-diff", "--stale", filepath.Join(depDir, "python", "requirements-declared.txt"), filepath.Join(buildDir, "requirements.txt"), "--exclude", "setuptools", "pip", "wheel").Return(requirementsStale, nil)470 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "uninstall", "-r", filepath.Join(depDir, "python", "requirements-stale.txt", "-y", "--exists-action=w"))471 Expect(supplier.UninstallUnusedDependencies()).To(Succeed())472 fileContents, err := ioutil.ReadFile(filepath.Join(depDir, "python", "requirements-stale.txt"))473 Expect(err).ToNot(HaveOccurred())474 Expect(string(fileContents)).To(Equal(requirementsStale))475 })476 })477 Context("when requirements-declared.txt does not exist", func() {478 It("does nothing", func() {479 fileExists, err := libbuildpack.FileExists(filepath.Join(depDir, "python", "requirements-stale.txt"))480 Expect(err).ToNot(HaveOccurred())481 Expect(fileExists).To(Equal(false))482 Expect(supplier.UninstallUnusedDependencies()).To(Succeed())483 })484 })485 })486 Describe("RunPipUnvendored", func() {487 BeforeEach(func() {488 Expect(os.MkdirAll(depDir, 0755)).To(Succeed())489 })490 Context("requirements.txt exists in dep dir", func() {491 BeforeEach(func() {492 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(depDir, "python", "bin"), "bin")493 Expect(ioutil.WriteFile(filepath.Join(buildDir, "requirements.txt"), []byte{}, 0644)).To(Succeed())494 })495 It("Runs and outputs pip", func() {496 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "-r", filepath.Join(buildDir, "requirements.txt"), "--ignore-installed", "--exists-action=w", fmt.Sprintf("--src=%s/src", depDir), "--disable-pip-version-check")497 Expect(supplier.RunPipUnvendored()).To(Succeed())498 })499 })500 Context("requirements.txt exists in dep dir and pip install fails", func() {501 BeforeEach(func() {502 Expect(ioutil.WriteFile(filepath.Join(buildDir, "requirements.txt"), []byte{}, 0644)).To(Succeed())503 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "-r", filepath.Join(buildDir, "requirements.txt"), "--ignore-installed", "--exists-action=w", fmt.Sprintf("--src=%s/src", depDir), "--disable-pip-version-check").Return(fmt.Errorf("exit 28"))504 })505 const proTip = "Running pip install failed. You need to include all dependencies in the vendor directory."506 It("does NOT alert the user", func() {507 Expect(supplier.RunPipUnvendored()).To(MatchError(fmt.Errorf("could not run pip: exit 28")))508 Expect(buffer.String()).ToNot(ContainSubstring(proTip))509 })510 })511 Context("requirements.txt is NOT in dep dir", func() {512 It("exits early", func() {513 Expect(supplier.RunPipUnvendored()).To(Succeed())514 })515 })516 Context("have index_url, find_links, allow_hosts exists in pydistutils.cfg file", func() {517 requirements :=518 `--index-url https://index-url519--extra-index-url https://extra-index-url1520--extra-index-url https://extra-index-url2521--trusted-host extra-index-url1522--trusted-host extra-index-url2523Flask==0.10.1524Jinja2==2.7.2525MarkupSafe==0.21526`527 BeforeEach(func() {528 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(depDir, "python", "bin"), "bin")529 Expect(ioutil.WriteFile(filepath.Join(buildDir, "requirements.txt"), []byte(requirements), 0644)).To(Succeed())530 })531 It("check index_url, find_links, allow_hosts values", func() {532 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "-r", filepath.Join(buildDir, "requirements.txt"), "--ignore-installed", "--exists-action=w", fmt.Sprintf("--src=%s/src", depDir), "--disable-pip-version-check")533 Expect(supplier.RunPipUnvendored()).To(Succeed())534 filePath := filepath.Join(os.Getenv("HOME"), ".pydistutils.cfg")535 fileContents, err := ioutil.ReadFile(filePath)536 Expect(err).ShouldNot(HaveOccurred())537 configMap, err := ParsePydistutils(string(fileContents))538 Expect(err).ToNot(HaveOccurred())539 Expect(configMap).Should(HaveKeyWithValue("index_url", []string{"https://index-url"}))540 // find_links is array of string541 Expect(configMap).Should(HaveKeyWithValue("find_links", []string{"https://extra-index-url1", "https://extra-index-url2"}))542 // allow_hosts is comma separated string543 Expect(configMap).Should(HaveKeyWithValue("allow_hosts", []string{"extra-index-url1,extra-index-url2"}))544 })545 })546 })547 Describe("RunPipVendored", func() {548 BeforeEach(func() {549 Expect(os.MkdirAll(depDir, 0755)).To(Succeed())550 })551 Context("requirements.txt exists in dep dir", func() {552 BeforeEach(func() {553 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(depDir, "python", "bin"), "bin")554 Expect(ioutil.WriteFile(filepath.Join(buildDir, "requirements.txt"), []byte{}, 0644)).To(Succeed())555 Expect(os.Mkdir(filepath.Join(buildDir, "vendor"), 0755)).To(Succeed())556 })557 It("installs the vendor directory", func() {558 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "--no-build-isolation", "-h").Return(nil)559 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "-r", filepath.Join(buildDir, "requirements.txt"), "--ignore-installed", "--exists-action=w", fmt.Sprintf("--src=%s/src", depDir), "--no-index", fmt.Sprintf("--find-links=file://%s/vendor", buildDir), "--disable-pip-version-check", "--no-build-isolation")560 Expect(supplier.RunPipVendored()).To(Succeed())561 })562 })563 Context("requirements.txt exists in dep dir and pip install fails", func() {564 BeforeEach(func() {565 Expect(ioutil.WriteFile(filepath.Join(buildDir, "requirements.txt"), []byte{}, 0644)).To(Succeed())566 Expect(os.Mkdir(filepath.Join(buildDir, "vendor"), 0755)).To(Succeed())567 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "--no-build-isolation", "-h").Return(nil)568 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "-r", filepath.Join(buildDir, "requirements.txt"), "--ignore-installed", "--exists-action=w", fmt.Sprintf("--src=%s/src", depDir), "--no-index", fmt.Sprintf("--find-links=file://%s/vendor", buildDir), "--disable-pip-version-check", "--no-build-isolation").Return(fmt.Errorf("exit 28"))569 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "-r", filepath.Join(buildDir, "requirements.txt"), "--ignore-installed", "--exists-action=w", fmt.Sprintf("--src=%s/src", depDir), "--disable-pip-version-check").Return(fmt.Errorf("exit 28"))570 })571 const proTip = "Running pip install failed. You need to include all dependencies in the vendor directory."572 It("alerts the user", func() {573 Expect(supplier.RunPipVendored()).To(MatchError(fmt.Errorf("could not run pip: exit 28")))574 Expect(buffer.String()).To(ContainSubstring(proTip))575 })576 })577 Context("requirements.txt is NOT in dep dir", func() {578 It("exits early", func() {579 Expect(supplier.RunPipVendored()).To(Succeed())580 })581 })582 })583 Describe("CreateDefaultEnv", func() {584 It("writes an env file for PYTHONPATH", func() {585 mockStager.EXPECT().WriteEnvFile("PYTHONPATH", depDir)586 mockStager.EXPECT().WriteEnvFile("LIBRARY_PATH", filepath.Join(depDir, "lib"))587 mockStager.EXPECT().WriteEnvFile("PYTHONHASHSEED", "random")588 mockStager.EXPECT().WriteEnvFile("PYTHONUNBUFFERED", "1")589 mockStager.EXPECT().WriteEnvFile("LANG", "en_US.UTF-8")590 mockStager.EXPECT().WriteEnvFile("PYTHONHOME", filepath.Join(depDir, "python"))591 mockStager.EXPECT().WriteProfileD(gomock.Any(), gomock.Any())592 Expect(supplier.CreateDefaultEnv()).To(Succeed())593 })594 It("writes the profile.d", func() {595 mockStager.EXPECT().WriteEnvFile(gomock.Any(), gomock.Any()).AnyTimes()596 mockStager.EXPECT().WriteProfileD("python.sh", fmt.Sprintf(`export LANG=${LANG:-en_US.UTF-8}597export PYTHONHASHSEED=${PYTHONHASHSEED:-random}598export PYTHONPATH=$DEPS_DIR/%s599export PYTHONHOME=$DEPS_DIR/%s/python600export PYTHONUNBUFFERED=1601export FORWARDED_ALLOW_IPS='*'602export GUNICORN_CMD_ARGS=${GUNICORN_CMD_ARGS:-'--access-logfile -'}603`, depsIdx, depsIdx))604 Expect(supplier.CreateDefaultEnv()).To(Succeed())605 })606 Context("HasNltkData=true", func() {607 BeforeEach(func() {608 supplier.HasNltkData = true609 })610 It("writes an env file for NLTK_DATA", func() {611 mockStager.EXPECT().WriteEnvFile("NLTK_DATA", filepath.Join(depDir, "python", "nltk_data"))612 mockStager.EXPECT().WriteEnvFile(gomock.Any(), gomock.Any()).AnyTimes()613 mockStager.EXPECT().WriteProfileD(gomock.Any(), gomock.Any())614 Expect(supplier.CreateDefaultEnv()).To(Succeed())615 })616 It("writes the profile.d", func() {617 mockStager.EXPECT().WriteEnvFile(gomock.Any(), gomock.Any()).AnyTimes()618 mockStager.EXPECT().WriteProfileD("python.sh", gomock.Any()).Do(func(_, actual string) {619 expected := fmt.Sprintf("export NLTK_DATA=$DEPS_DIR/%s/python/nltk_data", depsIdx)620 Expect(actual).To(ContainSubstring(expected))621 })622 Expect(supplier.CreateDefaultEnv()).To(Succeed())623 })624 })625 })626 Describe("DownloadNLTKCorpora", func() {627 Context("NLTK not installed", func() {628 BeforeEach(func() {629 mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), "python", "-m", "nltk.downloader", "-h").Return(errors.New(""))630 })631 It("should not do anything", func() {632 Expect(supplier.DownloadNLTKCorpora()).To(Succeed())633 Expect(buffer.String()).To(Equal(""))634 })635 })636 Context("NLTK installed", func() {637 BeforeEach(func() {638 mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), "python", "-m", "nltk.downloader", "-h").Return(nil)639 })640 It("logs downloading", func() {641 Expect(supplier.DownloadNLTKCorpora()).To(Succeed())642 Expect(buffer.String()).To(ContainSubstring("Downloading NLTK corpora"))643 Expect(supplier.HasNltkData).To(BeFalse())644 })645 Context("nltk.txt is not in app", func() {646 BeforeEach(func() {647 Expect(filepath.Join(buildDir, "nltk.txt")).ToNot(BeARegularFile())648 })649 It("warns the user", func() {650 Expect(supplier.DownloadNLTKCorpora()).To(Succeed())651 Expect(buffer.String()).To(ContainSubstring("nltk.txt not found, not downloading any corpora"))652 Expect(supplier.HasNltkData).To(BeFalse())653 })654 })655 Context("nltk.txt exists in app", func() {656 BeforeEach(func() {657 Expect(ioutil.WriteFile(filepath.Join(buildDir, "nltk.txt"), []byte("brown\nred\n"), 0644)).To(Succeed())658 })659 It("downloads nltk", func() {660 mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), "python", "-m", "nltk.downloader", "-d", filepath.Join(depDir, "python", "nltk_data"), "brown", "red").Return(nil)661 Expect(supplier.DownloadNLTKCorpora()).To(Succeed())...

Full Screen

Full Screen

transfer_test.go

Source:transfer_test.go Github

copy

Full Screen

...49 require.Equal(t, http.StatusOK, recorder.Code)50 },51 },52 {53 name: "FromAccountNotFound",54 body: gin.H{55 "from_account_id": account1.ID,56 "to_account_id": account2.ID,57 "amount": amount,58 "currency": util.USD,59 },60 buildStubs: func(store *mockdb.MockStore) {61 store.EXPECT().GetAccount(gomock.Any(), gomock.Eq(account1.ID)).Times(1).Return(db.Account{}, sql.ErrNoRows)62 store.EXPECT().GetAccount(gomock.Any(), gomock.Eq(account2.ID)).Times(0)63 store.EXPECT().TransferTx(gomock.Any(), gomock.Any()).Times(0)64 },65 checkResponse: func(recorder *httptest.ResponseRecorder) {66 require.Equal(t, http.StatusNotFound, recorder.Code)67 },68 },69 {70 name: "ToAccountNotFound",71 body: gin.H{72 "from_account_id": account1.ID,73 "to_account_id": account2.ID,74 "amount": amount,75 "currency": util.USD,76 },77 buildStubs: func(store *mockdb.MockStore) {78 store.EXPECT().GetAccount(gomock.Any(), gomock.Eq(account1.ID)).Times(1).Return(account1, nil)79 store.EXPECT().GetAccount(gomock.Any(), gomock.Eq(account2.ID)).Times(1).Return(db.Account{}, sql.ErrNoRows)80 store.EXPECT().TransferTx(gomock.Any(), gomock.Any()).Times(0)81 },82 checkResponse: func(recorder *httptest.ResponseRecorder) {83 require.Equal(t, http.StatusNotFound, recorder.Code)84 },85 },86 {87 name: "FromAccountCurrencyMismatch",88 body: gin.H{89 "from_account_id": account3.ID,90 "to_account_id": account2.ID,91 "amount": amount,92 "currency": util.USD,93 },94 buildStubs: func(store *mockdb.MockStore) {95 store.EXPECT().GetAccount(gomock.Any(), gomock.Eq(account3.ID)).Times(1).Return(account3, nil)96 store.EXPECT().GetAccount(gomock.Any(), gomock.Eq(account2.ID)).Times(0)97 store.EXPECT().TransferTx(gomock.Any(), gomock.Any()).Times(0)...

Full Screen

Full Screen

controller_handle_group_entry_test.go

Source:controller_handle_group_entry_test.go Github

copy

Full Screen

...36 client.EXPECT().GetInstalledFeaturePatchBase(gomock.Any()).Return(k8sclient.MergeFrom(ift))37 client.EXPECT().PatchInstalledFeatureStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)38 result, err := sut.Reconcile(iftReconcileRequest)39 Expect(result).Should(Equal(successResult))40 Expect(err).ToNot(HaveOccurred())41 })42 It("should add the status entry on the IFTG when the IFTG has already features", func() {43 ift := createIFT(name, namespace, version, provider, description, uri, true, false)44 setGroupToIFT(ift, group, namespace)45 iftg := createIFTG(group, namespace, provider, description, uri, true, false)46 iftg.Status.Features = make([]InstalledFeatureGroupListedFeature, 1)47 iftg.Status.Features[0] = InstalledFeatureGroupListedFeature{48 Namespace: namespace,49 Name: "other-feature",50 }51 client.EXPECT().LoadInstalledFeature(gomock.Any(), iftLookupKey).Return(ift, nil)52 client.EXPECT().LoadInstalledFeatureGroup(gomock.Any(), iftgLookupKey).Return(iftg, nil)53 client.EXPECT().GetInstalledFeatureGroupPatchBase(gomock.Any()).Return(k8sclient.MergeFrom(iftg))54 client.EXPECT().PatchInstalledFeatureGroupStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)55 client.EXPECT().GetInstalledFeaturePatchBase(gomock.Any()).Return(k8sclient.MergeFrom(ift))56 client.EXPECT().PatchInstalledFeatureStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)57 result, err := sut.Reconcile(iftReconcileRequest)58 Expect(result).Should(Equal(successResult))59 Expect(err).ToNot(HaveOccurred())60 })61 It("should not add the feature to the status entry on the IFTG when the IFTG already lists this feature", func() {62 ift := createIFT(name, namespace, version, provider, description, uri, true, false)63 setGroupToIFT(ift, group, namespace)64 iftg := createIFTG(group, namespace, provider, description, uri, true, false)65 iftg.Status.Features = make([]InstalledFeatureGroupListedFeature, 1)66 iftg.Status.Features[0] = InstalledFeatureGroupListedFeature{67 Namespace: namespace,68 Name: name,69 }70 client.EXPECT().LoadInstalledFeature(gomock.Any(), iftLookupKey).Return(ift, nil)71 client.EXPECT().LoadInstalledFeatureGroup(gomock.Any(), iftgLookupKey).Return(iftg, nil)72 client.EXPECT().GetInstalledFeatureGroupPatchBase(gomock.Any()).Return(k8sclient.MergeFrom(iftg))73 client.EXPECT().GetInstalledFeaturePatchBase(gomock.Any()).Return(k8sclient.MergeFrom(ift))74 client.EXPECT().PatchInstalledFeatureStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)75 result, err := sut.Reconcile(iftReconcileRequest)76 Expect(result).Should(Equal(successResult))77 Expect(err).ToNot(HaveOccurred())78 })79 It("should remove the status entry on the IFTG when IFT is deleted and is listed in IFTG", func() {80 ift := createIFT(name, namespace, version, provider, description, uri, false, true)81 setGroupToIFT(ift, group, namespace)82 iftg := createIFTG(group, namespace, provider, description, uri, true, false)83 iftg.Status.Features = make([]InstalledFeatureGroupListedFeature, 1)84 iftg.Status.Features[0] = InstalledFeatureGroupListedFeature{85 Namespace: namespace,86 Name: name,87 }88 client.EXPECT().LoadInstalledFeature(gomock.Any(), iftLookupKey).Return(ift, nil)89 client.EXPECT().LoadInstalledFeatureGroup(gomock.Any(), iftgLookupKey).Return(iftg, nil)90 client.EXPECT().GetInstalledFeatureGroupPatchBase(gomock.Any()).Return(k8sclient.MergeFrom(iftg))91 client.EXPECT().PatchInstalledFeatureGroupStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)92 client.EXPECT().GetInstalledFeaturePatchBase(gomock.Any()).Return(k8sclient.MergeFrom(ift))93 client.EXPECT().PatchInstalledFeatureStatus(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)94 result, err := sut.Reconcile(iftReconcileRequest)95 Expect(result).Should(Equal(successResult))96 Expect(err).ToNot(HaveOccurred())97 })98 It("should requeue the request when IFTG can't be loaded", func() {99 ift := createIFT(name, namespace, version, provider, description, uri, false, true)100 setGroupToIFT(ift, group, namespace)101 client.EXPECT().LoadInstalledFeature(gomock.Any(), iftLookupKey).Return(ift, nil)102 client.EXPECT().LoadInstalledFeatureGroup(gomock.Any(), iftgLookupKey).Return(nil, errors.New("can not load IFTG"))103 result, err := sut.Reconcile(iftReconcileRequest)104 Expect(result).Should(Equal(errorResult))105 Expect(err).Should(HaveOccurred())106 })107 })108})...

Full Screen

Full Screen

Not

Using AI Code Generation

copy

Full Screen

1func TestNot(t *testing.T) {2 ctrl := gomock.NewController(t)3 defer ctrl.Finish()4 mock := mock.NewMockInterface(ctrl)5 mock.EXPECT().Method(1).Return("Hello")6 mock.EXPECT().Method(2).Return("World")7 mock.EXPECT().Method(gomock.Not(1)).Return("GoMock")8 if mock.Method(1) != "Hello" {9 t.Error("Expected Hello")10 }11 if mock.Method(2) != "World" {12 t.Error("Expected World")13 }14 if mock.Method(3) != "GoMock" {15 t.Error("Expected GoMock")16 }17}18--- PASS: TestNot (0.00s)

Full Screen

Full Screen

Not

Using AI Code Generation

copy

Full Screen

1import (2func TestNot(t *testing.T) {3 ctrl := gomock.NewController(t)4 defer ctrl.Finish()5 mockObj := mock.NewMockInterface(ctrl)6 mockObj.EXPECT().Get(gomock.Not(gomock.Eq(5))).Return(10, nil)7 if val, err := mockObj.Get(6); err != nil || val != 10 {8 t.Errorf("unexpected result: %d, %v", val, err)9 }10}11import (12func TestAny(t *testing.T) {13 ctrl := gomock.NewController(t)14 defer ctrl.Finish()15 mockObj := mock.NewMockInterface(ctrl)16 mockObj.EXPECT().Get(gomock.Any()).Return(10, nil)17 if val, err := mockObj.Get(6); err != nil || val != 10 {18 t.Errorf("unexpected result: %d, %v", val, err)19 }20}21import (22func TestAnyTimes(t *testing.T) {23 ctrl := gomock.NewController(t)24 defer ctrl.Finish()25 mockObj := mock.NewMockInterface(ctrl)26 mockObj.EXPECT().Get(5).Return(10, nil).AnyTimes()

Full Screen

Full Screen

Not

Using AI Code Generation

copy

Full Screen

1import (2type MockInterface struct {3}4func (m *MockInterface) Not() {5 m.Called()6}7func TestNot(t *testing.T) {8 mockCtrl := gomock.NewController(t)9 defer mockCtrl.Finish()10 mockObj := &MockInterface{mockCtrl}11 mockObj.EXPECT().Not().Times(1)12 mockObj.Not()13}14import (15type MockInterface struct {16}17func (m *MockInterface) Not() {18 m.Called()19}20func TestNot(t *testing.T) {21 mockCtrl := gomock.NewController(t)22 defer mockCtrl.Finish()23 mockObj := &MockInterface{mockCtrl}24 mockObj.EXPECT().Not().Times(1)25 mockObj.Not()26}27import (28type MockInterface struct {29}30func (m *MockInterface) Not() {31 m.Called()32}33func TestNot(t *testing.T) {34 mockCtrl := gomock.NewController(t)35 defer mockCtrl.Finish()36 mockObj := &MockInterface{mockCtrl}37 mockObj.EXPECT().Not().Times(1)38 mockObj.Not()39}40import (41type MockInterface struct {42}43func (m *MockInterface) Not() {44 m.Called()45}46func TestNot(t *testing.T) {47 mockCtrl := gomock.NewController(t)48 defer mockCtrl.Finish()49 mockObj := &MockInterface{mockCtrl}50 mockObj.EXPECT().Not().Times(1)51 mockObj.Not()52}53import (54type MockInterface struct {55}56func (m *MockInterface) Not() {57 m.Called()58}59func TestNot(t *testing.T) {60 mockCtrl := gomock.NewController(t)61 defer mockCtrl.Finish()62 mockObj := &MockInterface{mockCtrl}63 mockObj.EXPECT().Not().Times(1)64 mockObj.Not()65}66import (

Full Screen

Full Screen

Not

Using AI Code Generation

copy

Full Screen

1import "testing"2import "github.com/golang/mock/gomock"3import "github.com/golang/mock/gomock/call"4import "github.com/rajeshpandey/gomocktest/mocks"5import "github.com/rajeshpandey/gomocktest"6func TestNot(t *testing.T) {7 mockCtrl := gomock.NewController(t)8 mock := mocks.NewMockIMyInterface(mockCtrl)9 call := gomock.Not(gomock.Eq("test"))10 mock.EXPECT().MyMethod(call).Return(nil)11 myStruct := gomocktest.NewMyStruct(mock)12 myStruct.MyMethod("test")13 mockCtrl.Finish()14}15--- PASS: TestNot (0.00s)

Full Screen

Full Screen

Not

Using AI Code Generation

copy

Full Screen

1import (2type Call interface {3 DoSomething() error4}5type TestStruct struct {6}7func (t *TestStruct) DoSomething() error {8 return t.Call.DoSomething()9}10func TestDoSomething(t *testing.T) {11 ctrl := gomock.NewController(t)12 defer ctrl.Finish()13 mockCall := NewMockCall(ctrl)14 mockCall.EXPECT().DoSomething().Return(nil)15 test := &TestStruct{Call: mockCall}16 err := test.DoSomething()17 if err != nil {18 fmt.Println(err)19 t.Fail()20 }21}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful