Skip to content

Commit

Permalink
sqlcon: expose option for using random driver names when using tracin…
Browse files Browse the repository at this point in the history
…g so consumers can write integration tests.

Signed-off-by: Amir Aslaminejad <aslaminejad@gmail.com>
  • Loading branch information
aaslamin authored and aeneasr committed Oct 23, 2018
1 parent c221b26 commit 5d8a86f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 4 additions & 4 deletions sqlcon/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,27 @@ func TestDistributedTracing(t *testing.T) {
description: "mysql: when tracing has been configured - spans should be created",
sqlConnection: mustSQL(t, mysqlUrl.String(),
WithDistributedTracing(),
withRandomDriverName(), // this test option is set to ensure a unique driver name is registered
WithRandomDriverName(), // this test option is set to ensure a unique driver name is registered
WithAllowRoot()),
},
{
description: "postgres: when tracing has been configured - spans should be created",
sqlConnection: mustSQL(t, postgresUrl.String(),
WithDistributedTracing(),
withRandomDriverName(), // this test option is set to ensure a unique driver name is registered
WithRandomDriverName(), // this test option is set to ensure a unique driver name is registered
WithAllowRoot()),
},
{
description: "mysql: no spans should be created if parent span is missing from context when `WithAllowRoot` has NOT been set",
sqlConnection: mustSQL(t, mysqlUrl.String(),
WithDistributedTracing(), // Notice that the WithAllowRoot() option has NOT been set
withRandomDriverName()), // this test option is set to ensure a unique driver name is registered
WithRandomDriverName()), // this test option is set to ensure a unique driver name is registered
},
{
description: "postgres: no spans should be created if parent span is missing from context when `WithAllowRoot` has NOT been set",
sqlConnection: mustSQL(t, postgresUrl.String(),
WithDistributedTracing(), // Notice that the WithAllowRoot() option has NOT been set
withRandomDriverName()), // this test option is set to ensure a unique driver name is registered
WithRandomDriverName()), // this test option is set to ensure a unique driver name is registered
},
{
description: "mysql: when tracing has NOT been configured - NO spans should be created",
Expand Down
7 changes: 2 additions & 5 deletions sqlcon/options.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package sqlcon

import "github.com/satori/go.uuid"

type options struct {
UseTracedDriver bool
OmitArgs bool
Expand Down Expand Up @@ -33,9 +31,8 @@ func WithAllowRoot() Opt {
}
}

// This option is specifically for tests, hence why it is unexported...
// Reason for this option is because you can't register a driver with the same name more than once
func withRandomDriverName() Opt {
// This option is specifically for writing tests as you can't register a driver with the same name more than once
func WithRandomDriverName() Opt {
return func(o *options) {
o.forcedDriverName = uuid.NewV4().String()
}
Expand Down

0 comments on commit 5d8a86f

Please sign in to comment.