Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: run-tests

on:
push:
branches: [master]
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{github.event.pull_request.head.sha}}

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23

- name: Report test coverage results to DeepSource
run: |
# Run test commands
go test ./... -v -race -cover -coverprofile=cover.out -covermode=atomic
go tool cover -html=cover.out -o coverage.html

# Install deepsource CLI
curl https://deepsource.io/cli | sh

# Run the report coverage command from the root directory
./bin/deepsource report --analyzer test-coverage --key go --value-file ./coverage.html
env:
DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}

2 changes: 1 addition & 1 deletion checkers/discover/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// We use go.mod.embed because embedding is not supported for go.mod files
//
//go:embed custom_analyzer_stub/*.go custom_analyzer_stub/go.mod.embed custom_analyzer_stub/go.sum.embed
//go:embed custom_analyzer_stub/go.mod.embed custom_analyzer_stub/go.sum.embed custom_analyzer_stub/main.go.embed
var AnalyzerStubs embed.FS

// Copy all the files from the source directory to the destination directory
Expand Down
4 changes: 3 additions & 1 deletion checkers/discover/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestGenerateAnalyzerRegistry(t *testing.T) {

import (
"globstar.dev/analysis"
"globstar.dev/customanalyzer/checkers"
)

var customCheckers []*analysis.Analyzer = []*analysis.Analyzer{}`,
Expand All @@ -26,6 +27,7 @@ var customCheckers []*analysis.Analyzer = []*analysis.Analyzer{}`,

import (
"globstar.dev/analysis"
"globstar.dev/customanalyzer/checkers"
)

var customCheckers []*analysis.Analyzer = []*analysis.Analyzer{
Expand All @@ -37,7 +39,7 @@ var customCheckers []*analysis.Analyzer = []*analysis.Analyzer{
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := generateAnalyzerRegistry(tt.goCheckers); got != tt.want {
t.Errorf("generateAnalyzerRegistry() = %v, want %v", got, tt.want)
t.Errorf("generateAnalyzerRegistry() = \n%v, want \n%v", got, tt.want)
}
})
}
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/cgi_import.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way to do these exclusions instead of having to add them in every checker?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can place test files inside a folder prefixed with an underscore (e.g., _testdata). However, the YAML test runner currently only looks for tests in the current directory. Once we add support for test folders in YAML-based checkers, we can remove the exclusion directives.


package main

import (
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/des_weak_crypto.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

import (
"crypto/des"
)
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/fmt_print_in_prod.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

// <expect-error>
fmt.Print()

Expand Down
2 changes: 2 additions & 0 deletions checkers/go/grpc_client_insecure_tls.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

func unsafe() {
// <expect-error> insecure grpc dial
conn, err := grpc.Dial(address, grpc.WithInsecure())
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/grpc_server_insecure_tls.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

func unsafe() {
// <expect-error> insecure grpc tls server
s := grpc.NewServer()
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/html_req_template_injection.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

import (
"fmt"
"net/http"
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/http_file_server.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/insecure_cookie.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

// <expect-error>
http.SetCookie(&http.Cookie{
Name: "session",
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/jwt_harcoded_signing_key.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

import (
"fmt"
"log"
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/jwt_none_algorithm.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/math_rand.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/md5_weak_hash.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

import (
// <expect-error> Weak hash function used
"crypto/md5" // UNSAFE: Weak hash function
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/missing_error_file_open.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

import (
"fmt"
"os"
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/mysql_conn_raw_passwd.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

import (
"database/sql"
"fmt"
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/net_bind_all_interfaces.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

func bind_all() {
// <expect-error> Bind to all interfaces
l, err := net.Listen("tcp", ":2000")
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/os_create_file_default_permission.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

import (
"fmt"
"os"
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/postgres_config_raw_passwd.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

import (
"fmt"
"os"
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/postgres_conn_raw_passwd.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

import (
"database/sql"
"fmt"
Expand Down
1 change: 1 addition & 0 deletions checkers/go/pprof_endpoint_automatic_exposure.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build exclude

import (
"fmt"
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/reflect_pkg.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

import (
"fmt"

Expand Down
2 changes: 2 additions & 0 deletions checkers/go/samesite_cookie.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

import (
"fmt"
"net/http"
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/sha1_weak_hash.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions checkers/go/tls_config_minver.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build exclude

import (
"crypto/tls"
"fmt"
Expand Down
1 change: 1 addition & 0 deletions checkers/go/tls_insecure.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build exclude

import (
"crypto/tls"
Expand Down
1 change: 1 addition & 0 deletions checkers/go/unsafe_pkg.test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build exclude

import (
"fmt"
Expand Down
Loading