-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Imporve ability to run package code in tests
- Loading branch information
1 parent
be5520c
commit 5539755
Showing
3 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed | ||
* under the Apache License Version 2.0. | ||
* | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019 Datadog, Inc. | ||
*/ | ||
package ddlambda | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestInvokeDryRun(t *testing.T) { | ||
called := false | ||
InvokeDryRun(func(ctx context.Context) { | ||
called = true | ||
globalCtx := GetContext() | ||
assert.Equal(t, globalCtx, ctx) | ||
}, nil) | ||
assert.True(t, called) | ||
} | ||
|
||
func TestMetricsSilentFailWithoutWrapper(t *testing.T) { | ||
Metric("my-metric", 100, "my:tag") | ||
} | ||
|
||
func TestMetricsSubmitWithWrapper(t *testing.T) { | ||
called := false | ||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
called = true | ||
w.WriteHeader(http.StatusCreated) | ||
})) | ||
defer server.Close() | ||
|
||
InvokeDryRun(func(ctx context.Context) { | ||
Metric("my-metric", 100, "my:tag") | ||
}, &Config{ | ||
APIKey: "abc-123", | ||
Site: server.URL, | ||
}) | ||
assert.True(t, called) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters