Best Syzkaller code snippet using vcs.TestGitRepo
package_test.go
Source:package_test.go
1// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4package beku5import (6 "fmt"7 "os"8 "path/filepath"9 "strings"10 "testing"11 "github.com/shuLhan/share/lib/ini"12 "github.com/shuLhan/share/lib/test"13 "github.com/shuLhan/share/lib/test/mock"14)15func TestPackageRemove(t *testing.T) {16 cases := []struct {17 desc string18 pkgName string19 pkg *Package20 expErr string21 }{{22 desc: `Package is not exist`,23 pkgName: testPkgNotExist,24 }, {25 desc: `Package exist`,26 pkg: testGitPkgInstall,27 }}28 for _, c := range cases {29 t.Log(c.desc)30 if len(c.pkgName) > 0 {31 c.pkg, _ = NewPackage(testEnv.dirSrc, c.pkgName, c.pkgName)32 }33 err := c.pkg.Remove()34 if err != nil {35 test.Assert(t, "err", c.expErr, err)36 continue37 }38 expErr := fmt.Sprintf("stat %s: no such file or directory", c.pkg.FullPath)39 _, err = os.Stat(c.pkg.FullPath)40 test.Assert(t, "src dir should not exist", expErr, err.Error())41 pkg := filepath.Join(testEnv.dirPkg, c.pkg.ImportPath)42 expErr = fmt.Sprintf("stat %s: no such file or directory", pkg)43 _, err = os.Stat(pkg)44 if err != nil {45 test.Assert(t, "pkg dir should not exist", expErr, err.Error())46 }47 }48}49func TestPackageInstall(t *testing.T) {50 cases := []struct {51 desc string52 pkg *Package53 expErr string54 expPkg *Package55 }{{56 desc: `Without version`,57 pkg: testGitPkgInstall,58 expPkg: &Package{59 ImportPath: testGitRepo,60 FullPath: testGitPkgInstall.FullPath,61 RemoteName: gitDefRemoteName,62 RemoteURL: testGitPkgInstall.RemoteURL,63 RemoteBranch: "master",64 Version: "157a004",65 vcsMode: VCSModeGit,66 state: packageStateNew,67 },68 }, {69 desc: `Install again`,70 pkg: testGitPkgInstall,71 expErr: "gitInstall: Clone: exit status 128",72 }}73 for _, c := range cases {74 t.Log(c.desc)75 mock.Reset(true)76 err := c.pkg.Install()77 if err != nil {78 test.Assert(t, "err", c.expErr, err.Error())79 continue80 }81 }82}83func TestIsEqual(t *testing.T) {84 cases := []struct {85 desc string86 pkg *Package87 other *Package88 exp bool89 }{{90 desc: "With nil on other",91 pkg: &Package{},92 }, {93 desc: "With different ImportPath",94 pkg: &Package{95 ImportPath: "git",96 },97 other: &Package{98 ImportPath: "gitt",99 },100 }, {101 desc: "With different RemoteName",102 pkg: &Package{103 ImportPath: "git",104 RemoteName: "origin",105 },106 other: &Package{107 ImportPath: "git",108 RemoteName: "upstream",109 },110 }, {111 desc: "With different RemoteURL",112 pkg: &Package{113 ImportPath: "git",114 RemoteName: "origin",115 RemoteURL: "https://github.com/shuLhan/beku",116 },117 other: &Package{118 ImportPath: "git",119 RemoteName: "origin",120 RemoteURL: "https://gopkg.in/shuLhan/beku",121 },122 }, {123 desc: "With different Version",124 pkg: &Package{125 ImportPath: "git",126 RemoteName: "origin",127 RemoteURL: "https://github.com/shuLhan/beku",128 Version: "v0.1.0",129 },130 other: &Package{131 ImportPath: "git",132 RemoteName: "origin",133 RemoteURL: "https://github.com/shuLhan/beku",134 Version: "v0.1.1",135 },136 }, {137 desc: "With equal",138 pkg: &Package{139 ImportPath: "git",140 RemoteName: "origin",141 RemoteURL: "https://github.com/shuLhan/beku",142 Version: "v0.1.0",143 },144 other: &Package{145 ImportPath: "git",146 RemoteName: "origin",147 RemoteURL: "https://github.com/shuLhan/beku",148 Version: "v0.1.0",149 },150 exp: true,151 }}152 var got bool153 for _, c := range cases {154 t.Log(c.desc)155 got = c.pkg.IsEqual(c.other)156 test.Assert(t, "", c.exp, got)157 }158}159func TestAddDep(t *testing.T) {160 cases := []struct {161 desc string162 envPkgs []*Package163 importPath string164 exp bool165 expDeps []string166 expDepsMissing []string167 expPkgsMissing []string168 }{{169 desc: "Is the same path as package",170 importPath: testGitRepo,171 }, {172 desc: "Is vendor package",173 importPath: "vendor/github.com/shuLhan/beku",174 }, {175 desc: "Is standard package",176 importPath: "os/exec",177 }, {178 desc: "Is exist on environment",179 envPkgs: []*Package{{180 ImportPath: "github.com/shuLhan/beku",181 }, {182 ImportPath: "github.com/shuLhan/share",183 }},184 importPath: "github.com/shuLhan/share/lib/test",185 exp: true,186 expDeps: []string{187 "github.com/shuLhan/share",188 },189 }, {190 desc: "Is exist on environment (again)",191 envPkgs: []*Package{{192 ImportPath: "github.com/shuLhan/beku",193 }, {194 ImportPath: "github.com/shuLhan/share",195 }},196 importPath: "github.com/shuLhan/share/lib/test",197 exp: true,198 expDeps: []string{199 "github.com/shuLhan/share",200 },201 }, {202 desc: "Is not exist on environment (missing)",203 importPath: "github.com/shuLhan/tekstus",204 exp: true,205 expDeps: []string{206 "github.com/shuLhan/share",207 },208 expDepsMissing: []string{209 "github.com/shuLhan/tekstus",210 },211 expPkgsMissing: []string{212 "github.com/shuLhan/tekstus",213 },214 }, {215 desc: "Is not exist on environment (again)",216 importPath: "github.com/shuLhan/tekstus",217 exp: true,218 expDeps: []string{219 "github.com/shuLhan/share",220 },221 expDepsMissing: []string{222 "github.com/shuLhan/tekstus",223 },224 expPkgsMissing: []string{225 "github.com/shuLhan/tekstus",226 },227 }}228 var got bool229 testGitPkgCur.Deps = nil230 testGitPkgCur.DepsMissing = nil231 for _, c := range cases {232 t.Log(c.desc)233 testEnv.pkgs = c.envPkgs234 testEnv.pkgsMissing = nil235 got = testGitPkgCur.addDep(testEnv, c.importPath)236 test.Assert(t, "return", c.exp, got)237 if !got {238 continue239 }240 test.Assert(t, "Deps", c.expDeps, testGitPkgCur.Deps)241 test.Assert(t, "DepsMissing", c.expDepsMissing, testGitPkgCur.DepsMissing)242 test.Assert(t, "env.pkgsMissing", c.expPkgsMissing, testEnv.pkgsMissing)243 }244 testGitPkgCur.Deps = nil245 testGitPkgCur.DepsMissing = nil246}247func TestPushRequiredBy(t *testing.T) {248 cases := []struct {249 desc string250 importPath string251 exp bool252 expRequiredBy []string253 }{{254 desc: "Not exist yet",255 importPath: testGitRepo,256 exp: true,257 expRequiredBy: []string{258 testGitRepo,259 },260 }, {261 desc: "Already exist",262 importPath: testGitRepo,263 expRequiredBy: []string{264 testGitRepo,265 },266 }}267 testGitPkgCur.RequiredBy = nil268 var got bool269 for _, c := range cases {270 t.Log(c.desc)271 got = testGitPkgCur.pushRequiredBy(c.importPath)272 test.Assert(t, "return value", c.exp, got)273 test.Assert(t, "RequiredBy", c.expRequiredBy, testGitPkgCur.RequiredBy)274 }275}276func TestPackageRemoveRequiredBy(t *testing.T) {277 cases := []struct {278 desc string279 pkg *Package280 importPath string281 exp bool282 expRequiredBy []string283 }{{284 desc: `With importPath not found`,285 pkg: testGitPkgCur,286 importPath: testPkgNotExist,287 exp: false,288 expRequiredBy: []string{289 testGitRepo,290 },291 }, {292 desc: `With importPath found`,293 pkg: testGitPkgCur,294 importPath: testGitRepo,295 exp: true,296 }}297 for _, c := range cases {298 t.Log(c.desc)299 t.Log(">>> RequiredBy:", c.pkg.RequiredBy)300 got := c.pkg.RemoveRequiredBy(c.importPath)301 test.Assert(t, "return value", c.exp, got)302 test.Assert(t, "RequiredBy", c.expRequiredBy, c.pkg.RequiredBy)303 }304}305func TestPackageLoad(t *testing.T) {306 cases := []struct {307 desc string308 pkgName string309 exp *Package310 }{{311 desc: "With invalid vcs mode",312 pkgName: "test_vcs",313 exp: &Package{314 vcsMode: VCSModeGit,315 },316 }, {317 desc: "Duplicate remote name",318 pkgName: "dup_remote_name",319 exp: &Package{320 vcsMode: VCSModeGit,321 RemoteName: "last",322 },323 }, {324 desc: "Duplicate remote URL",325 pkgName: "dup_remote_url",326 exp: &Package{327 vcsMode: VCSModeGit,328 RemoteName: "last",329 RemoteURL: "remote url 2",330 },331 }, {332 desc: "Duplicate version",333 pkgName: "dup_version",334 exp: &Package{335 vcsMode: VCSModeGit,336 RemoteName: "last",337 RemoteURL: "remote url 2",338 Version: "v1.1.0",339 isTag: true,340 },341 }, {342 desc: "Version not tag",343 pkgName: "version_not_tag",344 exp: &Package{345 vcsMode: VCSModeGit,346 RemoteName: "last",347 RemoteURL: "remote url 2",348 Version: "12345678",349 isTag: false,350 },351 }, {352 desc: "With deps",353 pkgName: "deps",354 exp: &Package{355 vcsMode: VCSModeGit,356 RemoteName: "last",357 RemoteURL: "remote url 2",358 Version: "12345678",359 isTag: false,360 Deps: []string{361 "dep/1",362 "dep/2",363 "dep/3",364 },365 },366 }, {367 desc: "With missing deps",368 pkgName: "deps_missing",369 exp: &Package{370 vcsMode: VCSModeGit,371 RemoteName: "last",372 RemoteURL: "remote url 2",373 Version: "12345678",374 isTag: false,375 DepsMissing: []string{376 "missing/1",377 "missing/2",378 "missing/3",379 },380 },381 }, {382 desc: "With required-by",383 pkgName: "required-by",384 exp: &Package{385 vcsMode: VCSModeGit,386 RemoteName: "last",387 RemoteURL: "remote url 2",388 Version: "12345678",389 isTag: false,390 RequiredBy: []string{391 "required-by/3",392 "required-by/2",393 "required-by/1",394 },395 },396 }}397 cfg, err := ini.Open("testdata/package_load.conf")398 if err != nil {399 t.Fatal(err)400 }401 for _, c := range cases {402 t.Log(c.desc)403 pkg := new(Package)404 sec := cfg.Section(sectionPackage, c.pkgName)405 pkg.load(sec)406 test.Assert(t, "", c.exp, pkg)407 }408}409func TestGoInstall(t *testing.T) {410 cases := []struct {411 desc string412 pkg *Package413 isVerbose bool414 expBin string415 expArchive string416 expStdout string417 expStderr string418 }{{419 desc: "Running #1",420 pkg: testGitPkgCur,421 expStderr: `go: warning: "./..." matched no packages`,422 }, {423 desc: "Running with verbose",424 pkg: testGitPkgCur,425 isVerbose: true,426 expStderr: `go: warning: "./..." matched no packages`,427 }}428 for _, c := range cases {429 t.Log(c.desc)430 mock.Reset(true)431 err := c.pkg.GoInstall(testEnv.path)432 mock.Reset(false)433 stdout := mock.Output()434 stderr := mock.Error()435 if err != nil {436 errLines := strings.Split(stderr, "\n")437 test.Assert(t, "stderr", c.expStderr, errLines[0])438 } else {439 outLines := strings.Split(stdout, "\n")440 test.Assert(t, "stdout", c.expStdout, outLines[0])441 }442 if len(c.expBin) > 0 {443 _, err = os.Stat(c.expBin)444 if err != nil {445 t.Fatal(err)446 }447 }448 if len(c.expArchive) > 0 {449 _, err = os.Stat(c.expArchive)450 if err != nil {451 t.Fatal(err)452 }453 }454 }455}456func TestPackageString(t *testing.T) {457 cases := []struct {458 pkg *Package459 exp string460 }{{461 pkg: testGitPkgCur,462 exp: `463[package "github.com/shuLhan/beku_test"]464 FullPath = ` + filepath.Join(testEnv.dirSrc, testGitRepo) + `465 VCS = git466 RemoteName = origin467 RemoteURL = ` + testGitRepoSrcLocal + `468 RemoteBranch = master469 Version = v0.2.0470 VersionNext = 471 IsTag = true472 Deps = []473 RequiredBy = []474 DepsMissing = []475`,476 }}477 for _, c := range cases {478 got := c.pkg.String()479 test.Assert(t, "string", c.exp, got)480 }481}482func TestUpdate(t *testing.T) {483 cases := []struct {484 desc string485 curPkg *Package486 newPkg *Package487 expErr error488 expPkg *Package489 }{{490 desc: "Update remote URL",491 curPkg: &Package{492 vcsMode: VCSModeGit,493 ImportPath: testGitRepo,494 FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),495 RemoteName: gitDefRemoteName,496 RemoteURL: "https://" + testGitRepo,497 },498 newPkg: &Package{499 vcsMode: VCSModeGit,500 ImportPath: testGitRepo,501 FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),502 RemoteName: gitDefRemoteName,503 RemoteURL: testGitRepoSrcLocal,504 },505 expPkg: &Package{506 vcsMode: VCSModeGit,507 ImportPath: testGitRepo,508 FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),509 RemoteName: gitDefRemoteName,510 RemoteURL: testGitRepoSrcLocal,511 RemoteBranch: "master",512 },513 }, {514 desc: "Update version",515 curPkg: &Package{516 vcsMode: VCSModeGit,517 ImportPath: testGitRepo,518 FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),519 RemoteName: gitDefRemoteName,520 RemoteURL: "https://" + testGitRepo,521 },522 newPkg: &Package{523 vcsMode: VCSModeGit,524 ImportPath: testGitRepo,525 FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),526 RemoteName: gitDefRemoteName,527 RemoteURL: testGitRepoSrcLocal,528 Version: "v0.1.0",529 isTag: true,530 },531 expPkg: &Package{532 vcsMode: VCSModeGit,533 ImportPath: testGitRepo,534 FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),535 RemoteName: gitDefRemoteName,536 RemoteURL: testGitRepoSrcLocal,537 RemoteBranch: "master",538 Version: "v0.1.0",539 isTag: true,540 },541 }, {542 desc: "Update version back",543 curPkg: &Package{544 vcsMode: VCSModeGit,545 ImportPath: testGitRepo,546 FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),547 RemoteName: gitDefRemoteName,548 RemoteURL: "https://" + testGitRepo,549 },550 newPkg: &Package{551 vcsMode: VCSModeGit,552 ImportPath: testGitRepo,553 FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),554 RemoteName: gitDefRemoteName,555 RemoteURL: testGitRepoSrcLocal,556 Version: "c9f69fb",557 isTag: true,558 },559 expPkg: &Package{560 vcsMode: VCSModeGit,561 ImportPath: testGitRepo,562 FullPath: filepath.Join(testEnv.dirSrc, testGitRepo),563 RemoteName: gitDefRemoteName,564 RemoteURL: testGitRepoSrcLocal,565 RemoteBranch: "master",566 Version: "c9f69fb",567 isTag: false,568 },569 }}570 for _, c := range cases {571 t.Log(c.desc)572 mock.Reset(true)573 err := c.curPkg.Update(c.newPkg)574 mock.Reset(false)575 stdout := mock.Output()576 stderr := mock.Error()577 if err != nil {578 t.Log("stderr:", stderr)579 test.Assert(t, "err", c.expErr, err.Error())580 continue581 }582 if len(stdout) > 0 {583 t.Log("stdout:", stdout)584 }585 test.Assert(t, "current pkg", *c.expPkg, *c.curPkg)586 }587}588func TestUpdateMissingDep(t *testing.T) {589 cases := []struct {590 desc string591 curPkg *Package592 misPkg *Package593 exp bool594 expCurPkg *Package595 expMisPkg *Package596 }{{597 desc: "No missing found",598 curPkg: &Package{599 ImportPath: "curpkg",600 DepsMissing: []string{601 "a",602 "b",603 },604 },605 misPkg: &Package{606 ImportPath: "c",607 },608 expCurPkg: &Package{609 ImportPath: "curpkg",610 DepsMissing: []string{611 "a",612 "b",613 },614 },615 expMisPkg: &Package{616 ImportPath: "c",617 },618 }, {619 desc: "Missing package found",620 curPkg: &Package{621 ImportPath: "curpkg",622 DepsMissing: []string{623 "a",624 "b",625 "c",626 },627 },628 misPkg: &Package{629 ImportPath: "c",630 },631 exp: true,632 expCurPkg: &Package{633 ImportPath: "curpkg",634 DepsMissing: []string{635 "a",636 "b",637 },638 Deps: []string{639 "c",640 },641 state: packageStateDirty,642 },643 expMisPkg: &Package{644 ImportPath: "c",645 RequiredBy: []string{646 "curpkg",647 },648 },649 }}650 for _, c := range cases {651 t.Log(c.desc)652 got := c.curPkg.UpdateMissingDep(c.misPkg, true)653 test.Assert(t, "return value", c.exp, got)654 test.Assert(t, "package", c.expCurPkg, c.curPkg)655 }656}657func TestPackageGoClean(t *testing.T) {658 cases := []struct {659 desc string660 pkgName string661 pkg *Package662 pkgBin string663 expErr string664 expBinErr string665 }{{666 desc: `With package not exist`,667 pkgName: testPkgNotExist,668 }, {669 desc: `With package exist`,670 pkg: testGitPkgCur,671 pkgBin: filepath.Join(testEnv.dirBin, "beku_test"),672 expBinErr: "stat %s: no such file or directory",673 }}674 var err error675 for _, c := range cases {676 t.Log(c.desc)677 if len(c.pkgName) > 0 {678 c.pkg, _ = NewPackage(testEnv.dirSrc, c.pkgName, c.pkgName)679 }680 err = c.pkg.GoClean()681 if err != nil {682 test.Assert(t, "err", c.expErr, err)683 continue684 }685 if len(c.pkgBin) > 0 {686 _, err = os.Stat(c.pkgBin)687 if err != nil {688 exp := fmt.Sprintf(c.expBinErr, c.pkgBin)689 test.Assert(t, "pkgBin", exp, err.Error())690 }691 }692 }693}694func TestPackagePost(t *testing.T) {695 err := testGitPkgInstall.Remove()696 if err != nil {697 t.Fatal(err)698 }699}...
vcs_repo_test.go
Source:vcs_repo_test.go
1// Copyright 2017 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4package gps5import (6 "context"7 "errors"8 "io/ioutil"9 "os"10 "testing"11 "time"12 "github.com/Masterminds/vcs"13)14// original implementation of these test files come from15// https://github.com/Masterminds/vcs test files16const gitRemoteTestRepo = "https://github.com/Masterminds/VCSTestRepo"17func TestErrs(t *testing.T) {18 err := newVcsLocalErrorOr(context.Canceled, nil, "", "")19 if err != context.Canceled {20 t.Errorf("context errors should always pass through, got %s", err)21 }22 err = newVcsRemoteErrorOr(context.Canceled, nil, "", "")23 if err != context.Canceled {24 t.Errorf("context errors should always pass through, got %s", err)25 }26 err = newVcsLocalErrorOr(context.DeadlineExceeded, nil, "", "")27 if err != context.DeadlineExceeded {28 t.Errorf("context errors should always pass through, got %s", err)29 }30 err = newVcsRemoteErrorOr(context.DeadlineExceeded, nil, "", "")31 if err != context.DeadlineExceeded {32 t.Errorf("context errors should always pass through, got %s", err)33 }34 err = newVcsLocalErrorOr(errors.New("bar"), nil, "foo", "baz")35 if _, is := err.(*vcs.LocalError); !is {36 t.Errorf("should have gotten local error, got %T %v", err, err)37 }38 err = newVcsRemoteErrorOr(errors.New("bar"), nil, "foo", "baz")39 if _, is := err.(*vcs.RemoteError); !is {40 t.Errorf("should have gotten remote error, got %T %v", err, err)41 }42}43func testSvnRepo(t *testing.T) {44 t.Parallel()45 if testing.Short() {46 t.Skip("Skipping slow test in short mode")47 }48 ctx := context.Background()49 tempDir, err := ioutil.TempDir("", "go-vcs-svn-tests")50 if err != nil {51 t.Fatal(err)52 }53 defer func() {54 err = os.RemoveAll(tempDir)55 if err != nil {56 t.Error(err)57 }58 }()59 rep, err := vcs.NewSvnRepo("https://github.com/Masterminds/VCSTestRepo/trunk", tempDir+string(os.PathSeparator)+"VCSTestRepo")60 if err != nil {61 t.Fatal(err)62 }63 repo := &svnRepo{rep}64 // Do an initial checkout.65 err = repo.get(ctx)66 if err != nil {67 t.Fatalf("Unable to checkout SVN repo. Err was %s", err)68 }69 // Verify SVN repo is a SVN repo70 if !repo.CheckLocal() {71 t.Fatal("Problem checking out repo or SVN CheckLocal is not working")72 }73 // Update the version to a previous version.74 err = repo.updateVersion(ctx, "r2")75 if err != nil {76 t.Fatalf("Unable to update SVN repo version. Err was %s", err)77 }78 // Use Version to verify we are on the right version.79 v, err := repo.Version()80 if err != nil {81 t.Fatal(err)82 }83 if v != "2" {84 t.Fatal("Error checking checked SVN out version")85 }86 // Perform an update which should take up back to the latest version.87 err = repo.fetch(ctx)88 if err != nil {89 t.Fatal(err)90 }91 // Make sure we are on a newer version because of the update.92 v, err = repo.Version()93 if err != nil {94 t.Fatal(err)95 }96 if v == "2" {97 t.Fatal("Error with version. Still on old version. Update failed")98 }99 ci, err := repo.CommitInfo("2")100 if err != nil {101 t.Fatal(err)102 }103 if ci.Commit != "2" {104 t.Error("Svn.CommitInfo wrong commit id")105 }106 if ci.Author != "matt.farina" {107 t.Error("Svn.CommitInfo wrong author")108 }109 if ci.Message != "Update README.md" {110 t.Error("Svn.CommitInfo wrong message")111 }112 ti, err := time.Parse(time.RFC3339Nano, "2015-07-29T13:46:20.000000Z")113 if err != nil {114 t.Fatal(err)115 }116 if !ti.Equal(ci.Date) {117 t.Error("Svn.CommitInfo wrong date")118 }119 _, err = repo.CommitInfo("555555555")120 if err != vcs.ErrRevisionUnavailable {121 t.Error("Svn didn't return expected ErrRevisionUnavailable")122 }123}124func testHgRepo(t *testing.T) {125 t.Parallel()126 if testing.Short() {127 t.Skip("Skipping slow test in short mode")128 }129 ctx := context.Background()130 tempDir, err := ioutil.TempDir("", "go-vcs-hg-tests")131 if err != nil {132 t.Fatal(err)133 }134 defer func() {135 err = os.RemoveAll(tempDir)136 if err != nil {137 t.Error(err)138 }139 }()140 rep, err := vcs.NewHgRepo("https://bitbucket.org/mattfarina/testhgrepo", tempDir+"/testhgrepo")141 if err != nil {142 t.Fatal(err)143 }144 repo := &hgRepo{rep}145 // Do an initial clone.146 err = repo.get(ctx)147 if err != nil {148 t.Fatalf("Unable to clone Hg repo. Err was %s", err)149 }150 // Verify Hg repo is a Hg repo151 if !repo.CheckLocal() {152 t.Fatal("Problem checking out repo or Hg CheckLocal is not working")153 }154 // Set the version using the short hash.155 err = repo.updateVersion(ctx, "a5494ba2177f")156 if err != nil {157 t.Fatalf("Unable to update Hg repo version. Err was %s", err)158 }159 // Use Version to verify we are on the right version.160 v, err := repo.Version()161 if err != nil {162 t.Fatal(err)163 }164 if v != "a5494ba2177ff9ef26feb3c155dfecc350b1a8ef" {165 t.Fatalf("Error checking checked out Hg version: %s", v)166 }167 // Perform an update.168 err = repo.fetch(ctx)169 if err != nil {170 t.Fatal(err)171 }172}173func testGitRepo(t *testing.T) {174 t.Parallel()175 if testing.Short() {176 t.Skip("Skipping slow test in short mode")177 }178 ctx := context.Background()179 tempDir, err := ioutil.TempDir("", "go-vcs-git-tests")180 if err != nil {181 t.Fatal(err)182 }183 defer func() {184 err = os.RemoveAll(tempDir)185 if err != nil {186 t.Error(err)187 }188 }()189 rep, err := vcs.NewGitRepo(gitRemoteTestRepo, tempDir+"/VCSTestRepo")190 if err != nil {191 t.Fatal(err)192 }193 repo := &gitRepo{rep}194 // Do an initial clone.195 err = repo.get(ctx)196 if err != nil {197 t.Fatalf("Unable to clone Git repo. Err was %s", err)198 }199 // Verify Git repo is a Git repo200 if !repo.CheckLocal() {201 t.Fatal("Problem checking out repo or Git CheckLocal is not working")202 }203 // Perform an update.204 err = repo.fetch(ctx)205 if err != nil {206 t.Fatal(err)207 }208 v, err := repo.Current()209 if err != nil {210 t.Fatalf("Error trying Git Current: %s", err)211 }212 if v != "master" {213 t.Fatalf("Current failed to detect Git on tip of master. Got version: %s", v)214 }215 // Set the version using the short hash.216 err = repo.updateVersion(ctx, "806b07b")217 if err != nil {218 t.Fatalf("Unable to update Git repo version. Err was %s", err)219 }220 // Once a ref has been checked out the repo is in a detached head state.221 // Trying to pull in an update in this state will cause an error. Update222 // should cleanly handle this. Pulling on a branch (tested elsewhere) and223 // skipping that here.224 err = repo.fetch(ctx)225 if err != nil {226 t.Fatal(err)227 }228 // Use Version to verify we are on the right version.229 v, err = repo.Version()230 if err != nil {231 t.Fatal(err)232 }233 if v != "806b07b08faa21cfbdae93027904f80174679402" {234 t.Fatal("Error checking checked out Git version")235 }236}237func testBzrRepo(t *testing.T) {238 t.Parallel()239 if testing.Short() {240 t.Skip("Skipping slow test in short mode")241 }242 ctx := context.Background()243 tempDir, err := ioutil.TempDir("", "go-vcs-bzr-tests")244 if err != nil {245 t.Fatal(err)246 }247 defer func() {248 err = os.RemoveAll(tempDir)249 if err != nil {250 t.Error(err)251 }252 }()253 rep, err := vcs.NewBzrRepo("https://launchpad.net/govcstestbzrrepo", tempDir+"/govcstestbzrrepo")254 if err != nil {255 t.Fatal(err)256 }257 repo := &bzrRepo{rep}258 // Do an initial clone.259 err = repo.get(ctx)260 if err != nil {261 t.Fatalf("Unable to clone Bzr repo. Err was %s", err)262 }263 // Verify Bzr repo is a Bzr repo264 if !repo.CheckLocal() {265 t.Fatal("Problem checking out repo or Bzr CheckLocal is not working")266 }267 v, err := repo.Current()268 if err != nil {269 t.Fatalf("Error trying Bzr Current: %s", err)270 }271 if v != "-1" {272 t.Fatalf("Current failed to detect Bzr on tip of branch. Got version: %s", v)273 }274 err = repo.updateVersion(ctx, "2")275 if err != nil {276 t.Fatalf("Unable to update Bzr repo version. Err was %s", err)277 }278 // Use Version to verify we are on the right version.279 v, err = repo.Version()280 if err != nil {281 t.Fatal(err)282 }283 if v != "2" {284 t.Fatal("Error checking checked out Bzr version")285 }286 v, err = repo.Current()287 if err != nil {288 t.Fatalf("Error trying Bzr Current: %s", err)289 }290 if v != "2" {291 t.Fatalf("Current failed to detect Bzr on rev 2 of branch. Got version: %s", v)292 }293}...
TestGitRepo
Using AI Code Generation
1func main() {2 v := vcs.VCS{}3 v.TestGitRepo()4}5func main() {6 v := vcs.VCS{}7 v.TestGitRepo()8}9func main() {10 v := vcs.VCS{}11 v.TestGitRepo()12}13func main() {14 v := vcs.VCS{}15 v.TestGitRepo()16}17func main() {18 v := vcs.VCS{}19 v.TestGitRepo()20}21func CloneRepo(url string, path string, branch string) error {22 _, err := git.PlainClone(path, false, &git.CloneOptions{23 ReferenceName: plumbing.ReferenceName(branch),24 })25}
TestGitRepo
Using AI Code Generation
1func main() {2 repo := vcs.TestGitRepo()3 fmt.Println(repo)4}5func main() {6 repo := vcs.TestGitRepo()7 fmt.Println(repo)8}9func main() {10 repo := vcs.TestGitRepo()11 fmt.Println(repo)12}13func main() {14 repo := vcs.TestGitRepo()15 fmt.Println(repo)16}17func main() {18 repo := vcs.TestGitRepo()19 fmt.Println(repo)20}21func main() {22 repo := vcs.TestGitRepo()23 fmt.Println(repo)24}25func main() {26 repo := vcs.TestGitRepo()27 fmt.Println(repo)28}29func main() {30 repo := vcs.TestGitRepo()31 fmt.Println(repo)32}33func main() {34 repo := vcs.TestGitRepo()35 fmt.Println(repo)36}37func main() {38 repo := vcs.TestGitRepo()39 fmt.Println(repo)40}41func main() {42 repo := vcs.TestGitRepo()43 fmt.Println(repo)44}45func main() {46 repo := vcs.TestGitRepo()47 fmt.Println(repo)48}49func main() {50 repo := vcs.TestGitRepo()51 fmt.Println(repo)52}
TestGitRepo
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello World!")4 vcs.TestGitRepo()5}6import (7func TestGitRepo() {8 fmt.Println("Hello World! from vcs package")9}10import (11func main() {12 fmt.Println("Hello World!")13 mylib.Test()14}15import (16func Test() {17 fmt.Println("Hello World! from mylib package")18}
TestGitRepo
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 fmt.Println(golenv.VCS_REPO_DIR)5 golgit.TestGitRepo()6}7import (8func main() {9 fmt.Println("Hello, playground")10 fmt.Println(golenv.VCS_REPO_DIR)11 golgit.TestGitRepo()12}13import (14func main() {15 fmt.Println("Hello, playground")16 fmt.Println(golenv.VCS_REPO_DIR)17 golgit.TestGitRepo()18}19import (20func main() {21 fmt.Println("Hello, playground")22 fmt.Println(golenv.VCS_REPO_DIR)23 golgit.TestGitRepo()24}25import (26func main() {27 fmt.Println("Hello, playground")28 fmt.Println(golenv.VCS_REPO_DIR)29 golgit.TestGitRepo()30}31import (32func main() {33 fmt.Println("Hello, playground")34 fmt.Println(golenv.VCS_REPO_DIR)35 golgit.TestGitRepo()36}
TestGitRepo
Using AI Code Generation
1import (2func main() {3 vcs.TestGitRepo()4 fmt.Println("Hello, playground")5}6import (7func main() {8 vcs.TestGitRepo()9 fmt.Println("Hello, playground")10}11import (12func main() {13 vcs.TestGitRepo()14 fmt.Println("Hello, playground")15}16import (17func main() {18 vcs.TestGitRepo()19 fmt.Println("Hello, playground")20}21import (22func main() {23 vcs.TestGitRepo()24 fmt.Println("Hello, playground")25}26import (27func main() {28 vcs.TestGitRepo()29 fmt.Println("Hello, playground")30}31import (32func main() {33 vcs.TestGitRepo()34 fmt.Println("Hello, playground")35}36import (37func main() {38 vcs.TestGitRepo()39 fmt.Println("Hello, playground")40}41import (42func main() {43 vcs.TestGitRepo()44 fmt.Println("Hello, playground")45}46import (47func main() {
TestGitRepo
Using AI Code Generation
1import (2func main() {3 v := new(writ.VCS)4 v.TestGitRepo()5 fmt.Println("Done")6}
TestGitRepo
Using AI Code Generation
1import "fmt"2import "git.vcs"3func main() {4vcs.Init("/home/abhishek/go/src/git.vcs")5vcs.TestGitRepo()6}7import (8type Vcs struct {9}10func (vcs *Vcs) Init(path string) {11}12func (vcs *Vcs) TestGitRepo() {13 cmd := exec.Command("git", "rev-parse", "--show-toplevel")14 out, err := cmd.CombinedOutput()15 if err != nil {16 fmt.Printf("Error: %s17 }18 fmt.Printf("Output: %s19}20I am not sure what I am missing here. I have tried to import the package using the following syntaxes:21import "git.vcs"22import "vcs"23I have also tried to use the following syntax to import the package:24import (25import (26func main() {27 if len(os.Args) != 2 {28 fmt.Println("Usage: ", os.Args[0], "watchfile")29 os.Exit(1)30 }31 if _, err := os.Stat(watchfile); err != nil {32 fmt.Println("Error: ", err)33 os.Exit(1)34 }
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!!