Skip to content

Commit

Permalink
test: add acctests for data source "mackerel_service"
Browse files Browse the repository at this point in the history
  • Loading branch information
tosuke committed Jul 4, 2024
1 parent e121e5b commit bf2fd50
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion internal/provider/data_source_mackerel_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ package provider_test

import (
"context"
"fmt"
"testing"

fwdatasource "github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
"github.com/mackerelio-labs/terraform-provider-mackerel/internal/provider"
)

func TestMackerelServiceDataSourceSchema(t *testing.T) {
func Test_MackerelServiceDataSource_schema(t *testing.T) {
t.Parallel()

ctx := context.Background()
Expand All @@ -24,3 +30,40 @@ func TestMackerelServiceDataSourceSchema(t *testing.T) {
t.Fatalf("schema validation diagnostics: %+v", diags)
}
}

func TestAcc_MackerelServiceDataSource_basic(t *testing.T) {
name := fmt.Sprintf("tf-service-%s", acctest.RandString(5))
resourceName := "data.mackerel_service.foo"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { preCheck(t) },
ProtoV5ProviderFactories: protoV5ProviderFactories(),
Steps: []resource.TestStep{
{
Config: mackerelServiceDataSourceConfig(name),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("id"), knownvalue.StringExact(name)),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("name"), knownvalue.StringExact(name)),
statecheck.ExpectKnownValue(
resourceName,
tfjsonpath.New("memo"),
knownvalue.StringExact("This service is managed by Terraform."),
),
},
},
},
})
}

func mackerelServiceDataSourceConfig(name string) string {
return fmt.Sprintf(`
resource "mackerel_service" "foo" {
name = "%s"
memo = "This service is managed by Terraform."
}
data "mackerel_service" "foo" {
name = mackerel_service.foo.id
}
`, name)
}

0 comments on commit bf2fd50

Please sign in to comment.