Skip to content

tests: update unit tests #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 1, 2024
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
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/minivpn
/vpnping
/obfs4vpn
/geturl
/ndt7
.vscode
*.swp
*.swo
Expand All @@ -11,3 +7,4 @@
/*.out
data/*
measurements/*
coverage/*
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TARGET ?= "1.1.1.1"
COUNT ?= 5
TIMEOUT ?= 10
LOCAL_TARGET := $(shell ip -4 addr show docker0 | grep 'inet ' | awk '{print $$2}' | cut -f 1 -d /)
COVERAGE_THRESHOLD := 80
COVERAGE_THRESHOLD := 75
FLAGS=-ldflags="-w -s -buildid=none -linkmode=external" -buildmode=pie -buildvcs=false

build:
Expand All @@ -30,11 +30,19 @@ bootstrap:
test:
GOFLAGS='-count=1' go test -v ./...

test-coverage:
go test -coverprofile=coverage.out ./vpn
test-unit:
mkdir -p ./coverage/unit
go test -cover ./internal/... -args -test.gocoverdir="`pwd`/coverage/unit"

test-integration:
cd tests/integration && ./wrap_integration_cover.sh

test-coverage-refactor:
go test -coverprofile=coverage.out ./internal/...
test-combined-coverage:
go tool covdata percent -i=./coverage/unit,./coverage/int
# convert to text profile and exclude extras/integration test itself
go tool covdata textfmt -i=./coverage/unit,./coverage/int -o coverage/profile
cat coverage/profile| grep -v "extras/ping" | grep -v "tests/integration" > coverage/profile.out
scripts/go-coverage-check.sh ./coverage/profile.out ${COVERAGE_THRESHOLD}

test-coverage-threshold:
go test --short -coverprofile=cov-threshold.out ./vpn
Expand Down
2 changes: 1 addition & 1 deletion cmd/minivpn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func main() {
ctx := context.Background()

proto := config.Remote().Protocol
addr := config.Remote().AddrPort
addr := config.Remote().Endpoint

conn, err := dialer.DialContext(ctx, proto, addr)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/bytesx/bytesx.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ func ReadUint32(buf *bytes.Buffer) (uint32, error) {

// WriteUint32 is a convenience function that appends to the given buffer
// 4 bytes containing the big-endian representation of the given uint32 value.
// Caller is responsible to ensure the passed value does not overflow the
// maximal capacity of 4 bytes.
func WriteUint32(buf *bytes.Buffer, val uint32) {
var numBuf [4]byte
binary.BigEndian.PutUint32(numBuf[:], val)
Expand Down
Loading