Skip to content
Closed
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
59f5cd0
Added a field coverage tracker
jvander-JNPR Nov 25, 2025
219bc48
cleanup
jvander-JNPR Nov 25, 2025
865996f
bug fix
jvander-JNPR Nov 25, 2025
99af6f0
progress
jvander-JNPR Nov 25, 2025
4a5c919
Fixes and improvements
jvander-JNPR Nov 26, 2025
1abc380
field validator improvements
jvander-JNPR Nov 28, 2025
7dc9ca4
Fixed IP address normalisation
jvander-JNPR Jan 7, 2026
ef9ced8
bug fixes and improvements
jvander-JNPR Jan 7, 2026
05805dc
bug fixes and improvements
jvander-JNPR Jan 13, 2026
500c72c
Fixed typo
jvander-JNPR Jan 13, 2026
d23850b
Added support for nested sets and coverage on SchemaExtractionFailures
jvander-JNPR Jan 13, 2026
217504d
Better var name
jvander-JNPR Jan 13, 2026
0b98592
pr feedback
jvander-JNPR Jan 13, 2026
ddfa048
PR Feedback
jvander-JNPR Jan 14, 2026
626898c
Added coverage validator to some tests
jvander-JNPR Jan 14, 2026
a127c15
Better normalised fields
jvander-JNPR Jan 14, 2026
330e8ee
remove report
jvander-JNPR Jan 14, 2026
d7bccc8
More resources tracked
jvander-JNPR Jan 14, 2026
e8bf59c
All resources tracked
jvander-JNPR Jan 14, 2026
4ad25c0
Include test status
jvander-JNPR Jan 14, 2026
57800b8
revert silly
jvander-JNPR Jan 15, 2026
159cad5
Print to std out
jvander-JNPR Jan 16, 2026
d9d00eb
missing fuction
jvander-JNPR Jan 16, 2026
2d1f90b
better arch
jvander-JNPR Jan 21, 2026
3fba162
nil check
jvander-JNPR Jan 21, 2026
4bb1355
removed nil check in tracker
jvander-JNPR Jan 21, 2026
f95db6b
testing guide update and minor improvements
jvander-JNPR Jan 26, 2026
a063028
put TG where it should be
jvander-JNPR Jan 26, 2026
3699367
standardised log message
jvander-JNPR Jan 26, 2026
0cab847
good now
jvander-JNPR Jan 26, 2026
2d394c4
Standardised all test Skips
jvander-JNPR Jan 26, 2026
732d8cf
PR Feedback
jvander-JNPR Jan 27, 2026
452cda6
Feedback items
jvander-JNPR Jan 27, 2026
74ae190
Added map attributes
jvander-JNPR Jan 27, 2026
f71bbd8
Added support for maps
jvander-JNPR Jan 27, 2026
b31287c
clean up
jvander-JNPR Jan 27, 2026
31fce6f
better tested field count
jvander-JNPR Jan 27, 2026
d0bd820
added missing reports and fixed fixtures
jvander-JNPR Jan 28, 2026
09b6f0c
PR Feedback
jvander-JNPR Feb 2, 2026
ce00ffe
improved guide
jvander-JNPR Feb 2, 2026
cdd21bf
small niggle
jvander-JNPR Feb 2, 2026
7d9524c
optimizations
jvander-JNPR Feb 2, 2026
3c8616c
consistent styling for if statements
jvander-JNPR Feb 3, 2026
627d45a
comment fix
jvander-JNPR Feb 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions internal/provider/device_ap_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ import (
"strings"
"testing"

"github.com/Juniper/terraform-provider-mist/internal/provider/validators"
"github.com/Juniper/terraform-provider-mist/internal/resource_device_ap"
"github.com/hashicorp/hcl"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestDeviceAp(t *testing.T) {
func TestDeviceApModel(t *testing.T) {
resourceType := "device_ap"
t.Skipf("Skipping %s tests, as they require a real device.", resourceType)

type testStep struct {
config DeviceApModel
}
Expand Down Expand Up @@ -59,11 +64,9 @@ func TestDeviceAp(t *testing.T) {
}
}

tracker := validators.FieldCoverageTrackerWithSchema(resourceType, resource_device_ap.DeviceApResourceSchema(t.Context()).Attributes)
for tName, tCase := range testCases {
t.Skip("Skipping device_ap tests, as they require a real device.")
t.Run(tName, func(t *testing.T) {
resourceType := "device_ap"

steps := make([]resource.TestStep, len(tCase.steps))
for i, step := range tCase.steps {
siteConfig, siteRef := GetSiteBaseConfig(GetTestOrgId())
Expand All @@ -74,7 +77,7 @@ func TestDeviceAp(t *testing.T) {
f.Body().SetAttributeRaw("site_id", hclwrite.TokensForIdentifier(siteRef))
combinedConfig := siteConfig + "\n\n" + Render(resourceType, tName, string(f.Bytes()))

checks := config.testChecks(t, resourceType, tName)
checks := config.testChecks(t, resourceType, tName, tracker)
chkLog := checks.string()
stepName := fmt.Sprintf("test case %s step %d", tName, i+1)

Expand All @@ -94,10 +97,14 @@ func TestDeviceAp(t *testing.T) {
})
})
}
if tracker != nil {
tracker.FieldCoverageReport(t)
}
}

func (s *DeviceApModel) testChecks(t testing.TB, rType, rName string) testChecks {
checks := newTestChecks(PrefixProviderName(rType) + "." + rName)
func (s *DeviceApModel) testChecks(t testing.TB, rType, tName string, tracker *validators.FieldCoverageTracker) testChecks {
checks := newTestChecks(PrefixProviderName(rType) + "." + tName)
checks.SetTracker(tracker)

// Required attributes
checks.append(t, "TestCheckResourceAttr", "site_id", s.SiteId)
Expand Down
29 changes: 18 additions & 11 deletions internal/provider/device_gateway_cluster_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ import (
"fmt"
"testing"

"github.com/Juniper/terraform-provider-mist/internal/provider/validators"
"github.com/Juniper/terraform-provider-mist/internal/resource_device_gateway_cluster"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func (s *DeviceGatewayClusterModel) testChecks(t testing.TB, rType, rName string) testChecks {
checks := newTestChecks(rType + "." + rName)
checks.append(t, "TestCheckResourceAttr", "site_id", s.SiteId)

return checks
}
func TestDeviceGatewayClusterModel(t *testing.T) {
resourceType := "mist_device_gateway_cluster"
t.Skipf("Skipping %s tests, as they require real devices.", resourceType)

func TestDeviceGatewayCluster(t *testing.T) {
type testStep struct {
config DeviceGatewayClusterModel
}
Expand Down Expand Up @@ -55,11 +53,9 @@ func TestDeviceGatewayCluster(t *testing.T) {
},
}

tracker := validators.FieldCoverageTrackerWithSchema(resourceType, resource_device_gateway_cluster.DeviceGatewayClusterResourceSchema(t.Context()).Attributes)
for tName, tCase := range testCases {
t.Skip("Skipping by default as test requires two gateway devices.")
t.Run(tName, func(t *testing.T) {
resourceType := "mist_device_gateway_cluster"

steps := make([]resource.TestStep, len(tCase.steps))
for i, step := range tCase.steps {
config := step.config
Expand All @@ -68,7 +64,7 @@ func TestDeviceGatewayCluster(t *testing.T) {
gohcl.EncodeIntoBody(&config, f.Body())
configStr := Render(resourceType, tName, string(f.Bytes()))

checks := config.testChecks(t, resourceType, tName)
checks := config.testChecks(t, resourceType, tName, tracker)
chkLog := checks.string()
stepName := fmt.Sprintf("test case %s step %d", tName, i+1)

Expand All @@ -88,4 +84,15 @@ func TestDeviceGatewayCluster(t *testing.T) {
})
})
}
if tracker != nil {
tracker.FieldCoverageReport(t)
}
}

func (s *DeviceGatewayClusterModel) testChecks(t testing.TB, rType, tName string, tracker *validators.FieldCoverageTracker) testChecks {
checks := newTestChecks(PrefixProviderName(rType) + "." + tName)
checks.SetTracker(tracker)
checks.append(t, "TestCheckResourceAttr", "site_id", s.SiteId)

return checks
}
19 changes: 13 additions & 6 deletions internal/provider/device_gateway_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ import (
"strings"
"testing"

"github.com/Juniper/terraform-provider-mist/internal/provider/validators"
"github.com/Juniper/terraform-provider-mist/internal/resource_device_gateway"
"github.com/hashicorp/hcl"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestDeviceGatewayModel(t *testing.T) {
resourceType := "device_gateway"
t.Skipf("Skipping %s tests, as they require a real device.", resourceType)

type testStep struct {
config DeviceGatewayModel
}
Expand Down Expand Up @@ -59,11 +64,9 @@ func TestDeviceGatewayModel(t *testing.T) {
}
}

tracker := validators.FieldCoverageTrackerWithSchema(resourceType, resource_device_gateway.DeviceGatewayResourceSchema(t.Context()).Attributes)
for tName, tCase := range testCases {
t.Skip("Skipping device_gateway tests, as they require a real device.")
t.Run(tName, func(t *testing.T) {
resourceType := "device_gateway"

steps := make([]resource.TestStep, len(tCase.steps))
for i, step := range tCase.steps {
// siteConfig, siteRef := GetSiteBaseConfig(GetTestOrgId())
Expand All @@ -74,7 +77,7 @@ func TestDeviceGatewayModel(t *testing.T) {
// f.Body().SetAttributeRaw("site_id", hclwrite.TokensForIdentifier(siteRef))
combinedConfig := Render(resourceType, tName, string(f.Bytes()))

checks := config.testChecks(t, resourceType, tName)
checks := config.testChecks(t, resourceType, tName, tracker)
chkLog := checks.string()
stepName := fmt.Sprintf("test case %s step %d", tName, i+1)

Expand All @@ -94,10 +97,14 @@ func TestDeviceGatewayModel(t *testing.T) {
})
})
}
if tracker != nil {
tracker.FieldCoverageReport(t)
}
}

func (s *DeviceGatewayModel) testChecks(t testing.TB, rType, rName string) testChecks {
checks := newTestChecks(PrefixProviderName(rType) + "." + rName)
func (s *DeviceGatewayModel) testChecks(t testing.TB, rType, tName string, tracker *validators.FieldCoverageTracker) testChecks {
checks := newTestChecks(PrefixProviderName(rType) + "." + tName)
checks.SetTracker(tracker)

// Always present attributes
checks.append(t, "TestCheckResourceAttrSet", "site_id")
Expand Down
21 changes: 14 additions & 7 deletions internal/provider/device_image_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import (
"fmt"
"testing"

"github.com/Juniper/terraform-provider-mist/internal/provider/validators"
"github.com/Juniper/terraform-provider-mist/internal/resource_device_image"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestDeviceImageModel(t *testing.T) {
testImagePath := CreateTestPNGFile(t)
resourceType := "device_image"
t.Skipf("Skipping %s tests, as they require a real device.", resourceType)

testImagePath := CreateTestPNGFile(t)
type testStep struct {
config DeviceImageModel
}
Expand All @@ -34,11 +38,9 @@ func TestDeviceImageModel(t *testing.T) {
},
}

tracker := validators.FieldCoverageTrackerWithSchema(resourceType, resource_device_image.DeviceImageResourceSchema(t.Context()).Attributes)
for tName, tCase := range testCases {
t.Skip("Skipping test case: " + tName) // Skip all tests for now
t.Run(tName, func(t *testing.T) {
resourceType := "device_image"

steps := make([]resource.TestStep, len(tCase.steps))
for i, step := range tCase.steps {
siteConfig, siteRef := GetSiteBaseConfig(GetTestOrgId())
Expand All @@ -49,7 +51,7 @@ func TestDeviceImageModel(t *testing.T) {
f.Body().SetAttributeRaw("site_id", hclwrite.TokensForIdentifier(siteRef))
combinedConfig := siteConfig + "\n\n" + Render(resourceType, tName, string(f.Bytes()))

checks := config.testChecks(t, resourceType, tName)
checks := config.testChecks(t, resourceType, tName, tracker)
chkLog := checks.string()
stepName := fmt.Sprintf("test case %s step %d", tName, i+1)

Expand All @@ -69,10 +71,15 @@ func TestDeviceImageModel(t *testing.T) {
})
})
}
if tracker != nil {
tracker.FieldCoverageReport(t)
}
}

func (s *DeviceImageModel) testChecks(t testing.TB, rType, rName string) testChecks {
checks := newTestChecks(PrefixProviderName(rType) + "." + rName)
func (s *DeviceImageModel) testChecks(t testing.TB, rType, tName string, tracker *validators.FieldCoverageTracker) testChecks {
checks := newTestChecks(PrefixProviderName(rType) + "." + tName)
checks.SetTracker(tracker)

checks.append(t, "TestCheckResourceAttrSet", "site_id")
checks.append(t, "TestCheckResourceAttr", "file", s.File)
checks.append(t, "TestCheckResourceAttrSet", "device_id")
Expand Down
19 changes: 13 additions & 6 deletions internal/provider/device_switch_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ import (
"strings"
"testing"

"github.com/Juniper/terraform-provider-mist/internal/provider/validators"
"github.com/Juniper/terraform-provider-mist/internal/resource_device_switch"
"github.com/hashicorp/hcl"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestDeviceSwitchModel(t *testing.T) {
resourceType := "device_switch"
t.Skipf("Skipping %s tests, as they require a real device.", resourceType)

type testStep struct {
config DeviceSwitchModel
}
Expand Down Expand Up @@ -58,11 +63,9 @@ func TestDeviceSwitchModel(t *testing.T) {
}
}

tracker := validators.FieldCoverageTrackerWithSchema(resourceType, resource_device_switch.DeviceSwitchResourceSchema(t.Context()).Attributes)
for tName, tCase := range testCases {
t.Skip("Skipping device_switch tests, as they require a real device.")
t.Run(tName, func(t *testing.T) {
resourceType := "device_switch"

steps := make([]resource.TestStep, len(tCase.steps))
for i, step := range tCase.steps {
siteConfig, siteRef := GetSiteBaseConfig(GetTestOrgId())
Expand All @@ -73,7 +76,7 @@ func TestDeviceSwitchModel(t *testing.T) {
f.Body().SetAttributeRaw("site_id", hclwrite.TokensForIdentifier(siteRef))
combinedConfig := siteConfig + "\n\n" + Render(resourceType, tName, string(f.Bytes()))

checks := config.testChecks(t, resourceType, tName)
checks := config.testChecks(t, resourceType, tName, tracker)
chkLog := checks.string()
stepName := fmt.Sprintf("test case %s step %d", tName, i+1)

Expand All @@ -93,10 +96,14 @@ func TestDeviceSwitchModel(t *testing.T) {
})
})
}
if tracker != nil {
tracker.FieldCoverageReport(t)
}
}

func (s *DeviceSwitchModel) testChecks(t testing.TB, rType, rName string) testChecks {
checks := newTestChecks(PrefixProviderName(rType) + "." + rName)
func (s *DeviceSwitchModel) testChecks(t testing.TB, rType, tName string, tracker *validators.FieldCoverageTracker) testChecks {
checks := newTestChecks(PrefixProviderName(rType) + "." + tName)
checks.SetTracker(tracker)

// Required string attributes
checks.append(t, "TestCheckResourceAttrSet", "site_id")
Expand Down
Loading
Loading