How to use All method of gomock Package

Best Mock code snippet using gomock.All

supply_test.go

Source:supply_test.go Github

copy

Full Screen

...60 }61 })62 AfterEach(func() {63 mockCtrl.Finish()64 err = os.RemoveAll(depsDir)65 Expect(err).To(BeNil())66 err = os.RemoveAll(buildDir)67 Expect(err).To(BeNil())68 })69 Describe("InstallPython", func() {70 var pythonInstallDir string71 var versions []string72 var originalPath string73 BeforeEach(func() {74 Expect(os.MkdirAll(depDir, 0755)).To(Succeed())75 pythonInstallDir = filepath.Join(depDir, "python")76 Expect(ioutil.WriteFile(filepath.Join(depDir, "runtime.txt"), []byte("\n\n\npython-3.4.2\n\n\n"), 0644)).To(Succeed())77 versions = []string{"3.4.2"}78 originalPath = os.Getenv("PATH")79 })80 AfterEach(func() {81 os.Setenv("PATH", originalPath)82 })83 Context("runtime.txt sets Python version 3", func() {84 It("installs Python version 3", func() {85 mockManifest.EXPECT().AllDependencyVersions("python").Return(versions)86 mockInstaller.EXPECT().InstallDependency(libbuildpack.Dependency{Name: "python", Version: "3.4.2"}, pythonInstallDir)87 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(pythonInstallDir, "bin"), "bin")88 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(pythonInstallDir, "lib"), "lib")89 Expect(supplier.InstallPython()).To(Succeed())90 Expect(os.Getenv("PATH")).To(Equal(fmt.Sprintf("%s:%s", filepath.Join(depDir, "bin"), originalPath)))91 Expect(os.Getenv("PYTHONPATH")).To(Equal(filepath.Join(depDir)))92 })93 })94 Context("no runtime.txt is provided", func() {95 BeforeEach(func() {96 Expect(os.RemoveAll(filepath.Join(depDir, "runtime.txt"))).To(Succeed())97 })98 It("installs the default Python version", func() {99 mockManifest.EXPECT().DefaultVersion("python").Return(libbuildpack.Dependency{Name: "python", Version: "some-default-version"}, nil)100 mockInstaller.EXPECT().InstallDependency(libbuildpack.Dependency{Name: "python", Version: "some-default-version"}, pythonInstallDir)101 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(pythonInstallDir, "bin"), "bin")102 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(pythonInstallDir, "lib"), "lib")103 Expect(supplier.InstallPython()).To(Succeed())104 Expect(os.Getenv("PATH")).To(Equal(fmt.Sprintf("%s:%s", filepath.Join(depDir, "bin"), originalPath)))105 Expect(os.Getenv("PYTHONPATH")).To(Equal(filepath.Join(depDir)))106 })107 })108 })109 Describe("InstallPip", func() {110 Describe("BP_PIP_VERSION not set", func() {111 BeforeEach(func() {112 Expect(os.Unsetenv("BP_PIP_VERSION")).To(Succeed())113 })114 It("skips install", func() {115 mockInstaller.EXPECT().InstallOnlyVersion(gomock.Any(), gomock.Any()).Times(0)116 mockCommand.EXPECT().Execute(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0)117 mockStager.EXPECT().LinkDirectoryInDepDir(gomock.Any(), gomock.Any()).Times(0)118 Expect(supplier.InstallPip()).To(Succeed())119 })120 It("uses python's pip module for installs", func() {121 Expect(ioutil.WriteFile(filepath.Join(buildDir, "requirements.txt"), []byte{}, 0644)).To(Succeed())122 mockStager.EXPECT().LinkDirectoryInDepDir(gomock.Any(), gomock.Any())123 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")124 Expect(supplier.RunPipUnvendored()).To(Succeed())125 })126 })127 Describe("BP_PIP_VERSION set to 'latest'", func() {128 BeforeEach(func() {129 Expect(os.Setenv("BP_PIP_VERSION", "latest")).To(Succeed())130 })131 AfterEach(func() {132 Expect(os.Unsetenv("BP_PIP_VERSION")).To(Succeed())133 })134 It("installs latest from manifest", func() {135 mockInstaller.EXPECT().InstallOnlyVersion("pip", "/tmp/pip")136 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "python", "-m", "pip", "install", "pip", "--exists-action=w", "--no-index", "--ignore-installed", "--find-links=/tmp/pip")137 mockStager.EXPECT().LinkDirectoryInDepDir(filepath.Join(filepath.Join(depDir, "python"), "bin"), "bin")138 Expect(supplier.InstallPip()).To(Succeed())139 })140 It("uses installed pip for installs", func() {141 Expect(ioutil.WriteFile(filepath.Join(buildDir, "requirements.txt"), []byte{}, 0644)).To(Succeed())142 mockStager.EXPECT().LinkDirectoryInDepDir(gomock.Any(), gomock.Any())143 mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "pip", "install", "-r", filepath.Join(buildDir, "requirements.txt"), "--ignore-installed", "--exists-action=w", fmt.Sprintf("--src=%s/src", depDir), "--disable-pip-version-check")144 Expect(supplier.RunPipUnvendored()).To(Succeed())145 })146 })147 Describe("BP_PIP_VERSION is invalid", func() {148 BeforeEach(func() {149 Expect(os.Setenv("BP_PIP_VERSION", "something-else")).To(Succeed())150 })151 AfterEach(func() {152 Expect(os.Unsetenv("BP_PIP_VERSION")).To(Succeed())153 })154 It("returns an error without installing", func() {155 mockInstaller.EXPECT().InstallOnlyVersion(gomock.Any(), gomock.Any()).Times(0)156 mockCommand.EXPECT().Execute(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0)157 mockStager.EXPECT().LinkDirectoryInDepDir(gomock.Any(), gomock.Any()).Times(0)158 Expect(supplier.InstallPip()).To(MatchError("invalid pip version: something-else"))159 })160 })161 })162 Describe("HandlePipfile", func() {163 BeforeEach(func() {164 Expect(os.MkdirAll(depDir, 0755)).To(Succeed())165 pipfileContents := `166 {167 "_meta":{168 "requires":{169 "python_version":"3.6"170 }171 }172 }`173 Expect(ioutil.WriteFile(filepath.Join(buildDir, "Pipfile.lock"), []byte(pipfileContents), 0644)).To(Succeed())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() {...

Full Screen

Full Screen

messages_handlers_test.go

Source:messages_handlers_test.go Github

copy

Full Screen

...16 "time"17)18// These test cases does not cover "Unauthorized" requests (i.e. requests without a proper session cookie)19// because authorization check is handled in Protected Middleware20func TestGetAllMessages(t *testing.T) {21 tests := []struct {22 Prepare func(getter *mocks.MockMessageGetter)23 ExpectedCode int24 ExpectedBody gin.H25 }{26 {27 Prepare: func(getter *mocks.MockMessageGetter) {28 getter.EXPECT().GetAllMessages(gomock.Any(), "johndoe").Return([]models.Message{29 {30 ID: primitive.ObjectID{},31 From: "iskralawrence",32 To: "aliparlakci",33 Body: "hey cutie :)",34 IsRead: false,35 SendAt: time.Time{},36 },37 }, nil).MinTimes(1)38 },39 ExpectedCode: http.StatusOK,40 ExpectedBody: gin.H{"result": []gin.H{41 {42 "id": "000000000000000000000000",43 "from": "iskralawrence",44 "to": "aliparlakci",45 "body": "hey cutie :)",46 "is_read": false,47 "send_at": time.Time{},48 },49 }},50 }, {51 Prepare: func(getter *mocks.MockMessageGetter) {52 getter.EXPECT().GetAllMessages(gomock.Any(), "johndoe").Return(nil, errors.New("")).MinTimes(1)53 },54 ExpectedCode: http.StatusInternalServerError,55 ExpectedBody: gin.H{},56 },57 }58 for i, tt := range tests {59 testName := fmt.Sprintf("[%v]", i)60 t.Run(testName, func(t *testing.T) {61 ctrl := gomock.NewController(t)62 defer ctrl.Finish()63 mockedMessageGetter := mocks.NewMockMessageGetter(ctrl)64 if tt.Prepare != nil {65 tt.Prepare(mockedMessageGetter)66 }67 recorder := httptest.NewRecorder()68 _, r := gin.CreateTestContext(recorder)69 r.Use(func(c *gin.Context) {70 c.Set("user", models.User{Username: "johndoe"})71 })72 r.GET("/api/messages", GetAllMessages(mockedMessageGetter))73 request, err := http.NewRequest(http.MethodGet, "/api/messages", nil)74 if err != nil {75 t.Fatal(err)76 }77 r.ServeHTTP(recorder, request)78 if bodyAssertion, err := common.AreBodiesEqual(tt.ExpectedBody, recorder.Result().Body); err != nil {79 t.Fatal(err)80 } else if !bodyAssertion {81 t.Errorf("response bodies don't match")82 }83 if recorder.Result().StatusCode != tt.ExpectedCode {84 t.Errorf("want %v, got %v", tt.ExpectedCode, recorder.Result().StatusCode)85 }86 })...

Full Screen

Full Screen

account_test.go

Source:account_test.go Github

copy

Full Screen

...304 Currency: util.RandomCurrency(),305 }306}307func requireBodyMatchAccount(t *testing.T, body *bytes.Buffer, account db.Account) {308 data, err := ioutil.ReadAll(body)309 require.NoError(t, err)310 var gotAccount db.Account311 err = json.Unmarshal(data, &gotAccount)312 require.NoError(t, err)313 require.Equal(t, account, gotAccount)314}315func requireBodyMatchAccounts(t *testing.T, body *bytes.Buffer, accounts []db.Account) {316 data, err := ioutil.ReadAll(body)317 require.NoError(t, err)318 var gotAccounts []db.Account319 err = json.Unmarshal(data, &gotAccounts)320 require.NoError(t, err)321 require.Equal(t, accounts, gotAccounts)322}...

Full Screen

Full Screen

conda_test.go

Source:conda_test.go Github

copy

Full Screen

...51 subject = conda.New(mockInstaller, mockStager, mockCommand, logger)52 })53 AfterEach(func() {54 mockCtrl.Finish()55 Expect(os.RemoveAll(buildDir)).To(Succeed())56 Expect(os.RemoveAll(cacheDir)).To(Succeed())57 Expect(os.RemoveAll(depsDir)).To(Succeed())58 })59 Describe("Version", func() {60 Context("runtime.txt specifies python 3", func() {61 BeforeEach(func() {62 Expect(ioutil.WriteFile(filepath.Join(buildDir, "runtime.txt"), []byte("python-3.2.3"), 0644)).To(Succeed())63 })64 It("returns 'miniconda3'", func() {65 Expect(subject.Version()).To(Equal("miniconda3"))66 })67 })68 Context("runtime.txt does not exist", func() {69 It("returns 'miniconda3'", func() {70 Expect(subject.Version()).To(Equal("miniconda3"))71 })72 })73 })74 Describe("Install", func() {75 It("downloads and installs miniconda version", func() {76 mockInstaller.EXPECT().InstallOnlyVersion("Miniconda7", gomock.Any()).Do(func(_, path string) {77 Expect(ioutil.WriteFile(path, []byte{}, 0644)).To(Succeed())78 })79 mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())80 Expect(subject.Install("Miniconda7")).To(Succeed())81 })82 It("make downloaded file executable", func() {83 mockInstaller.EXPECT().InstallOnlyVersion("Miniconda7", gomock.Any()).Do(func(_, path string) {84 Expect(ioutil.WriteFile(path, []byte{}, 0644)).To(Succeed())85 })86 mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), gomock.Any(), "-b", "-p", filepath.Join(depDir, "conda")).Do(func(_ string, _, _ io.Writer, path string, _ ...string) {87 fi, err := os.Lstat(path)88 Expect(err).NotTo(HaveOccurred())89 Expect(fi.Mode()).To(Equal(os.FileMode(0755)))90 })91 Expect(subject.Install("Miniconda7")).To(Succeed())92 })93 It("deletes installer", func() {94 var installerPath string95 mockInstaller.EXPECT().InstallOnlyVersion("Miniconda7", gomock.Any()).Do(func(_, path string) {96 Expect(ioutil.WriteFile(path, []byte{}, 0644)).To(Succeed())97 installerPath = path98 })99 mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), gomock.Any(), "-b", "-p", filepath.Join(depDir, "conda")).Do(func(_ string, _, _ io.Writer, path string, _ ...string) {100 Expect(path).To(Equal(installerPath))101 })102 Expect(subject.Install("Miniconda7")).To(Succeed())103 Expect(installerPath).ToNot(BeARegularFile())104 })105 })106 Describe("UpdateAndClean", func() {107 AfterEach(func() {108 os.Unsetenv("BP_DEBUG")109 })110 Context("BP_DEBUG == false", func() {111 It("calls update and clean on conda (with quiet flag)", func() {112 mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), filepath.Join(depDir, "conda", "bin", "conda"), "env", "update", "--quiet", "-n", "dep_env", "-f", filepath.Join(buildDir, "environment.yml"))113 mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), filepath.Join(depDir, "conda", "bin", "conda"), "clean", "-pt")114 Expect(subject.UpdateAndClean()).To(Succeed())115 })116 })117 Context("BP_DEBUG == true", func() {118 BeforeEach(func() {119 os.Setenv("BP_DEBUG", "1")120 })121 It("calls update and clean on conda (with debug and verbose flags)", func() {122 mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), filepath.Join(depDir, "conda", "bin", "conda"), "env", "update", "--debug", "--verbose", "-n", "dep_env", "-f", filepath.Join(buildDir, "environment.yml"))123 mockCommand.EXPECT().Execute("/", gomock.Any(), gomock.Any(), filepath.Join(depDir, "conda", "bin", "conda"), "clean", "-pt")124 Expect(subject.UpdateAndClean()).To(Succeed())125 })126 })127 })128 It("ProfileD", func() {129 Expect(subject.ProfileD()).To(Equal(`grep -rlI ` + depDir + ` $DEPS_DIR/13/conda | xargs sed -i -e "s|` + depDir + `|$DEPS_DIR/13|g"130source activate dep_env131`))132 })133 Describe("SaveCache", func() {134 It("copies the conda envs dir to cache", func() {135 mockCommand.EXPECT().Output("/", "cp", "-Rl", filepath.Join(depDir, "conda", "envs"), filepath.Join(cacheDir, "envs"))136 Expect(subject.SaveCache()).To(Succeed())137 })138 It("stores dep dir in cache as conda_prefix", func() {139 mockCommand.EXPECT().Output(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()140 Expect(subject.SaveCache()).To(Succeed())141 Expect(filepath.Join(cacheDir, "conda_prefix")).To(BeARegularFile())142 Expect(ioutil.ReadFile(filepath.Join(cacheDir, "conda_prefix"))).To(Equal([]byte(depDir)))143 })144 })145 Describe("RestoreCache", func() {146 Context("no cache", func() {147 It("does nothing", func() {148 Expect(subject.RestoreCache()).To(Succeed())149 })150 })151 Context("envs cache exists", func() {152 BeforeEach(func() {153 Expect(ioutil.WriteFile(filepath.Join(cacheDir, "conda_prefix"), []byte("/old/dep/dir\n"), 0644)).To(Succeed())154 Expect(os.MkdirAll(filepath.Join(cacheDir, "envs", "dir1", "dir2"), 0755)).To(Succeed())155 Expect(ioutil.WriteFile(filepath.Join(cacheDir, "envs", "dir1", "dir2", "file"), []byte("contents"), 0644)).To(Succeed())156 Expect(os.MkdirAll(filepath.Join(depDir, "conda", "envs", "existing"), 0755)).To(Succeed())157 Expect(ioutil.WriteFile(filepath.Join(depDir, "conda", "envs", "existing", "file"), []byte("contents"), 0644)).To(Succeed())158 })159 It("moves copies cache envs directories to conda directory", func() {160 Expect(subject.RestoreCache()).To(Succeed())161 Expect(filepath.Join(depDir, "conda", "envs", "dir1", "dir2", "file")).To(BeARegularFile())162 Expect(ioutil.ReadFile(filepath.Join(depDir, "conda", "envs", "dir1", "dir2", "file"))).To(Equal([]byte("contents")))163 })164 It("does not alter existing files in conda envs", func() {165 Expect(subject.RestoreCache()).To(Succeed())166 Expect(filepath.Join(depDir, "conda", "envs", "existing", "file")).To(BeARegularFile())167 Expect(ioutil.ReadFile(filepath.Join(depDir, "conda", "envs", "existing", "file"))).To(Equal([]byte("contents")))168 })169 It("converts old depDir to new depDir", func() {170 Expect(ioutil.WriteFile(filepath.Join(cacheDir, "envs", "dir1", "dir2", "file"), []byte("run /old/dep/dir/conda"), 0644)).To(Succeed())...

Full Screen

Full Screen

room_test.go

Source:room_test.go Github

copy

Full Screen

...145 }146 })147 }148}149func TestRoomService_GetAll(t *testing.T) {150 type args struct {151 sortField string152 }153 type mockBehavior func(r *mock_repository.MockRoom)154 tests := []struct {155 name string156 mock mockBehavior157 input args158 want []*model.Room159 wantErr bool160 }{161 {162 name: "Ok Sort By Id",163 input: args{164 sortField: "id",165 },166 mock: func(r *mock_repository.MockRoom) {167 rooms := []*model.Room{168 {Id: 1, Description: "description1", Price: 1000},169 {Id: 2, Description: "description2", Price: 5000},170 {Id: 3, Description: "description3", Price: 3000},171 }172 r.EXPECT().GetAll(gomock.Any(), gomock.Any()).Return(rooms, nil)173 },174 want: []*model.Room{175 {Id: 1, Description: "description1", Price: 1000},176 {Id: 2, Description: "description2", Price: 5000},177 {Id: 3, Description: "description3", Price: 3000},178 },179 wantErr: false,180 },181 {182 name: "Ok Sort By Price",183 input: args{184 sortField: "price",185 },186 mock: func(r *mock_repository.MockRoom) {187 rooms := []*model.Room{188 {Id: 1, Description: "description1", Price: 1000},189 {Id: 2, Description: "description2", Price: 5000},190 {Id: 3, Description: "description3", Price: 3000},191 }192 r.EXPECT().GetAll(gomock.Any(), gomock.Any()).Return(rooms, nil)193 },194 want: []*model.Room{195 {Id: 1, Description: "description1", Price: 1000},196 {Id: 2, Description: "description2", Price: 5000},197 {Id: 3, Description: "description3", Price: 3000},198 },199 wantErr: false,200 },201 {202 name: "Ok Sort By Id Reverse",203 input: args{204 sortField: "-id",205 },206 mock: func(r *mock_repository.MockRoom) {207 rooms := []*model.Room{208 {Id: 1, Description: "description1", Price: 1000},209 {Id: 3, Description: "description3", Price: 3000},210 {Id: 2, Description: "description2", Price: 5000},211 }212 r.EXPECT().GetAll(gomock.Any(), gomock.Any()).Return(rooms, nil)213 },214 want: []*model.Room{215 {Id: 1, Description: "description1", Price: 1000},216 {Id: 3, Description: "description3", Price: 3000},217 {Id: 2, Description: "description2", Price: 5000},218 },219 wantErr: false,220 },221 {222 name: "Ok Sort By Price Reverse",223 input: args{224 sortField: "-price",225 },226 mock: func(r *mock_repository.MockRoom) {227 rooms := []*model.Room{228 {Id: 2, Description: "description3", Price: 5000},229 {Id: 3, Description: "description2", Price: 3000},230 {Id: 1, Description: "description1", Price: 1000},231 }232 r.EXPECT().GetAll(gomock.Any(), gomock.Any()).Return(rooms, nil)233 },234 want: []*model.Room{235 {Id: 2, Description: "description3", Price: 5000},236 {Id: 3, Description: "description2", Price: 3000},237 {Id: 1, Description: "description1", Price: 1000},238 },239 wantErr: false,240 },241 {242 name: "Empty Sort Field",243 input: args{244 sortField: "",245 },246 mock: func(r *mock_repository.MockRoom) {247 rooms := []*model.Room{248 {Id: 1, Description: "description1", Price: 1000},249 {Id: 2, Description: "description2", Price: 5000},250 {Id: 3, Description: "description3", Price: 3000},251 }252 r.EXPECT().GetAll(gomock.Any(), gomock.Any()).Return(rooms, nil)253 },254 want: []*model.Room{255 {Id: 1, Description: "description1", Price: 1000},256 {Id: 2, Description: "description2", Price: 5000},257 {Id: 3, Description: "description3", Price: 3000},258 },259 wantErr: false,260 },261 {262 name: "Wrong Sort Field",263 input: args{264 sortField: "wrong",265 },266 mock: func(r *mock_repository.MockRoom) {},267 wantErr: true,268 },269 {270 name: "Wrong Sort Field (Reverse)",271 input: args{272 sortField: "-wrong",273 },274 mock: func(r *mock_repository.MockRoom) {},275 wantErr: true,276 },277 {278 name: "Wrong Sort Field (one symbol)",279 input: args{280 sortField: "w",281 },282 mock: func(r *mock_repository.MockRoom) {},283 wantErr: true,284 },285 {286 name: "DB Error",287 input: args{288 sortField: "id",289 },290 mock: func(r *mock_repository.MockRoom) {291 r.EXPECT().GetAll(gomock.Any(), gomock.Any()).Return(nil, ErrInternalService)292 },293 wantErr: true,294 },295 }296 for _, test := range tests {297 t.Run(test.name, func(t *testing.T) {298 c := gomock.NewController(t)299 defer c.Finish()300 repo := mock_repository.NewMockRoom(c)301 test.mock(repo)302 s := &RoomService{repo: repo}303 got, err := s.GetAll(test.input.sortField)304 if test.wantErr {305 assert.Error(t, err)306 } else {307 assert.NoError(t, err)308 assert.Equal(t, test.want, got)309 }310 })311 }312}...

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import (2func TestAll(t *testing.T) {3 ctrl := gomock.NewController(t)4 defer ctrl.Finish()5 mock := NewMockMyInterface(ctrl)6 mock.EXPECT().MyFunc(1).Return(1).AnyTimes()7 mock.EXPECT().MyFunc(2).Return(2).AnyTimes()8 fmt.Println(mock.MyFunc(1))9 fmt.Println(mock.MyFunc(2))10 assert.Equal(t, 1, mock.MyFunc(1))11 assert.Equal(t, 2, mock.MyFunc(2))12}13import (14func TestDo(t *testing.T) {15 ctrl := gomock.NewController(t)16 defer ctrl.Finish()17 mock := NewMockMyInterface(ctrl)18 mock.EXPECT().MyFunc(1).Return(1).Do(func(i int) {19 fmt.Println("Do called!!!")20 })21 fmt.Println(mock.MyFunc(1))22 assert.Equal(t, 1, mock.MyFunc(1))23}24import (25func TestMinTimes(t *testing.T) {26 ctrl := gomock.NewController(t)27 defer ctrl.Finish()28 mock := NewMockMyInterface(ctrl)29 mock.EXPECT().MyFunc(1).Return(1).MinTimes(1)30 mock.EXPECT().MyFunc(2).Return(2).MinTimes(1)31 fmt.Println(mock.MyFunc(1))32 fmt.Println(mock.MyFunc(2))33 assert.Equal(t, 1, mock.MyFunc(1))34 assert.Equal(t, 2, mock.MyFunc(2))35}36import (37func TestMaxTimes(t *testing.T) {38 ctrl := gomock.NewController(t)39 defer ctrl.Finish()

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import (2func TestAll(t *testing.T) {3 mockCtrl := gomock.NewController(t)4 defer mockCtrl.Finish()5 mockFoo := NewMockFoo(mockCtrl)6 mockFoo.EXPECT().All().Return("Hello", nil)7 fmt.Println(mockFoo.All())8}9import (10func TestAll(t *testing.T) {11 mockCtrl := gomock.NewController(t)12 defer mockCtrl.Finish()13 mockFoo := NewMockFoo(mockCtrl)14 mockFoo.EXPECT().All().Return("Hello", nil)15 fmt.Println(mockFoo.All())16}17import (18func TestAll(t *testing.T) {19 mockCtrl := gomock.NewController(t)20 defer mockCtrl.Finish()21 mockFoo := NewMockFoo(mockCtrl)22 mockFoo.EXPECT().All().Return("Hello", nil)23 fmt.Println(mockFoo.All())24}25import (26func TestAll(t *testing.T) {27 mockCtrl := gomock.NewController(t)28 defer mockCtrl.Finish()29 mockFoo := NewMockFoo(mockCtrl)30 mockFoo.EXPECT().All().Return("Hello", nil)31 fmt.Println(mockFoo.All())32}33import (34func TestAll(t *testing.T) {35 mockCtrl := gomock.NewController(t)36 defer mockCtrl.Finish()37 mockFoo := NewMockFoo(mockCtrl)38 mockFoo.EXPECT().All().Return("Hello", nil)39 fmt.Println(mockFoo.All())40}41import (42func TestAll(t *testing.T) {43 mockCtrl := gomock.NewController(t)44 defer mockCtrl.Finish()45 mockFoo := NewMockFoo(mockCtrl)46 mockFoo.EXPECT().All().Return("Hello", nil)47 fmt.Println(mockFoo.All())48}

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import (2func TestAll(t *testing.T) {3 ctrl := gomock.NewController(t)4 defer ctrl.Finish()5 mock := mock_mocking.NewMockMyInterface(ctrl)6 mock.EXPECT().All().Return([]mocking.MyStruct{{ID: 1, Name: "test"}})

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import (2func TestAll(t *testing.T) {3 mockCtrl := gomock.NewController(t)4 defer mockCtrl.Finish()5 mockObj := NewMockInterface(mockCtrl)6 mockObj.EXPECT().Method(1).Return(2)7 result := mockObj.Method(1)8 fmt.Println(result)9}10import (11func TestAny(t *testing.T) {12 mockCtrl := gomock.NewController(t)13 defer mockCtrl.Finish()14 mockObj := NewMockInterface(mockCtrl)15 mockObj.EXPECT().Method(gomock.Any()).Return(2)16 result := mockObj.Method(1)17 fmt.Println(result)18}19import (20func TestDo(t *testing.T) {21 mockCtrl := gomock.NewController(t)22 defer mockCtrl.Finish()23 mockObj := NewMockInterface(mockCtrl)24 mockObj.EXPECT().Method(1).Do(func(i int) {25 fmt.Println(i)26 })27 mockObj.Method(1)28}29import (30func TestDoAndReturn(t *testing.T) {31 mockCtrl := gomock.NewController(t)32 defer mockCtrl.Finish()33 mockObj := NewMockInterface(mockCtrl)34 mockObj.EXPECT().Method(1).DoAndReturn(func(i int) int {35 fmt.Println(i)

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctrl := gomock.NewController(nil)4 defer ctrl.Finish()5 mock := _2.NewMockInterface(ctrl)6 mock.EXPECT().All().Return(4, nil)7 fmt.Println("Result:", mock.All())8}9import (10type Interface interface {11 All() (int, error)12}13func NewMockInterface(ctrl *gomock.Controller) *MockInterface {14 mock := &MockInterface{ctrl: ctrl}15 mock.recorder = &MockInterfaceMockRecorder{mock}16}17type MockInterface struct {18}19type MockInterfaceMockRecorder struct {20}21func (m *MockInterfaceMockRecorder) All() *gomock.Call {22 return m.mock.ctrl.RecordCall(m.mock, "All")23}24func (m *MockInterface) All() (int, error) {25 ret := m.ctrl.Call(m, "All")26 ret0, _ := ret[0].(int)27 ret1, _ := ret[1].(error)28}29func (mr *MockInterfaceMockRecorder) All() *gomock.Call {30 return mr.mock.ctrl.RecordCall(mr.mock, "All")31}32type MockInterface2 struct {33}34func NewMockInterface2(ctrl *gomock.Controller) *MockInterface2 {35 mock := &MockInterface2{MockInterface: NewMockInterface(ctrl)}36 mock.recorder = &MockInterface2MockRecorder{mock}37}38type MockInterface2MockRecorder struct {39}40func (m *MockInterface2MockRecorder) All() *gomock.Call {41 return m.mock.MockInterface.recorder.All()42}43func (m *MockInterface2) All() (int, error) {44 ret := m.MockInterface.All()45}46func (mr *MockInterface2MockRecorder) All() *gomock.Call {47 return mr.mock.MockInterface.recorder.All()48}49func (m *MockInterface2) All2() (int, error) {50 ret := m.MockInterface.All()

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import (2func TestAll(t *testing.T) {3 ctrl := gomock.NewController(t)4 defer ctrl.Finish()5 mockObj := mock.NewMockMyInterface(ctrl)6 mockObj.EXPECT().All().Return("Hello World")7 fmt.Println(mockObj.All())8}9import (10func TestGet(t *testing.T) {11 ctrl := gomock.NewController(t)12 defer ctrl.Finish()13 mockObj := mock.NewMockMyInterface(ctrl)14 mockObj.EXPECT().Get(1).Return("Hello World")15 fmt.Println(mockObj.Get(1))16}17import (18func TestGet(t *testing.T) {19 ctrl := gomock.NewController(t)20 defer ctrl.Finish()21 mockObj := mock.NewMockMyInterface(ctrl)22 mockObj.EXPECT().Get(1).Return("Hello World")23 fmt.Println(mockObj.Get(1))24}25import (26func TestGet(t *testing.T) {27 ctrl := gomock.NewController(t)28 defer ctrl.Finish()29 mockObj := mock.NewMockMyInterface(ctrl)30 mockObj.EXPECT().Get(1).Return("Hello World")31 fmt.Println(mockObj.Get(1))32}

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1func TestGomock(t *testing.T) {2 ctrl := gomock.NewController(t)3 defer ctrl.Finish()4 mock := NewMockMyInterface(ctrl)5 mock.EXPECT().All().Return([]string{"a", "b"})6 fmt.Println(mock.All())7}8func TestGomock(t *testing.T) {9 ctrl := gomock.NewController(t)10 defer ctrl.Finish()11 mock := NewMockMyInterface(ctrl)12 mock.EXPECT().All().Return([]string{"a", "b"})13 fmt.Println(mock.All())14}15func TestGomock(t *testing.T) {16 ctrl := gomock.NewController(t)17 defer ctrl.Finish()18 mock := NewMockMyInterface(ctrl)19 mock.EXPECT().All().Return([]string{"a", "b"})20 fmt.Println(mock.All())21}22func TestGomock(t *testing.T) {23 ctrl := gomock.NewController(t)24 defer ctrl.Finish()25 mock := NewMockMyInterface(ctrl)26 mock.EXPECT().All().Return([]string{"a", "b"})27 fmt.Println(mock.All())28}29func TestGomock(t *testing.T) {30 ctrl := gomock.NewController(t)31 defer ctrl.Finish()32 mock := NewMockMyInterface(ctrl)33 mock.EXPECT().All().Return([]string{"a", "b"})34 fmt.Println(mock.All())35}36func TestGomock(t *testing.T) {37 ctrl := gomock.NewController(t)38 defer ctrl.Finish()39 mock := NewMockMyInterface(ctrl)40 mock.EXPECT().All().Return([]string{"a", "b"})41 fmt.Println(mock.All())42}43func TestGomock(t *testing.T) {44 ctrl := gomock.NewController(t)45 defer ctrl.Finish()

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World!")4 a.All()5}6import (7type A struct {8}9func (a A) All() {10 fmt.Println("All method of A")11}12import (13type A struct {14}15func (a A) All() {16 fmt.Println("All method of A")17}18import (19type A struct {20}21func (a A) All() {22 fmt.Println("All method of A")23}24import (25type A struct {26}27func (a A) All() {28 fmt.Println("All method of A")29}30import (31type A struct {32}33func (a A) All() {34 fmt.Println("All method of A")35}36import (37type A struct {38}39func (a A) All() {40 fmt.Println("All method of A")41}42import (43type A struct {44}45func (a A) All() {46 fmt.Println("All method of A")47}48import (49type A struct {50}51func (a A) All() {52 fmt.Println("All method of A")53}54import (55type A struct {56}57func (a A) All() {58 fmt.Println("All

Full Screen

Full Screen

All

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 mock := mocking.NewMockInterface(nil)4 s := []string{"hello", "world"}5 s1 := []string{"hello", "world", "!"}6 s2 := []string{"hello", "world", "!", "!"}7 mock.EXPECT().All().Return(s, nil).Times(1)8 mock.EXPECT().All().Return(s1, nil).Times(1)9 mock.EXPECT().All().Return(s2, nil).Times(1)10 result, _ := mock.All()11 fmt.Println(result)12 result, _ = mock.All()13 fmt.Println(result)14 result, _ = mock.All()15 fmt.Println(result)16}17import (18func main() {19 mock := mocking.NewMockInterface(nil)20 s := []string{"hello", "world"}21 s1 := []string{"hello", "world", "!"}22 s2 := []string{"hello", "world", "!", "!"}23 mock.EXPECT().All().Return(s, nil).Times(1)24 mock.EXPECT().All().Return(s1, nil).Times(1)25 mock.EXPECT().All().Return(s2, nil).Times(1)26 result, _ := mock.All()27 fmt.Println(result)28 result, _ = mock.All()29 fmt.Println(result)

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