Skip to content

Commit

Permalink
Fix linter warnings and add GitHub Actions test
Browse files Browse the repository at this point in the history
  • Loading branch information
SKevo18 authored Mar 22, 2024
2 parents 78a07d7 + c6cb0f4 commit d88b4f3
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Go Test

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
name: Run Tests
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.20'

- name: Install dependencies
run: go mod download

- name: Run tests
run: go test -v ./...
2 changes: 1 addition & 1 deletion corediff.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func saveDB(path string, db hashDB) {
}
}

func parseFile(path, relPath string, db hashDB, updateDB bool) (hits []int, lines [][]byte) {
func parseFile(path, _ string, db hashDB, updateDB bool) (hits []int, lines [][]byte) {
fh, err := os.Open(path)
if os.IsNotExist(err) {
logInfo(warn("file does not exist: " + path))
Expand Down
2 changes: 1 addition & 1 deletion corediff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ func Test_Corruption(t *testing.T) {
if err := scanner.Err(); err != nil {
log.Fatal(err)
}

fmt.Println("lines", len(lines))
}
5 changes: 0 additions & 5 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ func pathExists(p string) bool {
return err == nil
}

func isDir(path string) bool {
fi, err := os.Stat(path)
return err == nil && fi.IsDir()
}

func hasValidExt(path string) bool {
got := strings.TrimLeft(filepath.Ext(path), ".")
for _, want := range scanExts {
Expand Down
3 changes: 0 additions & 3 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package main
import "testing"

func Test_pathIsExcluded(t *testing.T) {
type args struct {
p string
}
tests := []struct {
arg string
want bool
Expand Down
2 changes: 1 addition & 1 deletion needle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Test_Needle(t *testing.T) {
db := loadDB(dbpath)
fmt.Println("Loaded entries:", len(db))

for k, _ := range db {
for k := range db {
fmt.Println("first entry", k)
break
}
Expand Down
7 changes: 0 additions & 7 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ var (

logLevel = 1

globalDB hashDB

buf = make([]byte, 0, maxTokenSize)

scanExts = []string{"php", "phtml", "js", "htaccess", "sh"}
Expand Down Expand Up @@ -96,11 +94,6 @@ func setup() *baseArgs {
args := &baseArgs{}
argParser := flags.NewParser(args, flags.HelpFlag|flags.PrintErrors|flags.PassDoubleDash)
if _, err := argParser.Parse(); err != nil {
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrRequired {
} else {
// log.Fatal(err)
// fmt.Println("Config parse error:", err)
}
os.Exit(1)
}

Expand Down

0 comments on commit d88b4f3

Please sign in to comment.