Best Mock code snippet using gomock.String
supply_test.go
Source:supply_test.go
...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())662 Expect(buffer.String()).To(ContainSubstring("Downloading NLTK packages: brown red"))663 Expect(supplier.HasNltkData).To(BeTrue())664 })665 })666 })667 })668 Describe("SetupCacheDir", func() {669 AfterEach(func() { os.Unsetenv("XDG_CACHE_HOME") })670 It("Sets pip's cache directory", func() {671 mockStager.EXPECT().WriteEnvFile("XDG_CACHE_HOME", filepath.Join(cacheDir, "pip_cache"))672 Expect(supplier.SetupCacheDir()).To(Succeed())673 Expect(os.Getenv("XDG_CACHE_HOME")).To(Equal(filepath.Join(cacheDir, "pip_cache")))674 })675 })676})...
conda_test.go
Source:conda_test.go
1package conda_test2import (3 "bytes"4 io "io"5 "io/ioutil"6 "os"7 "path/filepath"8 "github.com/cloudfoundry/python-buildpack/src/python/conda"9 "github.com/cloudfoundry/libbuildpack"10 "github.com/cloudfoundry/libbuildpack/ansicleaner"11 gomock "github.com/golang/mock/gomock"12 . "github.com/onsi/ginkgo"13 . "github.com/onsi/gomega"14)15//go:generate mockgen -source=conda.go --destination=mocks_test.go --package=conda_test16var _ = Describe("Conda", func() {17 var (18 err error19 buildDir string20 cacheDir string21 depsDir string22 depsIdx string23 depDir string24 subject *conda.Conda25 logger *libbuildpack.Logger26 buffer *bytes.Buffer27 mockCtrl *gomock.Controller28 mockInstaller *MockInstaller29 mockStager *MockStager30 mockCommand *MockCommand31 )32 BeforeEach(func() {33 buildDir, err = ioutil.TempDir("", "python-buildpack.build.")34 Expect(err).To(BeNil())35 cacheDir, err = ioutil.TempDir("", "python-buildpack.cache.")36 Expect(err).To(BeNil())37 depsDir, err = ioutil.TempDir("", "python-buildpack.deps.")38 Expect(err).To(BeNil())39 depsIdx = "13"40 depDir = filepath.Join(depsDir, depsIdx)41 mockCtrl = gomock.NewController(GinkgoT())42 mockInstaller = NewMockInstaller(mockCtrl)43 mockStager = NewMockStager(mockCtrl)44 mockStager.EXPECT().BuildDir().AnyTimes().Return(buildDir)45 mockStager.EXPECT().CacheDir().AnyTimes().Return(cacheDir)46 mockStager.EXPECT().DepDir().AnyTimes().Return(depDir)47 mockStager.EXPECT().DepsIdx().AnyTimes().Return(depsIdx)48 mockCommand = NewMockCommand(mockCtrl)49 buffer = new(bytes.Buffer)50 logger = libbuildpack.NewLogger(ansicleaner.New(buffer))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())171 Expect(subject.RestoreCache()).To(Succeed())172 Expect(filepath.Join(depDir, "conda", "envs", "dir1", "dir2", "file")).To(BeARegularFile())173 Expect(ioutil.ReadFile(filepath.Join(depDir, "conda", "envs", "dir1", "dir2", "file"))).To(Equal([]byte("run " + depDir + "/conda")))174 })175 })176 })177})...
send_test.go
Source:send_test.go
...50 mockSrvcs.EXPECT().Close(),51 )52 err := app.Run([]string{"lotus", "send", "t01", "1"})53 assert.NoError(t, err)54 assert.EqualValues(t, sigMsg.Cid().String()+"\n", buf.String())55 })56}
String
Using AI Code Generation
1import (2func TestString(t *testing.T) {3 ctrl := gomock.NewController(t)4 defer ctrl.Finish()5 m := mock.NewMockMyInterface(ctrl)6 m.EXPECT().String().Return("hello world")7 fmt.Println(m.String())8}9--- PASS: TestString (0.00s)
String
Using AI Code Generation
1import (2func TestMock(t *testing.T) {3 ctrl := gomock.NewController(t)4 defer ctrl.Finish()5 mockObj := mocktest.NewMockMyInterface(ctrl)6 mockObj.EXPECT().String().Return("mocked string")7 fmt.Println(mockObj.String())8}
String
Using AI Code Generation
1import "fmt"2func main() {3 fmt.Println("Hello, playground")4 var i interface{}5 s := i.(string)6 fmt.Println(s)7}8import "fmt"9func main() {10 fmt.Println("Hello, playground")11 var i interface{}12 s, ok := i.(string)13 fmt.Println(s, ok)14}15import "fmt"16func main() {17 fmt.Println("Hello, playground")18 var i interface{}19 s, ok := i.(int)20 fmt.Println(s, ok)21}22import "fmt"23func main() {24 fmt.Println("Hello, playground")25 var i interface{}26 s, ok := i.(int)27 fmt.Println(s, ok)28}29import "fmt"30func main() {31 fmt.Println("Hello, playground")32 var i interface{}33 s, ok := i.(int)34 fmt.Println(s, ok)35}36import "fmt"37func main() {38 fmt.Println("Hello, playground")39 var i interface{}40 s, ok := i.(int)41 fmt.Println(s, ok)42}43import "fmt"44func main() {45 fmt.Println("Hello, playground")46 var i interface{}47 s, ok := i.(int)48 fmt.Println(s, ok)49}50import "fmt"51func main() {52 fmt.Println("Hello, playground")53 var i interface{}
String
Using AI Code Generation
1import (2func main() {3ctrl := gomock.NewController(nil)4mock := NewMockStringer(ctrl)5mock.EXPECT().String().Return("Hello, world!")6fmt.Println(mock.String())7}
String
Using AI Code Generation
1import "fmt"2import "github.com/golang/mock/gomock"3import "github.com/rajeshkumarv/gomocktest/mock"4func main() {5 ctrl := gomock.NewController(nil)6 defer ctrl.Finish()7 mock := mock.NewMockInterface(ctrl)8 mock.EXPECT().String().Return("Hello, world!")9 fmt.Println(mock.String())10}11import "fmt"12import "github.com/golang/mock/gomock"13import "github.com/rajeshkumarv/gomocktest/mock"14import "github.com/rajeshkumarv/gomocktest/test"15func main() {16 ctrl := gomock.NewController(nil)17 defer ctrl.Finish()18 mock := mock.NewMockInterface(ctrl)19 mock.EXPECT().String().Return("Hello, world!")20 fmt.Println(test.Test(mock))21}22import "fmt"23import "github.com/golang/mock/gomock"24import "github.com/rajeshkumarv/gomocktest/mock"25import "github.com/rajeshkumarv/gomocktest/test"26func main() {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!