Skip to content

Commit

Permalink
Refactor ExpectedSyms to return bool; document it
Browse files Browse the repository at this point in the history
Document that we are looking for ANY of the expected symbols, and
simplify the code to return bool instead of an error.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jul 11, 2023
1 parent 856a827 commit 869bc3e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
13 changes: 4 additions & 9 deletions goscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,13 @@ func readTable(fileName string) (*gosym.Table, error) {
return symTable, nil
}

// Checks the .gopclntab for the expected list of symbols.
func ExpectedSyms(expectedSyms []string, symTable *gosym.Table) error {
found := false
// Checks that .gopclntab contains any of the expectedSyms.
func ExpectedSyms(expectedSyms []string, symTable *gosym.Table) bool {
for _, s := range expectedSyms {
fn := symTable.LookupFunc(s)
if fn != nil {
found = true
break
return true
}
}
if !found {
return fmt.Errorf("expected symbol(s) %v not found", expectedSyms)
}
return nil
return false
}
4 changes: 2 additions & 2 deletions validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func validateGoSymbols(_ context.Context, _ *v1.TagReference, path string, baton
return nil
}

if err := ExpectedSyms(requiredGolangSymbols, symtable); err != nil {
return fmt.Errorf("go: expected symbols not found for %v: %w", filepath.Base(path), err)
if !ExpectedSyms(requiredGolangSymbols, symtable) {
return fmt.Errorf("go: expected symbols not found for %v", filepath.Base(path))
}
return nil
}
Expand Down

0 comments on commit 869bc3e

Please sign in to comment.