Skip to content
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

Add testing for Go 1.20 #3372

Merged
merged 9 commits into from
Feb 13, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
compatibility-test:
strategy:
matrix:
go-version: [1.19, 1.18]
go-version: ["1.20", 1.19, 1.18]
os: [ubuntu-latest, macos-latest, windows-latest]
# GitHub Actions does not support arm* architectures on default
# runners. It is possible to acomplish this with a self-hosted runner
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added

- Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068)
- Support [Go 1.20]. (#3372)

### Changed

Expand Down Expand Up @@ -694,3 +695,5 @@ First official tagged release of `contrib` repository.
[0.8.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.8.0
[0.7.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.7.0
[0.6.1]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.6.1

[Go 1.20]: https://go.dev/doc/go1.20
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ This project is tested on the following systems.

| OS | Go Version | Architecture |
| ------- | ---------- | ------------ |
| Ubuntu | 1.20 | amd64 |
| Ubuntu | 1.19 | amd64 |
| Ubuntu | 1.18 | amd64 |
| Ubuntu | 1.20 | 386 |
| Ubuntu | 1.19 | 386 |
| Ubuntu | 1.18 | 386 |
| MacOS | 1.20 | amd64 |
| MacOS | 1.19 | amd64 |
| MacOS | 1.18 | amd64 |
| Windows | 1.20 | amd64 |
| Windows | 1.19 | amd64 |
| Windows | 1.18 | amd64 |
| Windows | 1.20 | 386 |
| Windows | 1.19 | 386 |
| Windows | 1.18 | 386 |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"

"go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego"
"go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego/internal"
Expand All @@ -36,6 +37,7 @@ import (

"github.com/astaxie/beego"
beegoCtx "github.com/astaxie/beego/context"
assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -225,28 +227,59 @@ func TestStatic(t *testing.T) {
assertSpan(t, spans[0], tc)
}

func TestRender(t *testing.T) {
// Disable autorender to enable traced render
beego.BConfig.WebConfig.AutoRender = false
addTestRoutes(t)
defer replaceBeego()
htmlStr := "<!DOCTYPE html><html lang=\"en\">" +
"<head><meta charset=\"UTF-8\"><title>Hello World</title></head>" +
"<body>This is a template test. Hello {{.name}}</body></html>"
var htmlStr = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World</title>
</head>
<body>This is a template test. Hello {{.name}}</body>
</html>
`

// Create a temp directory to hold a view
dir := t.TempDir()

// Create the view
file, err := os.CreateTemp(dir, "*index.tpl")
require.NoError(t, err)
defer file.Close()
_, err = file.WriteString(htmlStr)
require.NoError(t, err)
// Add path to view path
require.NoError(t, beego.AddViewPath(dir))
beego.SetViewsPath(dir)
_, tplName = filepath.Split(file.Name())
func TestRender(t *testing.T) {
tplName = "index.tpl"
beego.SetTemplateFSFunc(func() http.FileSystem {
return &assetfs.AssetFS{
Asset: func(path string) ([]byte, error) {
if _, f := filepath.Split(path); f == tplName {
return []byte(htmlStr), nil
}
return nil, os.ErrNotExist
},
AssetDir: func(path string) ([]string, error) {
switch path {
case "", `\`:
return []string{tplName}, nil
}
return nil, os.ErrNotExist
},
AssetInfo: func(path string) (os.FileInfo, error) {
if _, f := filepath.Split(path); f == tplName {
return &assetfs.FakeFile{
Path: path,
Len: int64(len(htmlStr)),
Timestamp: time.Now(),
}, nil
}
return nil, os.ErrNotExist
},
}
})
viewPath := "/"
require.NoError(t, beego.AddViewPath(viewPath))

ctrl := &testController{
Controller: beego.Controller{
ViewPath: viewPath,
EnableRender: true,
},
T: t,
}
app := beego.NewApp()
app.Handlers.Add("/template/render", ctrl, "get:TemplateRender")
app.Handlers.Add("/template/renderstring", ctrl, "get:TemplateRenderString")
app.Handlers.Add("/template/renderbytes", ctrl, "get:TemplateRenderBytes")

sr := tracetest.NewSpanRecorder()
tracerProvider := trace.NewTracerProvider(trace.WithSpanProcessor(sr))
Expand All @@ -259,7 +292,7 @@ func TestRender(t *testing.T) {
rr := httptest.NewRecorder()
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://localhost/template%s", str), nil)
require.NoError(t, err)
mw(beego.BeeApp.Handlers).ServeHTTP(rr, req)
mw(app.Handlers).ServeHTTP(rr, req)
body, err := io.ReadAll(rr.Result().Body)
require.Equal(t, strings.Replace(htmlStr, "{{.name}}", "test", 1), string(body))
require.NoError(t, err)
Expand All @@ -269,16 +302,14 @@ func TestRender(t *testing.T) {
require.Len(t, spans, 6) // 3 HTTP requests, each creating 2 spans
for _, span := range spans {
switch span.Name() {
case "/template/render":
case "/template/renderstring":
case "/template/renderbytes":
case "GET":
continue
case internal.RenderTemplateSpanName,
internal.RenderStringSpanName,
internal.RenderBytesSpanName:
assert.Contains(t, span.Attributes(), internal.TemplateKey.String(tplName))
default:
t.Fatal("unexpected span name")
t.Fatal("unexpected span name", span.Name())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/astaxie/beego v1.12.3
github.com/elazarl/go-bindata-assetfs v1.0.0
github.com/stretchr/testify v1.8.1
go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego v0.39.0
go.opentelemetry.io/contrib/propagators/b3 v1.14.0
Expand Down