Skip to content

Commit

Permalink
Merge pull request #16214 from github/mbg/go/use-shared-integration-t…
Browse files Browse the repository at this point in the history
…est-code

Go: Use shared integration test code
  • Loading branch information
mbg authored Apr 15, 2024
2 parents a99849d + 7a0aad8 commit ce73c29
Show file tree
Hide file tree
Showing 31 changed files with 104 additions and 418 deletions.
15 changes: 8 additions & 7 deletions go/integration-tests-lib/go_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
from create_database_utils import *
from diagnostics_test_utils import *

def go_integration_test(source = "src"):
def go_integration_test(source = "src", db = "db", runFunction = runSuccessfully):
# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath

run_codeql_database_create([], lang="go", source=source)
try:
run_codeql_database_create([], lang="go", source=source, db=db, runFunction=runFunction)

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
check_diagnostics()
finally:
# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
20 changes: 2 additions & 18 deletions go/ql/integration-tests/all-platforms/go/bazel-sample-1/test.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
import os
import subprocess
from go_integration_test import *

from create_database_utils import *
from diagnostics_test_utils import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath

run_codeql_database_create([], lang="go", source="src")

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test()
20 changes: 2 additions & 18 deletions go/ql/integration-tests/all-platforms/go/bazel-sample-2/test.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
import os
import subprocess
from go_integration_test import *

from create_database_utils import *
from diagnostics_test_utils import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath

run_codeql_database_create([], lang="go", source="src")

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test()
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import os
import subprocess

from create_database_utils import *
from diagnostics_test_utils import *
from go_integration_test import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
run_codeql_database_create([], lang="go", source="work", db=None)

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test(source="work", db=None)
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import os
import subprocess

from create_database_utils import *
from diagnostics_test_utils import *
from go_integration_test import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
run_codeql_database_create([], lang="go", source="work")

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test(source="work")
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import os
import subprocess

from create_database_utils import *
from diagnostics_test_utils import *
from go_integration_test import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
run_codeql_database_create([], lang="go", source="src")

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test()
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import os
import subprocess

from create_database_utils import *
from diagnostics_test_utils import *
from go_integration_test import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
run_codeql_database_create([], lang="go", source="work", db=None, runFunction=runUnsuccessfully)

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test(source="work", db=None, runFunction=runUnsuccessfully)
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import os
import subprocess

from create_database_utils import *
from diagnostics_test_utils import *
from go_integration_test import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
run_codeql_database_create([], lang="go", source="work", db=None, runFunction=runUnsuccessfully)

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test(source="work", db=None, runFunction=runUnsuccessfully)
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import os
import subprocess

from create_database_utils import *
from diagnostics_test_utils import *
from go_integration_test import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
run_codeql_database_create([], lang="go", source="work", db=None)

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test(source="work", db=None)
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import os
import subprocess

from create_database_utils import *
from diagnostics_test_utils import *
from go_integration_test import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
run_codeql_database_create([], lang="go", source="work", db=None)

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test(source="work", db=None)
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import os
import subprocess

from create_database_utils import *
from diagnostics_test_utils import *
from go_integration_test import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
os.environ['GITHUB_REPOSITORY'] = "a/b"
run_codeql_database_create([], lang="go", source="work", db=None)

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test(source="work", db=None)
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
import os
import subprocess
from go_integration_test import *

from create_database_utils import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
run_codeql_database_create([], lang="go", source="src")

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"markdownMessage": "A single `go.mod` file was found.\n\n`go.mod`",
"severity": "note",
"source": {
"extractorName": "go",
"id": "go/autobuilder/single-root-go-mod-found",
"name": "A single `go.mod` file was found in the root"
},
"visibility": {
"cliSummaryTable": false,
"statusPage": false,
"telemetry": true
}
}
16 changes: 2 additions & 14 deletions go/ql/integration-tests/all-platforms/go/go-mod-sample/test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
import os
import subprocess
from go_integration_test import *

from create_database_utils import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
run_codeql_database_create([], lang="go", source="src")

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test()
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
import os
import subprocess
from go_integration_test import *

from create_database_utils import *
from diagnostics_test_utils import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
run_codeql_database_create([], lang="go", source="src")

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test()
19 changes: 2 additions & 17 deletions go/ql/integration-tests/all-platforms/go/go-version-bump/test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
import os
import subprocess
from go_integration_test import *

from create_database_utils import *
from diagnostics_test_utils import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
run_codeql_database_create([], lang="go", source="src")

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"markdownMessage": "A single `go.mod` file was found.\n\n`go.mod`",
"severity": "note",
"source": {
"extractorName": "go",
"id": "go/autobuilder/single-root-go-mod-found",
"name": "A single `go.mod` file was found in the root"
},
"visibility": {
"cliSummaryTable": false,
"statusPage": false,
"telemetry": true
}
}
16 changes: 2 additions & 14 deletions go/ql/integration-tests/all-platforms/go/make-sample/test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
import os
import subprocess
from go_integration_test import *

from create_database_utils import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
run_codeql_database_create([], lang="go", source="src")

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test()
19 changes: 2 additions & 17 deletions go/ql/integration-tests/all-platforms/go/mixed-layout/test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
import os
import subprocess
from go_integration_test import *

from create_database_utils import *
from diagnostics_test_utils import *

# Set up a GOPATH relative to this test's root directory;
# we set os.environ instead of using extra_env because we
# need it to be set for the call to "go clean -modcache" later
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
os.environ['GOPATH'] = goPath
run_codeql_database_create([], lang="go", source="src")

check_diagnostics()

# Clean up the temporary GOPATH to prevent Bazel failures next
# time the tests are run; see https://github.com/golang/go/issues/27161
subprocess.call(["go", "clean", "-modcache"])
go_integration_test()
Loading

0 comments on commit ce73c29

Please sign in to comment.