Skip to content

Commit cb1ac56

Browse files
authored
feat: added integration tests for auto org (#1052)
* feat: added integration tests for auto org * fix: added integration tests for folder org for code and test refactor * fix: use valid uuids for org * fix: update the integration tests for folder org * fix: add test for multiple folders with orgs for feature flags * fix: add folder org tests for autofix * fix: add folder org test for sarif * fix: use IntegTest for integration tests * fix: allow sast scans to run in test * fix: handle explain endpoint returnm error in integration tests * fix: revert removal av sast checks * fix: make tests use the new setupWorkspace function * fix: removed NewMockCodeIssue as it is no longer being used * fix: make NewMockIssues available for tests outside of workspace * fix: updated integration tests for crud ignroes All three operations (Create, Edit, Delete) now follow the same integration test pattern: Full end-to-end execution Mock engine setup with folder configs Workflow invocation verification Consistent structure across all three operations The tests verify that: The correct folder-specific org is used in the workflow configuration The full command execution path works correctly The workflow is invoked with the expected organization * fix: refactor to remove code duplication * fix: fixing review comments Refactored CLI test utilities: moved executeAndCaptureConfig to a shared location in testutil to eliminate duplication Package renaming: renamed workspace package to workspaceutil to avoid import aliases Test improvements: enhanced feature flag test to verify cached values, not just key existence Code cleanup: removed duplicate functions, unused imports, and improved test structure * fix: replace testutils.SetupFakeWorkspace with workspaceutil.SetupWorkspace * fix: updated integration test for Test_CodeConfig_FallsBackToGlobalOrg * fix: update integration test for Test_CodeConfig_UsesFolderOrganization * fix: removed Test_GetCodeApiUrlForFolder_UsesFolderOrganization since it is covered by the new integration test * fix: refactored the rest of the tests in code integration tests * fix: move unit tests from integration test files * fix: cleanup tests * fix: fix test to use imagecache
1 parent 659b8a9 commit cb1ac56

23 files changed

+1263
-277
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ application/server/diagnostic_comparison.md
5858

5959
# Compatibility matrix cache
6060
.cache/compatibility-matrix/
61+
62+
# Snyk Security Extension - AI Rules (auto-generated)
63+
.cursor/rules/snyk_rules.mdc

application/codeaction/codeaction_test.go

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,13 @@ import (
2828
"github.com/snyk/snyk-ls/application/config"
2929
"github.com/snyk/snyk-ls/application/watcher"
3030
"github.com/snyk/snyk-ls/domain/ide/converter"
31-
"github.com/snyk/snyk-ls/domain/ide/hover"
32-
"github.com/snyk/snyk-ls/domain/ide/workspace"
33-
"github.com/snyk/snyk-ls/domain/scanstates"
3431
"github.com/snyk/snyk-ls/domain/snyk"
3532
"github.com/snyk/snyk-ls/domain/snyk/mock_snyk"
36-
"github.com/snyk/snyk-ls/domain/snyk/scanner"
3733
"github.com/snyk/snyk-ls/infrastructure/code"
3834
"github.com/snyk/snyk-ls/infrastructure/featureflag"
3935
"github.com/snyk/snyk-ls/internal/notification"
40-
"github.com/snyk/snyk-ls/internal/observability/performance"
4136
"github.com/snyk/snyk-ls/internal/testutil"
37+
"github.com/snyk/snyk-ls/internal/testutil/workspaceutil"
4238
"github.com/snyk/snyk-ls/internal/types"
4339
"github.com/snyk/snyk-ls/internal/uri"
4440
)
@@ -56,27 +52,6 @@ var exampleRange = sglsp.Range{
5652

5753
const documentUriExample = sglsp.DocumentURI("file:///path/to/file")
5854

59-
// setupTestWorkspace creates a minimal workspace with a folder for testing
60-
func setupTestWorkspace(c *config.Config) {
61-
if c.Workspace() != nil {
62-
return // Already initialized
63-
}
64-
65-
// Create workspace with minimal dependencies
66-
notifier := notification.NewMockNotifier()
67-
scanNotifier := scanner.NewMockScanNotifier()
68-
scanStateAggregator := scanstates.NewNoopStateAggregator()
69-
sc := scanner.NewTestScanner()
70-
71-
w := workspace.New(c, performance.NewInstrumentor(), sc, hover.NewFakeHoverService(), scanNotifier, notifier, nil, scanStateAggregator, featureflag.NewFakeService())
72-
73-
// Add a folder that contains the test file path
74-
folder := workspace.NewFolder(c, "/path/to", "test-folder", sc, nil, scanNotifier, notifier, nil, scanStateAggregator, featureflag.NewFakeService())
75-
w.AddFolder(folder)
76-
77-
c.SetWorkspace(w)
78-
}
79-
8055
func Test_GetCodeActions_ReturnsCorrectActions(t *testing.T) {
8156
c := testutil.UnitTest(t)
8257
expectedIssue := &snyk.Issue{
@@ -124,7 +99,9 @@ func Test_GetCodeActions_NoIssues_ReturnsNil(t *testing.T) {
12499
// It doesn't seem like there's a difference between returning a nil and returning an empty array. If this assumption
125100
// is proved to be false, this test can be changed.
126101
// Arrange
127-
setupTestWorkspace(c)
102+
// Set up workspace with folder that contains the test file path
103+
// The document URI is "file:///path/to/file", so the folder should be "/path/to"
104+
_, _ = workspaceutil.SetupWorkspace(t, c, types.FilePath("/path/to"))
128105

129106
ctrl := gomock.NewController(t)
130107
var issues []types.Issue
@@ -297,7 +274,9 @@ func Test_UpdateIssuesWithQuickFix_TitleConcatenationIssue_WhenCalledMultipleTim
297274

298275
func setupService(t *testing.T, c *config.Config) *codeaction.CodeActionsService {
299276
t.Helper()
300-
setupTestWorkspace(c)
277+
// Set up workspace with folder that contains the test file path
278+
// The document URI is "file:///path/to/file", so the folder should be "/path/to"
279+
_, _ = workspaceutil.SetupWorkspace(t, c, types.FilePath("/path/to"))
301280

302281
providerMock := mock_snyk.NewMockIssueProvider(gomock.NewController(t))
303282
providerMock.EXPECT().IssuesForRange(gomock.Any(), gomock.Any()).Return([]types.Issue{}).AnyTimes()
@@ -311,7 +290,9 @@ func setupWithSingleIssue(t *testing.T, c *config.Config, issue types.Issue) (*c
311290
uriPath := documentUriExample
312291
path := uri.PathFromUri(uriPath)
313292

314-
setupTestWorkspace(c)
293+
// Set up workspace with folder that contains the test file path
294+
// The document URI is "file:///path/to/file", so the folder should be "/path/to"
295+
_, _ = workspaceutil.SetupWorkspace(t, c, types.FilePath("/path/to"))
315296

316297
providerMock := mock_snyk.NewMockIssueProvider(gomock.NewController(t))
317298
issues := []types.Issue{issue}

application/server/inline_values_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package server
1818

1919
import (
20-
"os"
2120
"path/filepath"
2221
"testing"
2322
"time"
@@ -60,7 +59,7 @@ func Test_textDocumentInlineValues_InlineValues_IntegTest(t *testing.T) {
6059
ActivateSnykOpenSource: "true",
6160
ActivateSnykIac: "false",
6261
EnableTrustedFoldersFeature: "false",
63-
Token: os.Getenv("SNYK_TOKEN"),
62+
Token: c.Token(),
6463
CliPath: filepath.Join(t.TempDir(), discovery.ExecutableName(false)),
6564
},
6665
}

domain/ide/command/code_fix_feedback_test.go

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,10 @@ import (
2424

2525
"github.com/snyk/code-client-go/llm"
2626

27-
"github.com/snyk/snyk-ls/application/config"
28-
"github.com/snyk/snyk-ls/domain/ide/workspace"
29-
"github.com/snyk/snyk-ls/domain/scanstates"
30-
"github.com/snyk/snyk-ls/domain/snyk/persistence"
31-
"github.com/snyk/snyk-ls/domain/snyk/scanner"
3227
"github.com/snyk/snyk-ls/infrastructure/code"
3328
"github.com/snyk/snyk-ls/infrastructure/featureflag"
34-
"github.com/snyk/snyk-ls/internal/notification"
35-
"github.com/snyk/snyk-ls/internal/observability/performance"
3629
"github.com/snyk/snyk-ls/internal/testutil"
30+
"github.com/snyk/snyk-ls/internal/testutil/workspaceutil"
3731
"github.com/snyk/snyk-ls/internal/types"
3832
)
3933

@@ -83,7 +77,7 @@ func Test_getFolderFromFixId_ReturnsErrorWhenFixIdNotFound(t *testing.T) {
8377
c := testutil.UnitTest(t)
8478

8579
// Setup workspace with folders
86-
setupWorkspaceWithFolders(t, c, []string{"/workspace/folder1", "/workspace/folder2"})
80+
_, _ = workspaceutil.SetupWorkspace(t, c, types.FilePath("/workspace/folder1"), types.FilePath("/workspace/folder2"))
8781

8882
// Initialize HtmlRenderer
8983
fakeFFService := featureflag.NewFakeService()
@@ -102,7 +96,7 @@ func Test_getFolderFromFixId_ReturnsCorrectFolder(t *testing.T) {
10296
c := testutil.UnitTest(t)
10397

10498
// Setup workspace with folders
105-
setupWorkspaceWithFolders(t, c, []string{"/workspace/folder1", "/workspace/folder2"})
99+
_, _ = workspaceutil.SetupWorkspace(t, c, types.FilePath("/workspace/folder1"), types.FilePath("/workspace/folder2"))
106100

107101
// Initialize HtmlRenderer
108102
fakeFFService := featureflag.NewFakeService()
@@ -134,7 +128,7 @@ func Test_getFolderFromFixId_ReturnsErrorWhenFileNotInAnyFolder(t *testing.T) {
134128
c := testutil.UnitTest(t)
135129

136130
// Setup workspace with folders
137-
setupWorkspaceWithFolders(t, c, []string{"/workspace/folder1", "/workspace/folder2"})
131+
_, _ = workspaceutil.SetupWorkspace(t, c, types.FilePath("/workspace/folder1"), types.FilePath("/workspace/folder2"))
138132

139133
// Initialize HtmlRenderer
140134
fakeFFService := featureflag.NewFakeService()
@@ -166,7 +160,7 @@ func Test_getFolderFromFixId_HandlesMultipleFolders(t *testing.T) {
166160
c := testutil.UnitTest(t)
167161

168162
// Setup workspace with multiple folders
169-
setupWorkspaceWithFolders(t, c, []string{"/workspace/project1", "/workspace/project2", "/workspace/project3"})
163+
_, _ = workspaceutil.SetupWorkspace(t, c, types.FilePath("/workspace/project1"), types.FilePath("/workspace/project2"), types.FilePath("/workspace/project3"))
170164

171165
// Initialize HtmlRenderer
172166
fakeFFService := featureflag.NewFakeService()
@@ -208,44 +202,3 @@ func Test_getFolderFromFixId_HandlesMultipleFolders(t *testing.T) {
208202
require.NoError(t, err)
209203
assert.Equal(t, types.FilePath("/workspace/project3"), result3)
210204
}
211-
212-
// setupWorkspaceWithFolders creates a workspace with the specified folder paths
213-
func setupWorkspaceWithFolders(t *testing.T, c *config.Config, folderPaths []string) {
214-
t.Helper()
215-
216-
sc := &scanner.TestScanner{}
217-
scanNotifier := scanner.NewMockScanNotifier()
218-
scanPersister := persistence.NewGitPersistenceProvider(c.Logger(), c.Engine().GetConfiguration())
219-
scanStateAggregator := scanstates.NewNoopStateAggregator()
220-
fakeFFService := featureflag.NewFakeService()
221-
222-
w := workspace.New(
223-
c,
224-
performance.NewInstrumentor(),
225-
sc,
226-
nil,
227-
scanNotifier,
228-
notification.NewMockNotifier(),
229-
scanPersister,
230-
scanStateAggregator,
231-
fakeFFService,
232-
)
233-
234-
for _, folderPath := range folderPaths {
235-
folder := workspace.NewFolder(
236-
c,
237-
types.FilePath(folderPath),
238-
folderPath,
239-
sc,
240-
nil,
241-
scanNotifier,
242-
notification.NewMockNotifier(),
243-
scanPersister,
244-
scanStateAggregator,
245-
fakeFFService,
246-
)
247-
w.AddFolder(folder)
248-
}
249-
250-
c.SetWorkspace(w)
251-
}

domain/ide/command/folder_handler_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ import (
3030
"github.com/snyk/go-application-framework/pkg/workflow"
3131

3232
"github.com/snyk/snyk-ls/application/config"
33-
"github.com/snyk/snyk-ls/domain/ide/command/testutils"
3433
"github.com/snyk/snyk-ls/infrastructure/featureflag"
3534
"github.com/snyk/snyk-ls/internal/constants"
3635
"github.com/snyk/snyk-ls/internal/storedconfig"
3736
"github.com/snyk/snyk-ls/internal/testutil"
37+
"github.com/snyk/snyk-ls/internal/testutil/workspaceutil"
3838
"github.com/snyk/snyk-ls/internal/types"
3939
"github.com/snyk/snyk-ls/internal/types/mock_types"
4040
"github.com/snyk/snyk-ls/internal/util"
@@ -86,7 +86,8 @@ func Test_sendFolderConfigs_SendsNotification(t *testing.T) {
8686
setupMockOrgResolver(t, expectedOrg)
8787

8888
// Setup workspace with a folder
89-
notifier, folderPaths := testutils.SetupFakeWorkspace(t, c, 1)
89+
folderPaths := []types.FilePath{types.FilePath("/fake/test-folder-0")}
90+
_, notifier := workspaceutil.SetupWorkspace(t, c, folderPaths...)
9091

9192
logger := c.Logger()
9293
storedConfig := &types.FolderConfig{
@@ -117,7 +118,7 @@ func Test_sendFolderConfigs_NoFolders_NoNotification(t *testing.T) {
117118
_, _ = testutil.SetUpEngineMock(t, c)
118119

119120
// Setup workspace with no folders
120-
notifier, _ := testutils.SetupFakeWorkspace(t, c, 0)
121+
_, notifier := workspaceutil.SetupWorkspace(t, c)
121122

122123
sendFolderConfigs(c, notifier, featureflag.NewFakeService())
123124

@@ -225,7 +226,8 @@ func Test_sendFolderConfigs_LdxSyncError_ContinuesProcessing(t *testing.T) {
225226
setupMockOrgResolverWithError(t, assert.AnError)
226227

227228
// Setup workspace with a folder
228-
notifier, folderPaths := testutils.SetupFakeWorkspace(t, c, 1)
229+
folderPaths := []types.FilePath{types.FilePath("/fake/test-folder-0")}
230+
_, notifier := workspaceutil.SetupWorkspace(t, c, folderPaths...)
229231

230232
logger := c.Logger()
231233
storedConfig := &types.FolderConfig{
@@ -276,7 +278,11 @@ func Test_sendFolderConfigs_MultipleFolders_DifferentOrgConfigs(t *testing.T) {
276278
SetService(mockService)
277279

278280
// Setup workspace with multiple folders
279-
notifier, folderPaths := testutils.SetupFakeWorkspace(t, c, 2)
281+
folderPaths := []types.FilePath{
282+
types.FilePath("/fake/test-folder-0"),
283+
types.FilePath("/fake/test-folder-1"),
284+
}
285+
_, notifier := workspaceutil.SetupWorkspace(t, c, folderPaths...)
280286

281287
logger := c.Logger()
282288

0 commit comments

Comments
 (0)