Skip to content

Commit ce73c29

Browse files
authored
Merge pull request #16214 from github/mbg/go/use-shared-integration-test-code
Go: Use shared integration test code
2 parents a99849d + 7a0aad8 commit ce73c29

File tree

31 files changed

+104
-418
lines changed

31 files changed

+104
-418
lines changed

go/integration-tests-lib/go_integration_test.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
from create_database_utils import *
33
from diagnostics_test_utils import *
44

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

12-
run_codeql_database_create([], lang="go", source=source)
12+
try:
13+
run_codeql_database_create([], lang="go", source=source, db=db, runFunction=runFunction)
1314

14-
check_diagnostics()
15-
16-
# Clean up the temporary GOPATH to prevent Bazel failures next
17-
# time the tests are run; see https://github.com/golang/go/issues/27161
18-
subprocess.call(["go", "clean", "-modcache"])
15+
check_diagnostics()
16+
finally:
17+
# Clean up the temporary GOPATH to prevent Bazel failures next
18+
# time the tests are run; see https://github.com/golang/go/issues/27161
19+
subprocess.call(["go", "clean", "-modcache"])
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
import os
2-
import subprocess
1+
from go_integration_test import *
32

4-
from create_database_utils import *
5-
from diagnostics_test_utils import *
6-
7-
# Set up a GOPATH relative to this test's root directory;
8-
# we set os.environ instead of using extra_env because we
9-
# need it to be set for the call to "go clean -modcache" later
10-
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
11-
os.environ['GOPATH'] = goPath
12-
13-
run_codeql_database_create([], lang="go", source="src")
14-
15-
check_diagnostics()
16-
17-
# Clean up the temporary GOPATH to prevent Bazel failures next
18-
# time the tests are run; see https://github.com/golang/go/issues/27161
19-
subprocess.call(["go", "clean", "-modcache"])
3+
go_integration_test()
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
import os
2-
import subprocess
1+
from go_integration_test import *
32

4-
from create_database_utils import *
5-
from diagnostics_test_utils import *
6-
7-
# Set up a GOPATH relative to this test's root directory;
8-
# we set os.environ instead of using extra_env because we
9-
# need it to be set for the call to "go clean -modcache" later
10-
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
11-
os.environ['GOPATH'] = goPath
12-
13-
run_codeql_database_create([], lang="go", source="src")
14-
15-
check_diagnostics()
16-
17-
# Clean up the temporary GOPATH to prevent Bazel failures next
18-
# time the tests are run; see https://github.com/golang/go/issues/27161
19-
subprocess.call(["go", "clean", "-modcache"])
3+
go_integration_test()
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import os
2-
import subprocess
32

4-
from create_database_utils import *
5-
from diagnostics_test_utils import *
3+
from go_integration_test import *
64

7-
# Set up a GOPATH relative to this test's root directory;
8-
# we set os.environ instead of using extra_env because we
9-
# need it to be set for the call to "go clean -modcache" later
10-
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
11-
os.environ['GOPATH'] = goPath
125
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
13-
run_codeql_database_create([], lang="go", source="work", db=None)
14-
15-
check_diagnostics()
16-
17-
# Clean up the temporary GOPATH to prevent Bazel failures next
18-
# time the tests are run; see https://github.com/golang/go/issues/27161
19-
subprocess.call(["go", "clean", "-modcache"])
6+
go_integration_test(source="work", db=None)
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import os
2-
import subprocess
32

4-
from create_database_utils import *
5-
from diagnostics_test_utils import *
3+
from go_integration_test import *
64

7-
# Set up a GOPATH relative to this test's root directory;
8-
# we set os.environ instead of using extra_env because we
9-
# need it to be set for the call to "go clean -modcache" later
10-
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
11-
os.environ['GOPATH'] = goPath
125
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
13-
run_codeql_database_create([], lang="go", source="work")
14-
15-
check_diagnostics()
16-
17-
# Clean up the temporary GOPATH to prevent Bazel failures next
18-
# time the tests are run; see https://github.com/golang/go/issues/27161
19-
subprocess.call(["go", "clean", "-modcache"])
6+
go_integration_test(source="work")
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import os
2-
import subprocess
32

4-
from create_database_utils import *
5-
from diagnostics_test_utils import *
3+
from go_integration_test import *
64

7-
# Set up a GOPATH relative to this test's root directory;
8-
# we set os.environ instead of using extra_env because we
9-
# need it to be set for the call to "go clean -modcache" later
10-
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
11-
os.environ['GOPATH'] = goPath
125
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
13-
run_codeql_database_create([], lang="go", source="src")
14-
15-
check_diagnostics()
16-
17-
# Clean up the temporary GOPATH to prevent Bazel failures next
18-
# time the tests are run; see https://github.com/golang/go/issues/27161
19-
subprocess.call(["go", "clean", "-modcache"])
6+
go_integration_test()
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import os
2-
import subprocess
32

4-
from create_database_utils import *
5-
from diagnostics_test_utils import *
3+
from go_integration_test import *
64

7-
# Set up a GOPATH relative to this test's root directory;
8-
# we set os.environ instead of using extra_env because we
9-
# need it to be set for the call to "go clean -modcache" later
10-
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
11-
os.environ['GOPATH'] = goPath
125
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
13-
run_codeql_database_create([], lang="go", source="work", db=None, runFunction=runUnsuccessfully)
14-
15-
check_diagnostics()
16-
17-
# Clean up the temporary GOPATH to prevent Bazel failures next
18-
# time the tests are run; see https://github.com/golang/go/issues/27161
19-
subprocess.call(["go", "clean", "-modcache"])
6+
go_integration_test(source="work", db=None, runFunction=runUnsuccessfully)
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import os
2-
import subprocess
32

4-
from create_database_utils import *
5-
from diagnostics_test_utils import *
3+
from go_integration_test import *
64

7-
# Set up a GOPATH relative to this test's root directory;
8-
# we set os.environ instead of using extra_env because we
9-
# need it to be set for the call to "go clean -modcache" later
10-
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
11-
os.environ['GOPATH'] = goPath
125
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
13-
run_codeql_database_create([], lang="go", source="work", db=None, runFunction=runUnsuccessfully)
14-
15-
check_diagnostics()
16-
17-
# Clean up the temporary GOPATH to prevent Bazel failures next
18-
# time the tests are run; see https://github.com/golang/go/issues/27161
19-
subprocess.call(["go", "clean", "-modcache"])
6+
go_integration_test(source="work", db=None, runFunction=runUnsuccessfully)
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import os
2-
import subprocess
32

4-
from create_database_utils import *
5-
from diagnostics_test_utils import *
3+
from go_integration_test import *
64

7-
# Set up a GOPATH relative to this test's root directory;
8-
# we set os.environ instead of using extra_env because we
9-
# need it to be set for the call to "go clean -modcache" later
10-
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
11-
os.environ['GOPATH'] = goPath
125
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
13-
run_codeql_database_create([], lang="go", source="work", db=None)
14-
15-
check_diagnostics()
16-
17-
# Clean up the temporary GOPATH to prevent Bazel failures next
18-
# time the tests are run; see https://github.com/golang/go/issues/27161
19-
subprocess.call(["go", "clean", "-modcache"])
6+
go_integration_test(source="work", db=None)
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import os
2-
import subprocess
32

4-
from create_database_utils import *
5-
from diagnostics_test_utils import *
3+
from go_integration_test import *
64

7-
# Set up a GOPATH relative to this test's root directory;
8-
# we set os.environ instead of using extra_env because we
9-
# need it to be set for the call to "go clean -modcache" later
10-
goPath = os.path.join(os.path.abspath(os.getcwd()), ".go")
11-
os.environ['GOPATH'] = goPath
125
os.environ['LGTM_INDEX_IMPORT_PATH'] = "test"
13-
run_codeql_database_create([], lang="go", source="work", db=None)
14-
15-
check_diagnostics()
16-
17-
# Clean up the temporary GOPATH to prevent Bazel failures next
18-
# time the tests are run; see https://github.com/golang/go/issues/27161
19-
subprocess.call(["go", "clean", "-modcache"])
6+
go_integration_test(source="work", db=None)

0 commit comments

Comments
 (0)