Skip to content

Commit 2491e7e

Browse files
extract: add subtest using targetvar
1 parent dd07ec6 commit 2491e7e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

statecheck/extract_bool_value_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package statecheck_test
55

66
import (
7+
"fmt"
78
"regexp"
89
"testing"
910

@@ -42,6 +43,13 @@ func TestExtractBoolValue_Basic(t *testing.T) {
4243
},
4344
},
4445
})
46+
47+
t.Run("CheckTargetVar", func(t *testing.T) {
48+
// Now use the testAccAssertBoolEquals function to verify the value of targetVar
49+
if err := testAccAssertBoolEquals(true, targetVar); err != nil {
50+
t.Errorf("Error in testAccAssertBoolEquals: %v", err)
51+
}
52+
})
4553
}
4654

4755
func TestExtractBoolValue_KnownValueWrongType(t *testing.T) {
@@ -136,3 +144,11 @@ func TestExtractBoolValue_ResourceNotFound(t *testing.T) {
136144
},
137145
})
138146
}
147+
148+
// testAccAssertBoolEquals compares the expected and target bool values.
149+
func testAccAssertBoolEquals(expected bool, targetVar bool) error {
150+
if targetVar != expected {
151+
return fmt.Errorf("expected targetVar to be %v, got %v", expected, targetVar)
152+
}
153+
return nil
154+
}

statecheck/extract_string_value_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package statecheck_test
55

66
import (
7+
"fmt"
78
"testing"
89

910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -41,4 +42,19 @@ func TestExtractStringValue_Basic(t *testing.T) {
4142
},
4243
},
4344
})
45+
46+
t.Run("CheckTargetVar", func(t *testing.T) {
47+
// Now use the testAccAssertBoolEquals function to verify the value of targetVar
48+
if err := testAccAssertStringEquals("str", targetVar); err != nil {
49+
t.Errorf("Error in testAccAssertBoolEquals: %v", err)
50+
}
51+
})
52+
}
53+
54+
// testAccAssertStringEquals compares the expected and target string values.
55+
func testAccAssertStringEquals(expected string, targetVar string) error {
56+
if targetVar != expected {
57+
return fmt.Errorf("expected targetVar to be %v, got %v", expected, targetVar)
58+
}
59+
return nil
4460
}

0 commit comments

Comments
 (0)