| 1 | package thirdpartyscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/ |
| 2 | |
| 3 | import ( |
| 4 | "flagscip-go gomod github.com/golang/go/src go1.18 flag/" |
| 5 | "osscip-go gomod github.com/golang/go/src go1.18 os/" |
| 6 | "os/execscip-go gomod github.com/golang/go/src go1.18 `os/exec`/" |
| 7 | "path/filepathscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/" |
| 8 | "runtimescip-go gomod github.com/golang/go/src go1.18 runtime/" |
| 9 | "testingscip-go gomod github.com/golang/go/src go1.18 testing/" |
| 10 | |
| 11 | "github.com/mmcloughlin/avo/internal/testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/test`/" |
| 12 | ) |
| 13 | |
| 14 | //go:generate go run make_workflow.go -suite suite.json -output ../../.github/workflows/packages.yml |
| 15 | |
| 16 | // Custom flags. |
| 17 | var ( |
| 18 | suitefilenamescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/suitefilename. = flagscip-go gomod github.com/golang/go/src go1.18 flag/.Stringscip-go gomod github.com/golang/go/src go1.18 flag/String().("suite", "", "projects configuration") |
| 19 | preservescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/preserve. = flagscip-go gomod github.com/golang/go/src go1.18 flag/.Boolscip-go gomod github.com/golang/go/src go1.18 flag/Bool().("preserve", false, "preserve working directories") |
| 20 | latestscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/latest. = flagscip-go gomod github.com/golang/go/src go1.18 flag/.Boolscip-go gomod github.com/golang/go/src go1.18 flag/Bool().("latest", false, "use latest versions of each project") |
| 21 | ) |
| 22 | |
| 23 | // TestPackages runs integration tests on all packages specified by projects |
| 24 | // file given on the command line. |
| 25 | func TestPackagesscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/TestPackages().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 26 | // Load suite. |
| 27 | if *suitefilenamescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/suitefilename. == "" { |
| 28 | t.Skipscip-go gomod github.com/golang/go/src go1.18 testing/common#Skip().("no suite specified") |
| 29 | } |
| 30 | |
| 31 | s, err := LoadSuiteFilescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/LoadSuiteFile().(*suitefilenamescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/suitefilename.) |
| 32 | if err != nil { |
| 33 | t.Fatalscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatal().(err) |
| 34 | } |
| 35 | |
| 36 | for _, tst := range s.Projectsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Suite#Projects..Testsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Projects#Tests().() { |
| 37 | tst := tst // scopelint |
| 38 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(tst.IDscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#ID().(), func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 39 | if tst.Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Project..Skipscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Skip().() { |
| 40 | t.Skipfscip-go gomod github.com/golang/go/src go1.18 testing/common#Skipf().("skip: %s", tst.Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Project..Reasonscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Reason().()) |
| 41 | } |
| 42 | dir, clean := testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/test`/.TempDirscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/test`/TempDir().(t) |
| 43 | if !*preservescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/preserve. { |
| 44 | defer clean() |
| 45 | } else { |
| 46 | t.Logfscip-go gomod github.com/golang/go/src go1.18 testing/common#Logf().("working directory: %s", dir) |
| 47 | } |
| 48 | pt := PackageTestscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#{ |
| 49 | Tscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#T.: t, |
| 50 | Testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#Test.: tst, |
| 51 | WorkDirscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#WorkDir.: dir, |
| 52 | Latestscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#Latest.: *latestscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/latest., |
| 53 | } |
| 54 | pt.Runscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#Run().() |
| 55 | }) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // PackageTest executes an integration test based on a given third-party package. |
| 60 | type PackageTestscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest# struct { |
| 61 | *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#T. |
| 62 | *Testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#Test. |
| 63 | |
| 64 | WorkDirscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#WorkDir. string // working directory for the test |
| 65 | Latestscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#Latest. bool // use latest version of the project |
| 66 | |
| 67 | repopathscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#repopath. string // path the repo is cloned to |
| 68 | } |
| 69 | |
| 70 | // Run the test. |
| 71 | func (t *PackageTestscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#) Runscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#Run().() { |
| 72 | t.checkoutscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#checkout().() |
| 73 | t.validatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#validate().() |
| 74 | t.stepsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#steps().() |
| 75 | } |
| 76 | |
| 77 | // checkout the code at the specified version. |
| 78 | func (t *PackageTestscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#) checkoutscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#checkout().() { |
| 79 | // Determine the version we want to checkout. |
| 80 | version := t.Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Project..Versionscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Version. |
| 81 | if t.Latestscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#Latest. { |
| 82 | version = t.Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Project..DefaultBranchscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#DefaultBranch. |
| 83 | } |
| 84 | |
| 85 | // Clone. Use a shallow clone to speed up large repositories. |
| 86 | t.repopathscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#repopath. = filepathscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/Join().(t.WorkDirscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#WorkDir., t.Namescip-go gomod github.com/golang/go/src go1.18 testing/common#Name().()) |
| 87 | testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/test`/.Execscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/test`/Exec().(t.Tscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#T., "git", "init", t.repopathscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#repopath.) |
| 88 | testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/test`/.Execscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/test`/Exec().(t.Tscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#T., "git", "-C", t.repopathscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#repopath., "remote", "add", "origin", t.Projectscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Project..Repositoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Project#Repository..CloneURLscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/GithubRepository#CloneURL().()) |
| 89 | testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/test`/.Execscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/test`/Exec().(t.Tscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#T., "git", "-C", t.repopathscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#repopath., "fetch", "--depth=1", "origin", version) |
| 90 | testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/test`/.Execscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/test`/Exec().(t.Tscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#T., "git", "-C", t.repopathscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#repopath., "checkout", "FETCH_HEAD") |
| 91 | } |
| 92 | |
| 93 | // validate the test configuration relative to the checked out project. |
| 94 | func (t *PackageTestscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#) validatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#validate().() { |
| 95 | // Confirm expected directories exist. |
| 96 | expect := map[string]string{ |
| 97 | "package": t.Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Package..SubPackagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#SubPackage., |
| 98 | "root": t.Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Package..WorkingDirectoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#WorkingDirectory().(), |
| 99 | } |
| 100 | for name, subdir := range expect { |
| 101 | if subdir == "" { |
| 102 | continue |
| 103 | } |
| 104 | path := filepathscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/Join().(t.repopathscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#repopath., subdir) |
| 105 | if _, err := osscip-go gomod github.com/golang/go/src go1.18 os/.Statscip-go gomod github.com/golang/go/src go1.18 os/Stat().(path); err != nil { |
| 106 | t.Fatalfscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatalf().("expected %s directory: %s", name, err) |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | func (t *PackageTestscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#) stepsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#steps().() { |
| 112 | // Determine the path to avo. |
| 113 | _, self, _, ok := runtimescip-go gomod github.com/golang/go/src go1.18 runtime/.Callerscip-go gomod github.com/golang/go/src go1.18 runtime/Caller().(1) |
| 114 | if !ok { |
| 115 | t.Fatalscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatal().("failed to determine path to avo") |
| 116 | } |
| 117 | avodir := filepathscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/Join().(filepathscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/Dir().(self), "..", "..") |
| 118 | |
| 119 | // Run steps. |
| 120 | c := &Contextscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Context#{ |
| 121 | AvoDirectoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Context#AvoDirectory.: avodir, |
| 122 | RepositoryDirectoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Context#RepositoryDirectory.: t.repopathscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#repopath., |
| 123 | } |
| 124 | |
| 125 | for _, s := range t.Packagescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Test#Package..Stepsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Package#Steps().(c) { |
| 126 | for _, command := range s.Commandsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#Commands. { |
| 127 | cmd := execscip-go gomod github.com/golang/go/src go1.18 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.18 `os/exec`/Command().("sh", "-c", command) |
| 128 | cmd.Dirscip-go gomod github.com/golang/go/src go1.18 `os/exec`/Cmd#Dir. = filepathscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/Join().(t.repopathscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#repopath., s.WorkingDirectoryscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/Step#WorkingDirectory.) |
| 129 | testscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/test`/.ExecCommandscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/test`/ExecCommand().(t.Tscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/tests/thirdparty`/PackageTest#T., cmd) |
| 130 | } |
| 131 | } |
| 132 | } |