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

Test introduction demo #3194

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
38 changes: 38 additions & 0 deletions tests/test_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Unless explicitly stated otherwise all files in this repository are licensed under the the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2022 Datadog, Inc.

from utils import weblog, interfaces, features, scenarios


# If your test verifies a feature, make sure you represent it
# @features.unix_domain_sockets_support_for_traces
@features.not_reported # This hides your feature from the jaws of the Feature Parity Dashboard
@scenarios.my_nice_scenario # Do you need this? Maybe? Only you can decide.
class Test_Demo:
""" This is a place to describe the purpose of the test """

def setup_very_nice_system_test_has_web_span(self):
self.r = weblog.get("/my-cool-variable")

def test_very_nice_system_test_has_web_span(self):
# You can define multiple tests, but make sure they each have a setup :)
interfaces.library.assert_trace_exists(self.r, span_type="web")

def setup_very_nice_system_test_has_cool_tag_on_span(self):
self.r = weblog.get("/my-cool-variable")

def test_very_nice_system_test_has_cool_tag_on_span(self):
span_count = 0
for _, _, span in interfaces.library.get_spans(request=self.r):
print(" !Span inspection! ")
colin-higgins marked this conversation as resolved.
Show resolved Hide resolved
print(span)
span_count += 1

if span_count > 1:
raise ValueError(f"Oh no, this endpoint should only have one span.")
colin-higgins marked this conversation as resolved.
Show resolved Hide resolved

cool_tag = span["meta"]["DD_WOW_WOW"]
cool_tag_expectation = "wow wow wee wow"
if cool_tag != cool_tag_expectation:
raise ValueError(f"Expected {cool_tag_expectation} but got {cool_tag}")
colin-higgins marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions utils/_context/_scenarios/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,14 @@ def all_endtoend_scenarios(test_object):

external_processing = ExternalProcessingScenario("EXTERNAL_PROCESSING")

# It's VERY important to match the exact name of the property and the name
my_nice_scenario = EndToEndScenario(
name="MY_NICE_SCENARIO",
weblog_env={"DD_VERY_NICE_FEATURE": "wow wow wee wow",},
scenario_groups=[ScenarioGroup.VERY_COOL_SCENARIO_GROUP],
colin-higgins marked this conversation as resolved.
Show resolved Hide resolved
doc="This scenario is very nice, you like? I describe it!",
)


def get_all_scenarios() -> list[Scenario]:
result = []
Expand Down
1 change: 1 addition & 0 deletions utils/_context/_scenarios/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ScenarioGroup(Enum):
DOCKER_SSI = "docker-ssi"
ESSENTIALS = "essentials"
EXTERNAL_PROCESSING = "external-processing"
VERY_COOL_SCENARIO_GROUP = "very-cool-scenario-group"


VALID_GITHUB_WORKFLOWS = {
Expand Down
4 changes: 4 additions & 0 deletions utils/build/docker/golang/app/chi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ func main() {
w.Write([]byte("OK"))
})

// mux.HandleFunc("/my-cool-variable", func(w http.ResponseWriter, r *http.Request) {
// w.Write([]byte("OK"))
// })

mux.HandleFunc("/make_distant_call", func(w http.ResponseWriter, r *http.Request) {
if url := r.URL.Query().Get("url"); url != "" {
client := httptrace.WrapClient(http.DefaultClient)
Expand Down
4 changes: 4 additions & 0 deletions utils/build/docker/golang/app/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func main() {
return c.NoContent(http.StatusOK)
})

// r.Any("/my-cool-variable", func(c echo.Context) error {
// return c.NoContent(http.StatusOK)
// })

r.GET("/healthcheck", func(c echo.Context) error {
healthCheck, err := common.GetHealtchCheck()

Expand Down
7 changes: 7 additions & 0 deletions utils/build/docker/golang/app/net-http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,13 @@ func main() {
w.Write([]byte("ok"))
})

mux.HandleFunc("/my-cool-variable", func(w http.ResponseWriter, r *http.Request) {
cool_feature_text := os.Getenv("DD_VERY_NICE_FEATURE")
span, _ := tracer.SpanFromContext(r.Context())
span.SetTag("DD_WOW_WOW", cool_feature_text)
w.WriteHeader(http.StatusOK)
})

mux.HandleFunc("/dsm/inject", func(w http.ResponseWriter, r *http.Request) {
topic := r.URL.Query().Get("topic")
if len(topic) == 0 {
Expand Down
Loading