mirror of
https://github.com/securego/gosec.git
synced 2024-12-25 12:05: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
|
- nolintlint
|
||||||
- revive
|
- revive
|
||||||
- staticcheck
|
- staticcheck
|
||||||
|
- testifylint
|
||||||
- typecheck
|
- typecheck
|
||||||
- unconvert
|
- unconvert
|
||||||
- unparam
|
- unparam
|
||||||
|
@ -40,6 +41,9 @@ linters-settings:
|
||||||
- all
|
- all
|
||||||
- '-SA1019'
|
- '-SA1019'
|
||||||
|
|
||||||
|
testifylint:
|
||||||
|
enable-all: true
|
||||||
|
|
||||||
revive:
|
revive:
|
||||||
rules:
|
rules:
|
||||||
- name: dot-imports
|
- name: dot-imports
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/securego/gosec/v2/issue"
|
"github.com/securego/gosec/v2/issue"
|
||||||
)
|
)
|
||||||
|
@ -44,17 +45,16 @@ func TestGenerateSolutionByGemini_Success(t *testing.T) {
|
||||||
|
|
||||||
mockClient := new(MockGenAIClient)
|
mockClient := new(MockGenAIClient)
|
||||||
mockModel := new(MockGenAIGenerativeModel)
|
mockModel := new(MockGenAIGenerativeModel)
|
||||||
mockClient.On("GenerativeModel", GeminiModel).Return(mockModel)
|
mockClient.On("GenerativeModel", GeminiModel).Return(mockModel).Once()
|
||||||
mockModel.On("GenerateContent", mock.Anything, mock.Anything).Return("Autofix for issue 1", nil)
|
mockModel.On("GenerateContent", mock.Anything, mock.Anything).Return("Autofix for issue 1", nil).Once()
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
err := generateSolutionByGemini(mockClient, issues)
|
err := generateSolutionByGemini(mockClient, issues)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "Autofix for issue 1", issues[0].Autofix)
|
assert.Equal(t, []*issue.Issue{{What: "Example issue 1", Autofix: "Autofix for issue 1"}}, issues)
|
||||||
mockClient.AssertExpectations(t)
|
mock.AssertExpectationsForObjects(t, mockClient, mockModel)
|
||||||
mockModel.AssertExpectations(t)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateSolutionByGemini_NoCandidates(t *testing.T) {
|
func TestGenerateSolutionByGemini_NoCandidates(t *testing.T) {
|
||||||
|
@ -65,17 +65,15 @@ func TestGenerateSolutionByGemini_NoCandidates(t *testing.T) {
|
||||||
|
|
||||||
mockClient := new(MockGenAIClient)
|
mockClient := new(MockGenAIClient)
|
||||||
mockModel := new(MockGenAIGenerativeModel)
|
mockModel := new(MockGenAIGenerativeModel)
|
||||||
mockClient.On("GenerativeModel", GeminiModel).Return(mockModel)
|
mockClient.On("GenerativeModel", GeminiModel).Return(mockModel).Once()
|
||||||
mockModel.On("GenerateContent", mock.Anything, mock.Anything).Return("", nil)
|
mockModel.On("GenerateContent", mock.Anything, mock.Anything).Return("", nil).Once()
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
err := generateSolutionByGemini(mockClient, issues)
|
err := generateSolutionByGemini(mockClient, issues)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assert.Error(t, err)
|
require.EqualError(t, err, "no autofix returned by gemini")
|
||||||
assert.Equal(t, "no autofix returned by gemini", err.Error())
|
mock.AssertExpectationsForObjects(t, mockClient, mockModel)
|
||||||
mockClient.AssertExpectations(t)
|
|
||||||
mockModel.AssertExpectations(t)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateSolutionByGemini_APIError(t *testing.T) {
|
func TestGenerateSolutionByGemini_APIError(t *testing.T) {
|
||||||
|
@ -86,17 +84,15 @@ func TestGenerateSolutionByGemini_APIError(t *testing.T) {
|
||||||
|
|
||||||
mockClient := new(MockGenAIClient)
|
mockClient := new(MockGenAIClient)
|
||||||
mockModel := new(MockGenAIGenerativeModel)
|
mockModel := new(MockGenAIGenerativeModel)
|
||||||
mockClient.On("GenerativeModel", GeminiModel).Return(mockModel)
|
mockClient.On("GenerativeModel", GeminiModel).Return(mockModel).Once()
|
||||||
mockModel.On("GenerateContent", mock.Anything, mock.Anything).Return("", errors.New("API error"))
|
mockModel.On("GenerateContent", mock.Anything, mock.Anything).Return("", errors.New("API error")).Once()
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
err := generateSolutionByGemini(mockClient, issues)
|
err := generateSolutionByGemini(mockClient, issues)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assert.Error(t, err)
|
require.EqualError(t, err, "generating autofix with gemini: API error")
|
||||||
assert.Equal(t, "generating autofix with gemini: API error", err.Error())
|
mock.AssertExpectationsForObjects(t, mockClient, mockModel)
|
||||||
mockClient.AssertExpectations(t)
|
|
||||||
mockModel.AssertExpectations(t)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateSolution_UnsupportedProvider(t *testing.T) {
|
func TestGenerateSolution_UnsupportedProvider(t *testing.T) {
|
||||||
|
@ -109,6 +105,5 @@ func TestGenerateSolution_UnsupportedProvider(t *testing.T) {
|
||||||
err := GenerateSolution("unsupported-provider", "test-api-key", "", issues)
|
err := GenerateSolution("unsupported-provider", "test-api-key", "", issues)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assert.Error(t, err)
|
require.EqualError(t, err, "ai provider not supported")
|
||||||
assert.Equal(t, "ai provider not supported", err.Error())
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue