-
Notifications
You must be signed in to change notification settings - Fork 127
Closed
Description
Entity: elasticstack_elasticsearch_data_stream
Type: resource
Implementation: internal/elasticsearch/index/data_stream.go
Test file: internal/elasticsearch/index/data_stream_test.go
Attributes with no coverage
| Attribute | Flags | Gap |
|---|---|---|
metadata (absent case) |
Computed, TypeString | TestAccResourceDataStream (basic test with no-metadata template) never asserts that metadata is absent / empty — the field is populated from the index template's _meta, so it can silently populate with unexpected data |
Attributes with poor coverage
| Attribute | Flags | Observed | Gaps |
|---|---|---|---|
metadata |
Computed, TypeString | TestAccResourceDataStreamWithMetadata uses TestCheckResourceAttrSet + two TestMatchResourceAttr regex checks |
Set-only + partial regex only; no exact-value assertion; no test that the field is absent when the index template has no _meta; no import test for the metadata variant |
generation |
Computed, TypeInt | Always asserted as "1" |
Single-value only; never tested with generation > 1 (would require triggering a rollover) |
indices.0.index_uuid |
Computed, TypeString | TestCheckResourceAttrSet only |
Acceptable for non-deterministic UUIDs, but no format validation |
Prioritized top 5 gaps
| # | Gap | Impact | Effort |
|---|---|---|---|
| 1 | metadata not asserted as absent in basic test — TestAccResourceDataStream uses an index template with no _meta block, but never calls TestCheckNoResourceAttr or TestCheckResourceAttr(..., "metadata", "") |
MEDIUM — a regression that silently populates metadata would go undetected | Low — add one assertion to the existing basic test step |
| 2 | metadata only partially asserted (regex) — TestAccResourceDataStreamWithMetadata only checks for two substrings; exact JSON round-trip is not verified |
MEDIUM — JSON serialization bugs, extra fields, or incorrect values not caught | Low — replace / supplement regex with value-specific TestCheckResourceAttr using jsonencode expected output |
| 3 | No import test for the metadata variant — import is only tested in TestAccResourceDataStream; whether metadata survives an import cycle is untested |
MEDIUM — import regression in the metadata path invisible | Low — add an import step to TestAccResourceDataStreamWithMetadata |
| 4 | generation single-value coverage — always "1", no test after rollover |
LOW — rollover behaviour is out of scope for most acceptance tests | High — requires rollover trigger |
| 5 | status matched only with a broad regex — `^(?i)(green |
yellow | red)$` passes any valid colour; no test verifies a particular expected state |
Concrete acceptance test additions
1. Assert metadata is absent in the basic test
In TestAccResourceDataStream, step 1, add:
resource.TestCheckResourceAttr("elasticstack_elasticsearch_data_stream.test_ds", "metadata", ""),2. Assert metadata exact value in TestAccResourceDataStreamWithMetadata
Replace the two regex checks with an exact-value check. Since JSON key order may vary, use a normalised comparison or at least strengthen the assertions:
// Option A — assert both keys with individual checks
resource.TestCheckResourceAttrWith(
"elasticstack_elasticsearch_data_stream.test_ds", "metadata",
func(val string) error {
var m map[string]interface{}
if err := json.Unmarshal([]byte(val), &m); err != nil {
return fmt.Errorf("metadata is not valid JSON: %w", err)
}
if m["env"] != "test" {
return fmt.Errorf("expected env=test, got %v", m["env"])
}
if fmt.Sprintf("%v", m["version"]) != "1" {
return fmt.Errorf("expected version=1, got %v", m["version"])
}
return nil
},
),3. Add an import step to TestAccResourceDataStreamWithMetadata
{
Config: testAccResourceDataStreamWithMetadata(dsName),
ResourceName: "elasticstack_elasticsearch_data_stream.test_ds",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"elasticsearch_connection"},
},Generated by Schema Coverage Rotation · ◷
Generated by Schema Coverage Rotation · ◷
Reactions are currently unavailable
Metadata
Metadata
Type
Fields
Give feedbackNo fields configured for issues without a type.