Skip to content

Commit

Permalink
chore: bump Go version to 1.21 (#494)
Browse files Browse the repository at this point in the history
* chore: bump Go version to 1.21

* test: fix flaky

* test: use httptest

---------

Co-authored-by: Guillermo Sanchez Gavier <gsanchez@newrelic.com>
  • Loading branch information
rubenruizdegauna and gsanchezgavier authored May 9, 2024
1 parent 951d4f6 commit 983c3bc
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ jobs:
test-windows:
strategy:
matrix:
go: [ '1.20' ]
os: [ windows-2019 ]
go: [ '1.21' ]
os: [ windows-2022 ]
name: Run unit and integration tests in ${{matrix.os}} with go ${{matrix.go}}
runs-on: ${{matrix.os}}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
test-windows:
strategy:
matrix:
go: [ '1.20' ]
go: [ '1.21' ]
os: [ windows-2019 ]
name: Run unit and integration tests in ${{matrix.os}} with go ${{matrix.go}}
runs-on: ${{matrix.os}}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SRCDIR ?= .
BUILD_DIR ?= $(CURDIR)/bin
COVERAGE_FILE ?= coverage.out

GO_VERSION ?= 1.20
GO_VERSION ?= 1.21
GO_CMD ?= go
GODOC ?= godocdown

Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GO_VERSION=1.20
ARG GO_VERSION=1.21

FROM golang:$GO_VERSION

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
golang:
image: golang:1.20.13-bullseye
image: golang:1.21-bullseye
volumes:
- .:/go/src/github.com/newrelic/nri-flex
working_dir: /go/src/github.com/newrelic/nri-flex
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/newrelic/nri-flex

go 1.20
go 1.21

require (
github.com/Knetic/govaluate v3.0.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions integration-test/configs/windows/windows-http-test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: httpTest
apis:
- name: httpTest
url: http://localhost:8080/json
url: http://localhost:$$TEST_HTTP_SERVER_PORT/json
event_type: WindowsHttpSample
start_key:
- metrics
- metrics
2 changes: 1 addition & 1 deletion integration-test/configs/windows/windows-https-test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: httpsTest
apis:
- name: httpsTest
url: https://localhost:8043/json
url: https://localhost:$$TEST_HTTPS_SERVER_PORT/json
event_type: WindowsHttpSample
start_key:
- metrics
Expand Down
60 changes: 44 additions & 16 deletions integration-test/http_windows_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
// +build integration
// +build windows
//go:build integration && windows
// +build integration,windows

package integration_test

import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"testing"

"github.com/newrelic/infra-integrations-sdk/data/metric"
sdk "github.com/newrelic/infra-integrations-sdk/integration"
"github.com/newrelic/nri-flex/integration-test/gofile"
"github.com/newrelic/nri-flex/internal/load"
"github.com/newrelic/nri-flex/internal/runtime"
"github.com/stretchr/testify/require"
)

func Test_WindowsHttp_ReturnsData(t *testing.T) {
go startServer(false)
err := os.Setenv("TEST_HTTP_SERVER_PORT", startServer(t, false))
require.NoError(t, err)

load.Refresh()
i, _ := sdk.New(load.IntegrationName, load.IntegrationVersion)
Expand All @@ -29,7 +32,7 @@ func Test_WindowsHttp_ReturnsData(t *testing.T) {

// when
r := runtime.GetDefaultRuntime()
err := runtime.RunFlex(r)
err = runtime.RunFlex(r)
require.NoError(t, err)

//then
Expand All @@ -38,7 +41,8 @@ func Test_WindowsHttp_ReturnsData(t *testing.T) {
}

func Test_WindowsHttps_ReturnsData(t *testing.T) {
go startServer(true)
err := os.Setenv("TEST_HTTPS_SERVER_PORT", startServer(t, true))
require.NoError(t, err)

load.Refresh()
i, _ := sdk.New(load.IntegrationName, load.IntegrationVersion)
Expand All @@ -50,7 +54,7 @@ func Test_WindowsHttps_ReturnsData(t *testing.T) {

// when
r := runtime.GetDefaultRuntime()
err := runtime.RunFlex(r)
err = runtime.RunFlex(r)
require.NoError(t, err)

//then
Expand All @@ -59,8 +63,10 @@ func Test_WindowsHttps_ReturnsData(t *testing.T) {
}

func Test_WindowsHttps_ConfigFolder_ReturnsData(t *testing.T) {
go startServer(false)
go startServer(true)
err := os.Setenv("TEST_HTTP_SERVER_PORT", startServer(t, false))
require.NoError(t, err)
err = os.Setenv("TEST_HTTPS_SERVER_PORT", startServer(t, true))
require.NoError(t, err)

load.Refresh()
i, _ := sdk.New(load.IntegrationName, load.IntegrationVersion)
Expand All @@ -73,7 +79,7 @@ func Test_WindowsHttps_ConfigFolder_ReturnsData(t *testing.T) {

// when
r := runtime.GetDefaultRuntime()
err := runtime.RunFlex(r)
err = runtime.RunFlex(r)
require.NoError(t, err)

//then
Expand All @@ -99,10 +105,32 @@ func checkOutput(t *testing.T, metrics []*metric.Set, expectedCount int) {
require.Equal(t, expectedCount, actualCount)
}

func startServer(tls bool) {
serverFile, _ := filepath.Abs(filepath.Join("https-server", "server.go"))
_, err := gofile.Run(serverFile, fmt.Sprint(tls))
if err != nil {
fmt.Println(err)
func startServer(t *testing.T, tls bool) (port string) {
t.Helper()

srv := &httptest.Server{}
if tls {
srv = httptest.NewTLSServer(http.HandlerFunc(serveJSON))
} else {
srv = httptest.NewServer(http.HandlerFunc(serveJSON))
}

url, err := url.Parse(srv.URL)
require.NoError(t, err)
return url.Port()
}

func serveJSON(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-type", "application/json")
_, _ = w.Write([]byte(`
{
"metrics": [
{
"cpu": 10.0,
"memory": 3500,
"disk": 500
}
]
}
`))
}
2 changes: 1 addition & 1 deletion scripts/docker-compose-build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
golang:
image: golang:1.20.13-bullseye
image: golang:1.21-bullseye
volumes:
- ../:/go/src/github.com/newrelic/nri-flex
working_dir: /go/src/github.com/newrelic/nri-flex
7 changes: 4 additions & 3 deletions tools/go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/newrelic/nri-flex/tools

go 1.20
go 1.21

require (
github.com/AlekSi/gocov-xml v1.1.0
github.com/axw/gocov v1.0.0
github.com/axw/gocov v1.1.0
github.com/jandelgado/gcov2lcov v1.0.4
github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481
gopkg.in/yaml.v2 v2.2.8 // indirect
)

require gopkg.in/yaml.v2 v2.2.8 // indirect
4 changes: 4 additions & 0 deletions tools/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
github.com/AlekSi/gocov-xml v0.0.0-20190121064608-3a14fb1c4737 h1:JZHBkt0GhM+ARQykshqpI49yaWCHQbJonH3XpDTwMZQ=
github.com/AlekSi/gocov-xml v0.0.0-20190121064608-3a14fb1c4737/go.mod h1:w1KSuh2JgIL3nyRiZijboSUwbbxOrTzWwyWVFUHtXBQ=
github.com/AlekSi/gocov-xml v1.1.0/go.mod h1:g1dRVOCHjKkMtlPfW6BokJ/qxoeZ1uPNAK7A/ii3CUo=
github.com/axw/gocov v1.0.0 h1:YsqYR66hUmilVr23tu8USgnJIJvnwh3n7j5zRn7x4LU=
github.com/axw/gocov v1.0.0/go.mod h1:LvQpEYiwwIb2nYkXY2fDWhg9/AsYqkhmrCshjlUJECE=
github.com/axw/gocov v1.1.0/go.mod h1:H9G4tivgdN3pYSSVrTFBr6kGDCmAkgbJhtxFzAvgcdw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jandelgado/gcov2lcov v1.0.4 h1:ADwQPyNsxguqzznIbfQTENwY9FU88JdXEvpdHR9c48A=
Expand All @@ -13,6 +15,7 @@ github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481/go.mod h1:C
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -26,3 +29,4 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 983c3bc

Please sign in to comment.