Skip to content

Commit

Permalink
Add test case for half-configured v2 config
Browse files Browse the repository at this point in the history
  • Loading branch information
jharley committed Jul 17, 2024
1 parent 9bf24f0 commit d06404d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ func (p *HoneycombioProvider) Configure(ctx context.Context, req provider.Config
} else if (keyID != "" && keySecret == "") || (keyID == "" && keySecret != "") {
resp.Diagnostics.AddError(
"Unable to initialize Honeycomb provider",
"The provider requires both a Honeycomb API Key ID and Secret pair. "+
"The provider requires both a Honeycomb API Key ID and Secret. "+
"Set them both in the configuration or via the HONEYCOMB_KEY_ID and HONEYCOMB_KEY_SECRET"+
"environment variables.",
"environment variables. "+
"If you believe both are already set, ensure the values are not empty.",
)
return
}

if !initv1Client && !initv2Client {
Expand Down
24 changes: 24 additions & 0 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,30 @@ resource "honeycombio_api_key" "test" {
})
})

t.Run("fails when only half of v2 configuration is set", func(t *testing.T) {
resource.Test(t, resource.TestCase{
ProtoV5ProviderFactories: testAccProtoV5MuxServerFactory,
Steps: []resource.TestStep{
{
PreConfig: func() {
t.Setenv("HONEYCOMB_API_KEY", "")
t.Setenv("HONEYCOMB_KEY_SECRET", "")
},
Config: `
# TODO: replace with v2-client data source
resource "honeycombio_api_key" "test" {
name = "test"
type = "ingest"
environment_id = "1"
}`,
PlanOnly: true,
ExpectError: regexp.MustCompile(`provider requires both a Honeycomb API Key ID and Secret`),
},
},
})
})

t.Run("fails when no clients configured", func(t *testing.T) {
resource.Test(t, resource.TestCase{
ProtoV5ProviderFactories: testAccProtoV5MuxServerFactory,
Expand Down

0 comments on commit d06404d

Please sign in to comment.