Skip to content

Commit

Permalink
Handle case of no call expression in config function (#8436)
Browse files Browse the repository at this point in the history
  • Loading branch information
trodge authored Jul 24, 2023
1 parent 2e90d01 commit c9d82af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions tools/missing-test-detector/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ func readConfigFunc(configFunc *ast.FuncDecl) (Step, error) {
for _, stmt := range configFunc.Body.List {
if returnStmt, ok := stmt.(*ast.ReturnStmt); ok {
for _, result := range returnStmt.Results {
if basicLit, ok := result.(*ast.BasicLit); ok && basicLit.Kind == token.STRING {
return readConfigBasicLit(basicLit)
}
if callExpr, ok := result.(*ast.CallExpr); ok {
return readConfigFuncCallExpr(callExpr)
}
Expand All @@ -203,10 +206,8 @@ func readConfigFuncCallExpr(configFuncCallExpr *ast.CallExpr) (Step, error) {
if len(configFuncCallExpr.Args) == 0 {
return nil, fmt.Errorf("no arguments found for call expression %v", configFuncCallExpr)
}
if basicLit, ok := configFuncCallExpr.Args[0].(*ast.BasicLit); ok {
if basicLit.Kind == token.STRING {
return readConfigBasicLit(basicLit)
}
if basicLit, ok := configFuncCallExpr.Args[0].(*ast.BasicLit); ok && basicLit.Kind == token.STRING {
return readConfigBasicLit(basicLit)
} else if nestedCallExpr, ok := configFuncCallExpr.Args[0].(*ast.CallExpr); ok {
return readConfigFuncCallExpr(nestedCallExpr)
}
Expand Down
4 changes: 2 additions & 2 deletions tools/missing-test-detector/testdata/covered_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resource "covered_resource" "resource" {
}

func testAccCoveredResource_update() string {
return acctest.Nprintf(`
return `
resource "covered_resource" "resource" {
field_two {
field_three = "value-two"
Expand All @@ -47,5 +47,5 @@ resource "covered_resource" "resource" {
}
}
}
`, context)
`
}

0 comments on commit c9d82af

Please sign in to comment.