diff --git a/Taskfile.yml b/Taskfile.yml index 4d37c2f..8785f10 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -32,7 +32,7 @@ tasks: - go.mod - go.sum cmds: - - go mod download + - go mod tidy dep-graph: desc: generate dependency graph @@ -94,6 +94,19 @@ tasks: - protoc test: + desc: run short running unit tests that do not need sudo + sources: + - "**/*.go" + deps: + - deps + - generate + cmds: + - mkdir -p {{ .OUT_DIR }} + - go test -coverprofile={{ .OUT_DIR }}/cov-raw.out -covermode count -v ./... + - grep -v "generated" {{ .OUT_DIR }}/cov-raw.out > {{ .OUT_DIR }}/cov.out + - go tool cover -func={{ .OUT_DIR }}/cov.out + + test-all: desc: run all unit tests sources: - "**/*.go" @@ -102,7 +115,7 @@ tasks: - generate cmds: - mkdir -p {{ .OUT_DIR }} - - cmd: go test -coverprofile={{ .OUT_DIR }}/cov-raw.out -covermode count -v ./... 2>&1 | tee {{ .OUT_DIR }}/test_output + - cmd: go test --tags sudo -coverprofile={{ .OUT_DIR }}/cov-raw.out -covermode count -v ./... 2>&1 | tee {{ .OUT_DIR }}/test_output ignore_error: true - cat {{ .OUT_DIR }}/test_output | go-junit-report -set-exit-code > {{ .OUT_DIR }}/report.xml - grep -v "generated" {{ .OUT_DIR }}/cov-raw.out > {{ .OUT_DIR }}/cov.out @@ -123,21 +136,22 @@ tasks: cli-cover-report: desc: generate a coverage report on the CLI deps: - - test + - test-all cmds: - go tool cover -func={{ .OUT_DIR }}/cov.out html-cover-report: desc: generate a coverage report as HTML page deps: - - test + - test-all cmds: - go tool cover -html={{ .OUT_DIR }}/cov.out -o {{ .OUT_DIR }}/coverage.html build-inetmock: desc: build the INetMock server part deps: - - test + - deps + - generate cmds: - mkdir -p {{ .OUT_DIR }} - go build -ldflags='-w -s' -o {{ .OUT_DIR }}/inetmock {{ .INETMOCK_PKG }} @@ -150,7 +164,8 @@ tasks: build-imctl: desc: build the imctl INetMock client CLI deps: - - test + - deps + - generate cmds: - mkdir -p {{ .OUT_DIR }} - go build -ldflags='-w -s' -o {{ .OUT_DIR }}/imctl {{ .IMCTL_PKG }} diff --git a/internal/app/app.go b/internal/app/app.go index d8aaa89..36d390b 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -89,18 +89,16 @@ func NewApp(spec Spec) App { spec.Defaults = make(map[string]interface{}) } - ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) - a := &app{ rootCmd: &cobra.Command{ Use: spec.Name, Short: spec.Short, SilenceUsage: true, }, - ctx: ctx, - cancel: cancel, } + a.ctx, a.cancel = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) + lateInitTasks := []func(cmd *cobra.Command, args []string) (err error){ func(*cobra.Command, []string) (err error) { return spec.readConfig(a.rootCmd) diff --git a/internal/pcap/recorder_integration_test.go b/internal/pcap/recorder_integration_test.go index 0715778..4e7a54a 100644 --- a/internal/pcap/recorder_integration_test.go +++ b/internal/pcap/recorder_integration_test.go @@ -1,3 +1,5 @@ +//+build sudo + package pcap_test import ( diff --git a/internal/pcap/recorder_test.go b/internal/pcap/recorder_test.go index 774c1f8..278fcac 100644 --- a/internal/pcap/recorder_test.go +++ b/internal/pcap/recorder_test.go @@ -1,4 +1,4 @@ -// +build linux +// +build linux,sudo package pcap_test diff --git a/internal/rpc/pcap_server_test.go b/internal/rpc/pcap_server_test.go index f99ae3b..59a8d23 100644 --- a/internal/rpc/pcap_server_test.go +++ b/internal/rpc/pcap_server_test.go @@ -1,3 +1,5 @@ +//+build sudo + package rpc_test import (