Skip to content

Commit

Permalink
extract: add subtest using targetvar
Browse files Browse the repository at this point in the history
  • Loading branch information
bschaatsbergen committed Jan 14, 2025
1 parent dd07ec6 commit 2491e7e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions statecheck/extract_bool_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package statecheck_test

import (
"fmt"
"regexp"
"testing"

Expand Down Expand Up @@ -42,6 +43,13 @@ func TestExtractBoolValue_Basic(t *testing.T) {
},
},
})

t.Run("CheckTargetVar", func(t *testing.T) {
// Now use the testAccAssertBoolEquals function to verify the value of targetVar
if err := testAccAssertBoolEquals(true, targetVar); err != nil {
t.Errorf("Error in testAccAssertBoolEquals: %v", err)
}
})
}

func TestExtractBoolValue_KnownValueWrongType(t *testing.T) {
Expand Down Expand Up @@ -136,3 +144,11 @@ func TestExtractBoolValue_ResourceNotFound(t *testing.T) {
},
})
}

// testAccAssertBoolEquals compares the expected and target bool values.
func testAccAssertBoolEquals(expected bool, targetVar bool) error {
if targetVar != expected {
return fmt.Errorf("expected targetVar to be %v, got %v", expected, targetVar)
}
return nil
}
16 changes: 16 additions & 0 deletions statecheck/extract_string_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package statecheck_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -41,4 +42,19 @@ func TestExtractStringValue_Basic(t *testing.T) {
},
},
})

t.Run("CheckTargetVar", func(t *testing.T) {
// Now use the testAccAssertBoolEquals function to verify the value of targetVar
if err := testAccAssertStringEquals("str", targetVar); err != nil {
t.Errorf("Error in testAccAssertBoolEquals: %v", err)
}
})
}

// testAccAssertStringEquals compares the expected and target string values.
func testAccAssertStringEquals(expected string, targetVar string) error {
if targetVar != expected {
return fmt.Errorf("expected targetVar to be %v, got %v", expected, targetVar)
}
return nil
}

0 comments on commit 2491e7e

Please sign in to comment.