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

Adding a simple dataref extension #1018

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

matzew
Copy link
Member

@matzew matzew commented Feb 20, 2024

Inspired by the java sdk, adding a go implementation for dataref extension

const DataRefExtensionKey = "dataref"

type DataRefExtension struct {
DataRef string `json:"dataref"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it matters much but I'm curious why it's a struct instead of just a string? Are you leaving the option open that one day we may need to include extra metadata along with the URL?

@matzew
Copy link
Member Author

matzew commented Feb 20, 2024 via email

Copy link
Contributor

@duglin duglin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +14 to +41
func TestAddDataRefExtensionValidURL(t *testing.T) {
e := event.New()
expectedDataRef := "https://example.com/data"

err := AddDataRefExtension(&e, expectedDataRef)
if err != nil {
t.Fatalf("Failed to add DataRefExtension with valid URL: %s", err)
}
}

func TestAddDataRefExtensionInvalidURL(t *testing.T) {
e := event.New()
invalidDataRef := "://invalid-url"

err := AddDataRefExtension(&e, invalidDataRef)
if err == nil {
t.Fatal("Expected error when adding DataRefExtension with invalid URL, but got none")
}
}

func TestGetDataRefExtensionNotFound(t *testing.T) {
e := event.New()

_, ok := GetDataRefExtension(e)
if ok {
t.Fatal("Expected not to find DataRefExtension, but did")
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Java unit tests :)

nit: can we use table-driven tests so those tests are easier to modify/add later? Example here:

func TestRequestWithRetries_linear(t *testing.T) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed you might be following the distributed tracing implementation which uses same style...whatever you prefer

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matzew I'd like to merge this PR - did you want to update something based on this comment?

@duglin
Copy link
Contributor

duglin commented Mar 22, 2024

rebase needed

@duglin duglin requested a review from a team as a code owner July 16, 2024 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants