Skip to content

Commit

Permalink
bumping go build, linter related changes, prep release, adding a test…
Browse files Browse the repository at this point in the history
… to check coverage is working and increased (#886)

* adding a test to check coverage increase

* adding passing the token

* correct that this is v4 now

* Bump go - still need to fix new linter issues

* make linters happy, hopefully without breaking anything
  • Loading branch information
ldemailly committed Feb 9, 2024
1 parent 8045ad0 commit 03c4e44
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defaultEnv:
&defaultEnv
docker:
# specify the version
- image: docker.io/fortio/fortio.build:v67@sha256:cf1744d102e6aef54e8ca3ef85cfe48c6c44f53740b1535112af8bb95604cf8a
- image: docker.io/fortio/fortio.build:v68@sha256:eb854e95a07ff4bec2d4d8a2967a443e7879ba692066adb27e61f36312ab101e
working_directory: /build/fortio

jobs:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ jobs:
- name: Run coverage
run: make coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@e0b68c6749509c5f83f984dd99a76a1c1a231044 # pin@v3
uses: codecov/codecov-action@e0b68c6749509c5f83f984dd99a76a1c1a231044 # pin@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the binaries in larger image
FROM docker.io/fortio/fortio.build:v67@sha256:cf1744d102e6aef54e8ca3ef85cfe48c6c44f53740b1535112af8bb95604cf8a as build
FROM docker.io/fortio/fortio.build:v68@sha256:eb854e95a07ff4bec2d4d8a2967a443e7879ba692066adb27e61f36312ab101e as build
WORKDIR /build
COPY --chown=build:build . fortio
ARG MODE=install
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dependencies and linters for build:
FROM golang:1.21.6@sha256:6fbd2d3398db924f8d708cf6e94bd3a436bb468195daa6a96e80504e0a9615f2
FROM golang:1.21.7@sha256:b7bac393658f891b69189cfd98111525f951ac0fec8bab97a1990fe43c85d342
# Need gcc for -race test (and some linters though those work with CGO_ENABLED=0)
RUN apt-get -y update && \
apt-get --no-install-recommends -y upgrade && \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.echosrv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the binaries in larger image
FROM docker.io/fortio/fortio.build:v67@sha256:cf1744d102e6aef54e8ca3ef85cfe48c6c44f53740b1535112af8bb95604cf8a as build
FROM docker.io/fortio/fortio.build:v68@sha256:eb854e95a07ff4bec2d4d8a2967a443e7879ba692066adb27e61f36312ab101e as build
WORKDIR /build
COPY . fortio
RUN make -C fortio official-build-version BUILD_DIR=/build OFFICIAL_TARGET=fortio.org/fortio/echosrv
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.fcurl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the binaries in larger image
FROM docker.io/fortio/fortio.build:v67@sha256:cf1744d102e6aef54e8ca3ef85cfe48c6c44f53740b1535112af8bb95604cf8a as build
FROM docker.io/fortio/fortio.build:v68@sha256:eb854e95a07ff4bec2d4d8a2967a443e7879ba692066adb27e61f36312ab101e as build
WORKDIR /build
COPY . fortio
RUN make -C fortio official-build-version BUILD_DIR=/build OFFICIAL_TARGET=fortio.org/fortio/fcurl
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
IMAGES=echosrv fcurl # plus the combo image / Dockerfile without ext.

DOCKER_PREFIX := docker.io/fortio/fortio
BUILD_IMAGE_TAG := v67@sha256:cf1744d102e6aef54e8ca3ef85cfe48c6c44f53740b1535112af8bb95604cf8a
BUILD_IMAGE_TAG := v68@sha256:eb854e95a07ff4bec2d4d8a2967a443e7879ba692066adb27e61f36312ab101e
BUILDX_PLATFORMS := linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
BUILDX_POSTFIX :=
ifeq '$(shell echo $(BUILDX_PLATFORMS) | awk -F "," "{print NF-1}")' '0'
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- 1.63.2 -->
<!-- 1.63.3 -->
# Fortio

[![Awesome Go](https://fortio.org/mentioned-badge.svg)](https://github.com/avelino/awesome-go#networking)
Expand Down Expand Up @@ -60,13 +60,13 @@ You can install from source:
The [releases](https://github.com/fortio/fortio/releases) page has binaries for many OS/architecture combinations (see assets):

```shell
curl -L https://github.com/fortio/fortio/releases/download/v1.63.2/fortio-linux_amd64-1.63.2.tgz \
curl -L https://github.com/fortio/fortio/releases/download/v1.63.3/fortio-linux_amd64-1.63.3.tgz \
| sudo tar -C / -xvzpf -
# or the debian package
wget https://github.com/fortio/fortio/releases/download/v1.63.2/fortio_1.63.2_amd64.deb
dpkg -i fortio_1.63.2_amd64.deb
wget https://github.com/fortio/fortio/releases/download/v1.63.3/fortio_1.63.3_amd64.deb
dpkg -i fortio_1.63.3_amd64.deb
# or the rpm
rpm -i https://github.com/fortio/fortio/releases/download/v1.63.2/fortio-1.63.2-1.x86_64.rpm
rpm -i https://github.com/fortio/fortio/releases/download/v1.63.3/fortio-1.63.3-1.x86_64.rpm
# and more, see assets in release page
```

Expand All @@ -76,7 +76,7 @@ On a MacOS you can also install Fortio using [Homebrew](https://brew.sh/):
brew install fortio
```

On Windows, download https://github.com/fortio/fortio/releases/download/v1.63.2/fortio_win_1.63.2.zip and extract `fortio.exe` to any location, then using the Windows Command Prompt:
On Windows, download https://github.com/fortio/fortio/releases/download/v1.63.3/fortio_win_1.63.3.zip and extract `fortio.exe` to any location, then using the Windows Command Prompt:
```
fortio.exe server
```
Expand Down Expand Up @@ -130,7 +130,7 @@ Full list of command line flags (`fortio help`):
<!-- use release/updateFlags.sh to update this section -->
<pre>
<!-- USAGE_START -->
Φορτίο 1.63.2 usage:
Φορτίο 1.63.3 usage:
fortio command [flags] target
where command is one of: load (load testing), server (starts ui, rest api,
http-echo, redirect, proxies, tcp-echo, udp-echo and grpc ping servers),
Expand Down
2 changes: 1 addition & 1 deletion Webtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fi
PPROF_URL="$BASE_URL/debug/pprof/heap?debug=1"
$CURL "$PPROF_URL" | grep -i TotalAlloc # should find this in memory profile
# creating dummy container to hold a volume for test certs due to remote docker bind mount limitation.
DOCKERCURLID=$(docker run -d -v $TEST_CERT_VOL --net host --name $DOCKERSECVOLNAME docker.io/fortio/fortio.build:v67@sha256:cf1744d102e6aef54e8ca3ef85cfe48c6c44f53740b1535112af8bb95604cf8a sleep 120)
DOCKERCURLID=$(docker run -d -v $TEST_CERT_VOL --net host --name $DOCKERSECVOLNAME docker.io/fortio/fortio.build:v68@sha256:eb854e95a07ff4bec2d4d8a2967a443e7879ba692066adb27e61f36312ab101e sleep 120)
# while we have something with actual curl binary do
# Test for h2c upgrade (#562)
docker exec $DOCKERSECVOLNAME /usr/bin/curl -v --http2 -m 10 -d foo42 http://localhost:8080/debug | tee >(cat 1>&2) | grep foo42
Expand Down
2 changes: 1 addition & 1 deletion fgrpc/grpcrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Dial(o *GRPCRunnerOptions) (*grpc.ClientConn, error) {
serverAddr := grpcDestination(o.Destination)
if o.UnixDomainSocket != "" {
log.Warnf("Using domain socket %v instead of %v for grpc connection", o.UnixDomainSocket, serverAddr)
opts = append(opts, grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
opts = append(opts, grpc.WithContextDialer(func(_ context.Context, _ string) (net.Conn, error) {
return net.Dial(fnet.UnixDomainSocket, o.UnixDomainSocket)
}))
}
Expand Down
6 changes: 3 additions & 3 deletions fhttp/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (h *HTTPOptions) ValidateAndSetConnectionReuseRange(inp string) error {

reuseRangeString := strings.Split(inp, ":")
if len(reuseRangeString) > 2 {
return fmt.Errorf("more than two integers were provided in the connection reuse range")
return errors.New("more than two integers were provided in the connection reuse range")
}
reuseRangeInt := make([]int, 2)
for i, input := range reuseRangeString {
Expand Down Expand Up @@ -662,7 +662,7 @@ func NewStdClient(o *HTTPOptions) (*Client, error) {
}
tr2 := &http2.Transport{
AllowHTTP: true,
DialTLSContext: func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) {
DialTLSContext: func(ctx context.Context, network, addr string, _ *tls.Config) (net.Conn, error) {
return dialCtx(ctx, network, addr)
},
DisableCompression: !o.Compression,
Expand All @@ -676,7 +676,7 @@ func NewStdClient(o *HTTPOptions) (*Client, error) {
client.client.Transport = rt
if !o.FollowRedirects {
// Lets us see the raw response instead of auto following redirects.
client.client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
client.client.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
}
}
Expand Down
2 changes: 1 addition & 1 deletion fhttp/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ func TestInsecureRequest(t *testing.T) {
}

func TestInsecureRequestWithResolve(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
})
srv := httptest.NewTLSServer(handler)
Expand Down
2 changes: 1 addition & 1 deletion fhttp/httprunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func TestAccessLogAndTrace(t *testing.T) {
atomic.AddInt64(&numTrace, 1)
},
}
traceFactory := func(ctx context.Context) *httptrace.ClientTrace { return trace }
traceFactory := func(_ context.Context) *httptrace.ClientTrace { return trace }
opts.DisableFastClient = true
opts.ClientTrace = traceFactory
opts.LogErrors = true
Expand Down
8 changes: 4 additions & 4 deletions fnet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func dnsMethodValidator(inp string) error {
if valid[inp] {
return nil
}
return fmt.Errorf("invalid value for dns method, should be one of cached-rr, first, rnd or rr")
return errors.New("invalid value for dns method, should be one of cached-rr, first, rnd or rr")
}

//nolint:gochecknoinits // needed here (unit change)
Expand Down Expand Up @@ -415,7 +415,7 @@ func ResolveAll(ctx context.Context, host, resolveType string) ([]net.IP, error)
host = host[1 : len(host)-1]
}
if host == "" {
return nil, fmt.Errorf("can't resolve empty host")
return nil, errors.New("can't resolve empty host")
}
isAddr := net.ParseIP(host)
if isAddr != nil {
Expand Down Expand Up @@ -519,7 +519,7 @@ func transfer(wg *sync.WaitGroup, dst net.Conn, src net.Conn) {
}

// ErrNilDestination returned when trying to proxy to a nil address.
var ErrNilDestination = fmt.Errorf("nil destination")
var ErrNilDestination = errors.New("nil destination")

func handleProxyRequest(conn net.Conn, dest net.Addr) {
err := ErrNilDestination
Expand Down Expand Up @@ -577,7 +577,7 @@ func ProxyToDestination(ctx context.Context, listenPort string, destination stri
func NormalizeHostPort(inputPort string, addr net.Addr) string {
urlHostPort := addr.String()
if addr.Network() == UnixDomainSocket {
urlHostPort = fmt.Sprintf("-unix-socket=%s", urlHostPort)
urlHostPort = "-unix-socket=" + urlHostPort
} else if strings.HasPrefix(inputPort, ":") || !strings.Contains(inputPort, ":") {
urlHostPort = fmt.Sprintf("localhost:%d", addr.(*net.TCPAddr).Port)
}
Expand Down
2 changes: 1 addition & 1 deletion fnet/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func TestUnixDomain(t *testing.T) {
t.Fatalf("Nil socket in unix socket proxy listen")
}
hp := fnet.NormalizeHostPort("", addr)
expected := fmt.Sprintf("-unix-socket=%s", fname)
expected := "-unix-socket=" + fname
if hp != expected {
t.Errorf("Got %s, expected %s from fnet.NormalizeHostPort(%v)", hp, expected, addr)
}
Expand Down
2 changes: 1 addition & 1 deletion periodic/periodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func (r *periodicRunner) Run() RunnerResults {
// AccessLogger info check
extra := ""
if r.AccessLogger != nil {
extra = fmt.Sprintf(" with access logger %s", r.AccessLogger.Info())
extra = " with access logger " + r.AccessLogger.Info()
}
requestedQPS := "max"
if useQPS {
Expand Down
31 changes: 25 additions & 6 deletions rapi/restHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestHTTPRunnerRESTApi(t *testing.T) {

// Check payload is used and that query arg overrides payload
jsonData := fmt.Sprintf("{\"metadata\": {\"url\":%q, \"save\":\"on\", \"n\":\"200\", \"payload\": \"test payload\"}}", echoURL)
runURL = fmt.Sprintf("%s?jsonPath=.metadata&qps=100&n=100", restURL)
runURL = restURL + "?jsonPath=.metadata&qps=100&n=100"
res = GetResult(t, runURL, jsonData)
totalReq = res.DurationHistogram.Count
httpOk = res.RetCodes[http.StatusOK]
Expand All @@ -179,33 +179,33 @@ func TestHTTPRunnerRESTApi(t *testing.T) {
}

// Send a bad (missing unit) duration (test error return)
runURL = fmt.Sprintf("%s?jsonPath=.metadata&qps=100&n=10&t=42", restURL)
runURL = restURL + "?jsonPath=.metadata&qps=100&n=10&t=42"
errObj := GetErrorResult(t, runURL, jsonData)
if errObj.Message != "parsing duration" || errObj.Exception != "time: missing unit in duration \"42\"" {
t.Errorf("Didn't get the expected duration parsing error, got %+v", errObj)
}
// bad json path: doesn't exist
runURL = fmt.Sprintf("%s?jsonPath=.foo", restURL)
runURL = restURL + "?jsonPath=.foo"
errObj = GetErrorResult(t, runURL, jsonData)
if errObj.Exception != "\"foo\" not found in json" {
t.Errorf("Didn't get the expected json body access error, got %+v", errObj)
}
// bad json path: wrong type
runURL = fmt.Sprintf("%s?jsonPath=.metadata.url", restURL)
runURL = restURL + "?jsonPath=.metadata.url"
errObj = GetErrorResult(t, runURL, jsonData)
if errObj.Exception != "\"url\" path is not a map" {
t.Errorf("Didn't get the expected json type mismatch error, got %+v", errObj)
}
// missing url and a few other cases
jsonData = `{"metadata": {"n": 200}}`
runURL = fmt.Sprintf("%s?jsonPath=.metadata", restURL)
runURL = restURL + "?jsonPath=.metadata"
errObj = GetErrorResult(t, runURL, jsonData)
if errObj.Message != "URL is required" {
t.Errorf("Didn't get the expected url missing error, got %+v", errObj)
}
// not well formed json
jsonData = `{"metadata": {"n":`
runURL = fmt.Sprintf("%s?jsonPath=.metadata", restURL)
runURL = restURL + "?jsonPath=.metadata"
errObj = GetErrorResult(t, runURL, jsonData)
if errObj.Exception != "unexpected end of JSON input" {
t.Errorf("Didn't get the expected error for truncated/invalid json, got %+v", errObj)
Expand Down Expand Up @@ -660,3 +660,22 @@ func TestDataDir(t *testing.T) {
}
SetDataDir(oldDir)
}

func TestStateEnum(t *testing.T) {
// Test the unknown and error cases
var se StateEnum
actual := se.String()
expected := "unknown"
if actual != expected {
t.Errorf("Expected %q got %q", expected, actual)
}
se = StateEnum(1000)
// handle panic:
defer func() {
if r := recover(); r == nil {
t.Errorf("Expected panic for unknown state, got nil")
}
}()
actual = se.String()
t.Errorf("Expected panic, got %q", actual)
}
2 changes: 1 addition & 1 deletion release/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Concatenated after ../Dockerfile to create the tgz
FROM docker.io/fortio/fortio.build:v67@sha256:cf1744d102e6aef54e8ca3ef85cfe48c6c44f53740b1535112af8bb95604cf8a as stage
FROM docker.io/fortio/fortio.build:v68@sha256:eb854e95a07ff4bec2d4d8a2967a443e7879ba692066adb27e61f36312ab101e as stage
ARG archs="amd64 arm64 ppc64le s390x"
ENV archs=${archs}
# Build image defaults to build user, switch back to root for
Expand Down
6 changes: 3 additions & 3 deletions tcprunner/tcprunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ var (
TCPURLPrefix = "tcp://"
// TCPStatusOK is the map key on success.
TCPStatusOK = "OK"
errShortRead = fmt.Errorf("short read")
errLongRead = fmt.Errorf("bug: long read")
errMismatch = fmt.Errorf("read not echoing writes")
errShortRead = errors.New("short read")
errLongRead = errors.New("bug: long read")
errMismatch = errors.New("read not echoing writes")
)

// GeneratePayload generates a default 24 bytes unique payload for each runner thread and message sent
Expand Down
9 changes: 5 additions & 4 deletions udprunner/udprunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package udprunner
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -98,10 +99,10 @@ var (
UDPURLPrefix = "udp://"
// UDPStatusOK is the map key on success.
UDPStatusOK = "OK"
errTimeout = fmt.Errorf("timeout")
errShortRead = fmt.Errorf("short read")
errLongRead = fmt.Errorf("bug: long read")
errMismatch = fmt.Errorf("read not echoing writes")
errTimeout = errors.New("timeout")
errShortRead = errors.New("short read")
errLongRead = errors.New("bug: long read")
errMismatch = errors.New("read not echoing writes")
)

// NewUDPClient creates and initialize and returns a client based on the UDPOptions.
Expand Down
1 change: 0 additions & 1 deletion ui/uihandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ func Handler(w http.ResponseWriter, r *http.Request) {
}
// A bit awkward api because of trying to reuse yet be compatible from old UI code with
// new `rapi` code.
//nolint:contextcheck // we use the internal Aborter to cancel run through api/stop button in UI.
res, savedAs, json, err := rapi.Run(runWriter, r, nil, runner, url, &ro, httpopts, true /*html mode*/)
if err != nil {
_, _ = w.Write([]byte(fmt.Sprintf(
Expand Down

0 comments on commit 03c4e44

Please sign in to comment.