Skip to content
Merged
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
16 changes: 6 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ PACT_CLI_TARGETS := $(TOOLS_BIN)/pact/bin/pact-broker $(TOOLS_BIN)/.pact_$(PACT_
PACT_GO_V := v2.4.1
PACT_GO_LIB_TARGETS := /tmp/.libpact-ffi_$(PACT_GO_V) # Only use a marker file since lib extension is either .so or .dll

SHELL:=env PATH=$(TOOLS_BIN)/go:$(TOOLS_BIN)/pact/bin:$(PATH) $(SHELL)
SHELL:=env PATH=$(TOOLS_BIN)/pact/bin:$(PATH) $(SHELL)

## tools: Install required tooling.
.PHONY: tools
tools: $(TOOLS_BIN)/go $(GOCI_LINT_TARGETS) $(PACT_CLI_TARGETS) $(PACT_GO_LIB_TARGETS)
tools: $(GOCI_LINT_TARGETS) $(PACT_CLI_TARGETS) $(PACT_GO_LIB_TARGETS)

$(TOOLS_BIN):
@mkdir -p $(TOOLS_BIN)
Expand All @@ -31,13 +31,9 @@ $(PACT_CLI_TARGETS): $(TOOLS_BIN)
@cd $(TOOLS_BIN); curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh | PACT_CLI_VERSION=$(PACT_CLI_V) bash; cd ../
@touch $(TOOLS_BIN)/.pact_$(PACT_CLI_V)

$(TOOLS_BIN)/go:
mkdir -p ${TOOLS_BIN}/go
@cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % sh -c 'GOBIN=${TOOLS_BIN}/go go install %'

$(PACT_GO_LIB_TARGETS): $(TOOLS_BIN)/go
$(PACT_GO_LIB_TARGETS):
@rm -f /tmp/.libpact-ffi_*
@GOBIN=${TOOLS_BIN}/go ${TOOLS_BIN}/go/pact-go -l DEBUG install -d /tmp
@go tool github.com/pact-foundation/pact-go/v2 -l DEBUG install -d /tmp
@touch /tmp/.libpact-ffi_$(PACT_GO_V)

.PHONY: format
Expand Down Expand Up @@ -101,11 +97,11 @@ generate:
endif

.PHONY: generate-mocks
generate-mocks: $(TOOLS_BIN)/go/mockgen
generate-mocks:
@go generate -tags MOCK ./...

.PHONY: generate-apis
generate-apis: $(TOOLS_BIN)/go/oapi-codegen download-apis
generate-apis: download-apis
@go generate -tags API,!MOCK ./...

.PHONY: download-apis
Expand Down
4 changes: 3 additions & 1 deletion bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ package bundle
import (
"context"
"fmt"

"github.com/rs/zerolog"

"github.com/snyk/code-client-go/internal/deepcode"
"github.com/snyk/code-client-go/observability"
)

//go:generate mockgen -destination=mocks/bundle.go -source=bundle.go -package mocks
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/bundle.go -source=bundle.go -package mocks

type Bundle interface {
UploadBatch(ctx context.Context, requestId string, batch *Batch) error
GetBundleHash() string
Expand Down
6 changes: 3 additions & 3 deletions bundle/bundle_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ import (
"os"
"path/filepath"

"github.com/snyk/code-client-go/scan"

"github.com/puzpuzpuz/xsync"
"github.com/rs/zerolog"

"github.com/snyk/code-client-go/internal/deepcode"
"github.com/snyk/code-client-go/internal/util"
"github.com/snyk/code-client-go/observability"
"github.com/snyk/code-client-go/scan"
)

//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/bundle_manager.go -source=bundle_manager.go -package mocks

type bundleManager struct {
deepcodeClient deepcode.DeepcodeClient
instrumentor observability.Instrumentor
Expand All @@ -41,7 +42,6 @@ type bundleManager struct {
supportedConfigFiles *xsync.MapOf[string, bool]
}

//go:generate mockgen -destination=mocks/bundle_manager.go -source=bundle_manager.go -package mocks
type BundleManager interface {
Create(ctx context.Context,
requestId string,
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package config

import "time"

//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/config.go -source=config.go -package mocks

// Config defines the configurable options for the HTTP client.
//
//go:generate mockgen -destination=mocks/config.go -source=config.go -package mocks
type Config interface {

// Organization is the Snyk organization in which code SAST is being run.
Expand Down
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
github.com/hexops/gotextdiff v1.0.3
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1
github.com/oapi-codegen/runtime v1.1.1
github.com/pact-foundation/pact-go/v2 v2.4.1
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -44,6 +43,7 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pjbgf/sha1cd v0.3.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand All @@ -68,3 +68,9 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

tool (
github.com/golang/mock/mockgen
github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen
github.com/pact-foundation/pact-go/v2
)
3 changes: 2 additions & 1 deletion http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import (
"github.com/snyk/code-client-go/observability"
)

//go:generate mockgen -destination=mocks/http.go -source=http.go -package mocks
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/http.go -source=http.go -package mocks

type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/analysis/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import (
"github.com/snyk/code-client-go/scan"
)

//go:generate mockgen -destination=mocks/analysis.go -source=analysis.go -package mocks
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/analysis.go -source=analysis.go -package mocks

type AnalysisOrchestrator interface {
RunTest(ctx context.Context, orgId string, b bundle.Bundle, target scan.Target, reportingOptions AnalysisConfig) (*sarif.SarifResponse, *scan.ResultMetaData, error)
RunTestRemote(ctx context.Context, orgId string, reportingOptions AnalysisConfig) (*sarif.SarifResponse, *scan.ResultMetaData, error)
Expand Down
10 changes: 5 additions & 5 deletions internal/api/test/2024-12-21/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

package v20241221

//go:generate oapi-codegen --config common/common.config.yaml common/common.yaml
//go:generate oapi-codegen --config parameters/orgs.config.yaml parameters/orgs.yaml
//go:generate oapi-codegen --config parameters/tests.config.yaml parameters/tests.yaml
//go:generate oapi-codegen --config models/tests.config.yaml models/tests.yaml
//go:generate oapi-codegen --config spec.config.yaml spec.yaml
//go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config common/common.config.yaml common/common.yaml
//go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config parameters/orgs.config.yaml parameters/orgs.yaml
//go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config parameters/tests.config.yaml parameters/tests.yaml
//go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config models/tests.config.yaml models/tests.yaml
//go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config spec.config.yaml spec.yaml
3 changes: 2 additions & 1 deletion internal/deepcode/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import (
"github.com/snyk/code-client-go/observability"
)

//go:generate mockgen -destination=mocks/client.go -source=client.go -package mocks
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/client.go -source=client.go -package mocks

type DeepcodeClient interface {
GetFilters(ctx context.Context) (
filters FiltersResponse,
Expand Down
3 changes: 2 additions & 1 deletion observability/error_reporter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package observability

//go:generate mockgen -destination=mocks/error_reporter.go -source=error_reporter.go -package mocks
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/error_reporter.go -source=error_reporter.go -package mocks

type ErrorReporter interface {
FlushErrorReporting()
CaptureError(err error, options ErrorReporterOptions) bool
Expand Down
6 changes: 2 additions & 4 deletions observability/instrumentor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
)

//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/instrumentor.go -source=instrumentor.go -package mocks

// Instrumentor exposes functions used for adding instrumentation context to functions.
//
//go:generate mockgen -destination=mocks/instrumentor.go -source=instrumentor.go -package mocks
type Instrumentor interface {
StartSpan(ctx context.Context, operation string) Span
NewTransaction(
Expand All @@ -18,8 +18,6 @@ type Instrumentor interface {
}

// Span exposes functions that have context about functions.
//
//go:generate mockgen -destination=mocks/instrumentor.go -source=instrumentor.go -package mocks
type Span interface {
SetTransactionName(name string)
StartSpan(ctx context.Context)
Expand Down
3 changes: 2 additions & 1 deletion scan/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/
package scan

//go:generate mockgen -destination=mocks/tracker.go -source=tracker.go -package mocks
//go:generate go tool github.com/golang/mock/mockgen -destination=mocks/tracker.go -source=tracker.go -package mocks

type TrackerFactory interface {
GenerateTracker() Tracker
}
Expand Down
9 changes: 0 additions & 9 deletions tools.go

This file was deleted.