mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-13 09:32:24 -06:00
states/remote: use t.Run in table-based tests
These tests were originally written long before Go supported subtests explicitly, but now that we have t.Run we can avoid the prior problem that one test failing would mask all of the others that followed it. Now we'll always run all of them, potentially collecting more errors in a single run so we can have more context to debug with and potentially fix them all in a single step rather than one by one.
This commit is contained in:
parent
ad5ac89461
commit
69aa0a2b1f
@ -245,6 +245,7 @@ func TestStatePersist(t *testing.T) {
|
|||||||
|
|
||||||
// Run tests in order.
|
// Run tests in order.
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
s, cleanup := tc.mutationFunc(mgr)
|
s, cleanup := tc.mutationFunc(mgr)
|
||||||
|
|
||||||
if err := mgr.WriteState(s); err != nil {
|
if err := mgr.WriteState(s); err != nil {
|
||||||
@ -267,6 +268,7 @@ func TestStatePersist(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cleanup()
|
cleanup()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
logCnt := len(mockClient.log)
|
logCnt := len(mockClient.log)
|
||||||
if logIdx != logCnt {
|
if logIdx != logCnt {
|
||||||
@ -395,6 +397,7 @@ func TestWriteStateForMigration(t *testing.T) {
|
|||||||
logIdx := 0
|
logIdx := 0
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
sf := tc.stateFile(mgr)
|
sf := tc.stateFile(mgr)
|
||||||
err := mgr.WriteStateForMigration(sf, tc.force)
|
err := mgr.WriteStateForMigration(sf, tc.force)
|
||||||
shouldError := tc.expectedError != ""
|
shouldError := tc.expectedError != ""
|
||||||
@ -406,7 +409,7 @@ func TestWriteStateForMigration(t *testing.T) {
|
|||||||
} else if err.Error() != tc.expectedError {
|
} else if err.Error() != tc.expectedError {
|
||||||
t.Fatalf("test case %q expected error %q but got %q", tc.name, tc.expectedError, err)
|
t.Fatalf("test case %q expected error %q but got %q", tc.name, tc.expectedError, err)
|
||||||
}
|
}
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -426,6 +429,7 @@ func TestWriteStateForMigration(t *testing.T) {
|
|||||||
if diff := cmp.Diff(tc.expectedRequest, loggedRequest); len(diff) > 0 {
|
if diff := cmp.Diff(tc.expectedRequest, loggedRequest); len(diff) > 0 {
|
||||||
t.Fatalf("incorrect client requests for %q:\n%s", tc.name, diff)
|
t.Fatalf("incorrect client requests for %q:\n%s", tc.name, diff)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
logCnt := len(mockClient.log)
|
logCnt := len(mockClient.log)
|
||||||
@ -551,6 +555,7 @@ func TestWriteStateForMigrationWithForcePushClient(t *testing.T) {
|
|||||||
logIdx := 0
|
logIdx := 0
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
// Always reset client to not be force pushing
|
// Always reset client to not be force pushing
|
||||||
mockClient.force = false
|
mockClient.force = false
|
||||||
sf := tc.stateFile(mgr)
|
sf := tc.stateFile(mgr)
|
||||||
@ -564,7 +569,7 @@ func TestWriteStateForMigrationWithForcePushClient(t *testing.T) {
|
|||||||
} else if err.Error() != tc.expectedError {
|
} else if err.Error() != tc.expectedError {
|
||||||
t.Fatalf("test case %q expected error %q but got %q", tc.name, tc.expectedError, err)
|
t.Fatalf("test case %q expected error %q but got %q", tc.name, tc.expectedError, err)
|
||||||
}
|
}
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -588,6 +593,7 @@ func TestWriteStateForMigrationWithForcePushClient(t *testing.T) {
|
|||||||
if diff := cmp.Diff(tc.expectedRequest, loggedRequest); len(diff) > 0 {
|
if diff := cmp.Diff(tc.expectedRequest, loggedRequest); len(diff) > 0 {
|
||||||
t.Fatalf("incorrect client requests for %q:\n%s", tc.name, diff)
|
t.Fatalf("incorrect client requests for %q:\n%s", tc.name, diff)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
logCnt := len(mockClient.log)
|
logCnt := len(mockClient.log)
|
||||||
|
Loading…
Reference in New Issue
Block a user