forked from Antonboom/testifylint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Antonboom#64 from Antonboom/fixes/require-error-el…
…se-if require-error: support '} else if'
- Loading branch information
Showing
3 changed files
with
129 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
analyzer/testdata/src/require-error-skip-logic/else_if_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package requireerrorskiplogic | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestComplexCondition(t *testing.T) { | ||
testCases := []struct { | ||
testName string | ||
someValue any | ||
someOtherValue any | ||
expectedError error | ||
expectedValue any | ||
}{ | ||
{}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.testName, func(t *testing.T) { | ||
result, err := operationWithResult() | ||
if tc.someValue == nil && tc.someOtherValue == nil { | ||
assert.Nil(t, result) | ||
assert.NoError(t, err) | ||
} else if tc.someOtherValue != nil { | ||
assert.EqualError(t, err, tc.expectedError.Error()) | ||
} else { | ||
assert.Equal(t, tc.expectedError, err) | ||
assert.Equal(t, tc.expectedValue, result) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestCrazyCondition(t *testing.T) { | ||
testCases := []struct { | ||
testName string | ||
someValue any | ||
someOtherValue any | ||
expectedError error | ||
expectedValue any | ||
}{ | ||
{}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.testName, func(t *testing.T) { | ||
result, err := operationWithResult() | ||
if tc.someValue == nil && tc.someOtherValue == nil { | ||
assert.Nil(t, result) | ||
assert.NoError(t, err) | ||
} else if tc.someOtherValue != nil { | ||
assert.EqualError(t, err, tc.expectedError.Error()) | ||
} else if tc.someOtherValue == nil { | ||
require.NoError(t, err) | ||
assert.Equal(t, tc.expectedError, err) | ||
assert.Equal(t, tc.expectedValue, result) | ||
} else if tc.someValue != nil { | ||
assert.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAssertInElseIf(t *testing.T) { | ||
for _, tc := range []struct { | ||
filenames []string | ||
restartCount int | ||
}{ | ||
{}, | ||
} { | ||
t.Run("", func(t *testing.T) { | ||
count, err := calcRestartCountByLogDir(tc.filenames) | ||
if assert.NoError(t, err) { | ||
assert.Equal(t, count, tc.restartCount) | ||
assert.NoError(t, err) | ||
} else if true { | ||
assert.Error(t, err) | ||
assert.Equal(t, count, tc.restartCount) | ||
} else { | ||
assert.Error(t, err) | ||
assert.Equal(t, count, tc.restartCount) | ||
} | ||
|
||
if true { | ||
assert.Equal(t, count, tc.restartCount) | ||
assert.NoError(t, err) | ||
} else if assert.NoError(t, err) { | ||
assert.Error(t, err) | ||
assert.Equal(t, count, tc.restartCount) | ||
} else { | ||
assert.Error(t, err) | ||
assert.Equal(t, count, tc.restartCount) | ||
} | ||
|
||
assert.NoError(t, operation()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters