generated from hashicorp/terraform-provider-scaffolding
-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add instrumentation to inject user-agent header;
update changelog; update neon sdk. Signed-off-by: Dmitry Kisler <admin@dkisler.com>
- Loading branch information
Showing
6 changed files
with
121 additions
and
14 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
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
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,63 @@ | ||
//go:build !acceptance | ||
// +build !acceptance | ||
|
||
package provider | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type httpClient struct { | ||
header http.Header | ||
} | ||
|
||
func (h *httpClient) Do(r *http.Request) (*http.Response, error) { | ||
h.header = r.Header | ||
return &http.Response{ | ||
StatusCode: http.StatusOK, | ||
Body: io.NopCloser(strings.NewReader("{}")), | ||
}, nil | ||
} | ||
|
||
func TestUserAgentInstrumentation(t *testing.T) { | ||
const ( | ||
wantVersion = "ProviderVer" | ||
|
||
resourceDefinition = `resource "neon_role" "this" { | ||
project_id = "foo" | ||
branch_id = "foo" | ||
name = "foo" | ||
}` | ||
) | ||
|
||
c := &httpClient{} | ||
|
||
t.Setenv("NEON_API_KEY", "foo") | ||
|
||
resource.UnitTest(t, resource.TestCase{ | ||
ProviderFactories: map[string]func() (*schema.Provider, error){ | ||
"neon": func() (*schema.Provider, error) { | ||
return newWithClient(wantVersion, c), nil | ||
}, | ||
}, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: resourceDefinition, | ||
ExpectNonEmptyPlan: true, | ||
}, | ||
}, | ||
}) | ||
|
||
userAgent := c.header.Get("User-Agent") | ||
assert.Contains(t, userAgent, DefaultApplicationName) | ||
els := strings.Split(userAgent, "@") | ||
assert.Len(t, els, 2) | ||
assert.Equal(t, wantVersion, els[1]) | ||
} |
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