Skip to content

Commit 257436a

Browse files
committed
Convert test to inline expectation test
1 parent 4797491 commit 257436a

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
| test.go:12:10:12:26 | call to Getenv |
2-
| test.go:14:2:14:33 | ... := ...[0] |
3-
| test.go:19:20:19:31 | call to Environ |
4-
| test.go:34:29:34:32 | &... |
5-
| test.go:41:2:41:40 | ... := ...[0] |
6-
| test.go:48:2:48:52 | ... := ...[0] |
7-
| test.go:61:2:61:33 | ... := ...[0] |
1+
testFailures
2+
invalidModelRow
3+
failures

go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/environment/test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99
)
1010

1111
func osEnvironmentVariables() {
12-
home := os.Getenv("HOME")
12+
home := os.Getenv("HOME") // $ source
1313

14-
port, ok := os.LookupEnv("PORT")
14+
port, ok := os.LookupEnv("PORT") // $ source
1515
if !ok {
1616
port = "3000"
1717
}
1818

19-
for _, e := range os.Environ() {
19+
for _, e := range os.Environ() { // $ source
2020
_ = e
2121
}
2222

@@ -31,21 +31,21 @@ type ServerConfig struct {
3131

3232
func envconfigEnvironmentVariables() {
3333
var cfg ServerConfig
34-
envconfig.Process("myapp", &cfg)
34+
envconfig.Process("myapp", &cfg) // $ source
3535
}
3636

3737
func godotenvEnvironmentVariables() {
3838
var err error
3939
var username, greeting string
4040

41-
users, err := godotenv.Read("user.env")
41+
users, err := godotenv.Read("user.env") // $ source
4242
if err != nil {
4343
return
4444
}
4545

4646
username = users["USERNAME"]
4747

48-
greetings, err := godotenv.Unmarshal("HELLO=hello")
48+
greetings, err := godotenv.Unmarshal("HELLO=hello") // $ source
4949
if err != nil {
5050
return
5151
}
@@ -61,7 +61,7 @@ func envparseEnvironmentVariables() {
6161
return
6262
}
6363
defer f.Close()
64-
envVars, err := envparse.Parse(f)
64+
envVars, err := envparse.Parse(f) // $ source
6565

6666
if err != nil {
6767
return
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import go
2+
import ModelValidation
3+
import TestUtilities.InlineExpectationsTest
24

3-
from DataFlow::Node source
4-
where source instanceof ThreatModelFlowSource
5-
select source
5+
module SourceTest implements TestSig {
6+
string getARelevantTag() { result = "source" }
7+
8+
predicate hasActualResult(Location location, string element, string tag, string value) {
9+
exists(ThreatModelFlowSource s |
10+
s.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
11+
location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and
12+
element = s.toString() and
13+
value = "" and
14+
tag = "source"
15+
)
16+
}
17+
}
18+
19+
import MakeTest<SourceTest>

0 commit comments

Comments
 (0)