mirror of
https://github.com/securego/gosec.git
synced 2024-12-24 11:35:52 +00:00
Enable testifylint and fix up lint issues (#1276)
This commit is contained in:
parent
36c81ed69b
commit
54c2185ae6
2 changed files with 19 additions and 20 deletions
|
@ -23,6 +23,7 @@ linters:
|
|||
- nolintlint
|
||||
- revive
|
||||
- staticcheck
|
||||
- testifylint
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unparam
|
||||
|
@ -40,6 +41,9 @@ linters-settings:
|
|||
- all
|
||||
- '-SA1019'
|
||||
|
||||
testifylint:
|
||||
enable-all: true
|
||||
|
||||
revive:
|
||||
rules:
|
||||
- name: dot-imports
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/securego/gosec/v2/issue"
|
||||
)
|
||||
|
@ -44,17 +45,16 @@ func TestGenerateSolutionByGemini_Success(t *testing.T) {
|
|||
|
||||
mockClient := new(MockGenAIClient)
|
||||
mockModel := new(MockGenAIGenerativeModel)
|
||||
mockClient.On("GenerativeModel", GeminiModel).Return(mockModel)
|
||||
mockModel.On("GenerateContent", mock.Anything, mock.Anything).Return("Autofix for issue 1", nil)
|
||||
mockClient.On("GenerativeModel", GeminiModel).Return(mockModel).Once()
|
||||
mockModel.On("GenerateContent", mock.Anything, mock.Anything).Return("Autofix for issue 1", nil).Once()
|
||||
|
||||
// Act
|
||||
err := generateSolutionByGemini(mockClient, issues)
|
||||
|
||||
// Assert
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Autofix for issue 1", issues[0].Autofix)
|
||||
mockClient.AssertExpectations(t)
|
||||
mockModel.AssertExpectations(t)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*issue.Issue{{What: "Example issue 1", Autofix: "Autofix for issue 1"}}, issues)
|
||||
mock.AssertExpectationsForObjects(t, mockClient, mockModel)
|
||||
}
|
||||
|
||||
func TestGenerateSolutionByGemini_NoCandidates(t *testing.T) {
|
||||
|
@ -65,17 +65,15 @@ func TestGenerateSolutionByGemini_NoCandidates(t *testing.T) {
|
|||
|
||||
mockClient := new(MockGenAIClient)
|
||||
mockModel := new(MockGenAIGenerativeModel)
|
||||
mockClient.On("GenerativeModel", GeminiModel).Return(mockModel)
|
||||
mockModel.On("GenerateContent", mock.Anything, mock.Anything).Return("", nil)
|
||||
mockClient.On("GenerativeModel", GeminiModel).Return(mockModel).Once()
|
||||
mockModel.On("GenerateContent", mock.Anything, mock.Anything).Return("", nil).Once()
|
||||
|
||||
// Act
|
||||
err := generateSolutionByGemini(mockClient, issues)
|
||||
|
||||
// Assert
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "no autofix returned by gemini", err.Error())
|
||||
mockClient.AssertExpectations(t)
|
||||
mockModel.AssertExpectations(t)
|
||||
require.EqualError(t, err, "no autofix returned by gemini")
|
||||
mock.AssertExpectationsForObjects(t, mockClient, mockModel)
|
||||
}
|
||||
|
||||
func TestGenerateSolutionByGemini_APIError(t *testing.T) {
|
||||
|
@ -86,17 +84,15 @@ func TestGenerateSolutionByGemini_APIError(t *testing.T) {
|
|||
|
||||
mockClient := new(MockGenAIClient)
|
||||
mockModel := new(MockGenAIGenerativeModel)
|
||||
mockClient.On("GenerativeModel", GeminiModel).Return(mockModel)
|
||||
mockModel.On("GenerateContent", mock.Anything, mock.Anything).Return("", errors.New("API error"))
|
||||
mockClient.On("GenerativeModel", GeminiModel).Return(mockModel).Once()
|
||||
mockModel.On("GenerateContent", mock.Anything, mock.Anything).Return("", errors.New("API error")).Once()
|
||||
|
||||
// Act
|
||||
err := generateSolutionByGemini(mockClient, issues)
|
||||
|
||||
// Assert
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "generating autofix with gemini: API error", err.Error())
|
||||
mockClient.AssertExpectations(t)
|
||||
mockModel.AssertExpectations(t)
|
||||
require.EqualError(t, err, "generating autofix with gemini: API error")
|
||||
mock.AssertExpectationsForObjects(t, mockClient, mockModel)
|
||||
}
|
||||
|
||||
func TestGenerateSolution_UnsupportedProvider(t *testing.T) {
|
||||
|
@ -109,6 +105,5 @@ func TestGenerateSolution_UnsupportedProvider(t *testing.T) {
|
|||
err := GenerateSolution("unsupported-provider", "test-api-key", "", issues)
|
||||
|
||||
// Assert
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "ai provider not supported", err.Error())
|
||||
require.EqualError(t, err, "ai provider not supported")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue