Skip to content

Commit

Permalink
chore(insights_event): remove extraneous testAccCheckNewRelicInsights…
Browse files Browse the repository at this point in the history
…EventExists
  • Loading branch information
sanderblue committed Jun 25, 2020
1 parent a2dddb0 commit 514c166
Showing 1 changed file with 0 additions and 66 deletions.
66 changes: 0 additions & 66 deletions newrelic/resource_newrelic_insights_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package newrelic

import (
"fmt"
"strings"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/newrelic/newrelic-client-go/pkg/nrdb"
)

func TestAccNewRelicInsightsEvent_Basic(t *testing.T) {
Expand All @@ -27,77 +25,13 @@ func TestAccNewRelicInsightsEvent_Basic(t *testing.T) {
{
Config: testAccCheckNewRelicInsightsEventConfig(eType, tNow),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicInsightsEventExists(
"newrelic_insights_event.foo",
[]string{
fmt.Sprintf(
"SELECT * FROM tf_test_%s "+
"WHERE event_test = 'checking floats' "+
"AND a_float = 101.1 "+
"AND timestamp = %d",
eType, tNow),
fmt.Sprintf(
"SELECT * FROM tf_test_%s "+
"WHERE event_test = 'checking ints' "+
"AND an_int = 42 "+
"AND timestamp = %d",
eType, tNow),
fmt.Sprintf(
"SELECT * FROM tf_test_%s "+
"WHERE event_test = 'checking strings' "+
"AND a_string = 'a string' "+
"AND another_string = 'another string' "+
"AND timestamp = %d",
eType, tNow),
},
),
resource.TestCheckResourceAttr("newrelic_insights_event.foo", "event.#", "3"),
),
},
},
})
}

func testAccCheckNewRelicInsightsEventExists(n string, nrqls []string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("no event ID is set")
}

providerConfig := testAccProvider.Meta().(*ProviderConfig)
client := providerConfig.NewClient
accountID := providerConfig.AccountID

// Due to the asynchronous operation, we need to
// wait for the events to propagate.
time.Sleep(15 * time.Second)

var errs []string
for _, nrql := range nrqls {
resp, err := client.Nrdb.Query(accountID, nrdb.Nrql(nrql))
if err != nil {
errs = append(errs, err.Error())
}

if len(resp.Results) != 1 {
errs = append(errs, fmt.Sprintf("[Error] Insights event not found (likely due to async issue) - query: %v", nrql))
}
}

if len(errs) > 0 {
fmt.Printf("test case TestAccNewRelicInsightsEvent_Basic failed (likely due to asynchronous)")

return fmt.Errorf("%v", strings.Join(errs, "\n"))
}

return nil
}
}

func testAccCheckNewRelicInsightsEventConfig(eType string, t int64) string {
return fmt.Sprintf(`
resource "newrelic_insights_event" "foo" {
Expand Down

0 comments on commit 514c166

Please sign in to comment.