Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Commit

Permalink
cmd/trace-agent: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
gbbr committed Sep 27, 2018
1 parent 52c0d30 commit 840b4fa
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cmd/trace-agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"regexp"
"runtime"
"strings"
"testing"
Expand Down Expand Up @@ -107,6 +108,33 @@ func TestFormatTrace(t *testing.T) {
assert.Contains(result.Meta["sql.query"], "SELECT name FROM people WHERE age = ?")
}

func TestSQLResourceReplacer(t *testing.T) {
cfg := config.New()
cfg.APIKey = "test"
cfg.Ignore["resource"] = []string{}
cfg.ReplaceTags = []*config.ReplaceRule{{
Name: "resource.name",
Re: regexp.MustCompile("AND.*"),
Repl: "...",
}}
ctx, cancel := context.WithCancel(context.Background())
agent := NewAgent(ctx, cfg)
defer cancel()

now := time.Now()
span := &model.Span{
Resource: "SELECT name FROM people WHERE age = 42 AND extra = 55",
Type: "sql",
Start: now.Add(-time.Second).UnixNano(),
Duration: (500 * time.Millisecond).Nanoseconds(),
}
agent.Process(model.Trace{span})

assert := assert.New(t)
assert.Equal("SELECT name FROM people WHERE age = ? ...", span.Resource)
assert.Equal("SELECT name FROM people WHERE age = ? AND extra = ?", span.Meta["sql.query"])
}

func BenchmarkAgentTraceProcessing(b *testing.B) {
c := config.New()
c.APIKey = "test"
Expand Down

0 comments on commit 840b4fa

Please sign in to comment.