Skip to content

Commit

Permalink
Merge branch 'main' into breedloj/proxyUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
breedloj authored Jan 27, 2025
2 parents 713842a + 31eba90 commit a9971da
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugin/build/syncDependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if [ ! -f "$manifest_file" ]; then
fi

# Initialize the Bundle-Classpath entry
bundle_classpath="Bundle-Classpath: target/classes/,\n"
bundle_classpath="Bundle-Classpath: .,\n"

# Loop through the JAR files in the dependency directory
for jar in "$dependency_dir"/*.jar; do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package software.aws.toolkits.eclipse.amazonq.lsp.manager.fetcher;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.FileNotFoundException;
Expand Down Expand Up @@ -66,9 +68,11 @@

public final class RemoteLspFetcherTest {
private static VersionRange versionRange;
private static String majorVersion;
static {
try {
versionRange = VersionRange.createFromVersionSpec("[1.0.0, 2.0.0]");
majorVersion = "1";
} catch (InvalidVersionSpecificationException e) {
throw new AmazonQPluginException("Failed to parse LSP supported version range", e);
}
Expand Down Expand Up @@ -334,6 +338,65 @@ void fetchWhenMultipleLabelVersionsChooseLatest() throws IOException, Interrupte
assertTrue(zipContentsMatchUnzipped(zipPath, unzippedPath));
}

@Test
void testCleanup() throws IOException {

//set up compatible versions
String sampleLspVersionV2 = String.format("%s.1.0", majorVersion);
String sampleLspVersionV3 = String.format("%s.2.0", majorVersion);
sampleManifest = createManifest(
List.of(
sampleLspVersion,
createLspVersion(sampleLspVersionV2),
createLspVersion(sampleLspVersionV3))
);

//create the compatible versions
Path acceptedVersion1 = Files.createDirectory(tempDir.resolve("1.7.0"));
Path acceptedVersion2 = Files.createDirectory(tempDir.resolve("1.2.0"));

//create delisted versions
Path delistedVersion1 = Files.createDirectory(tempDir.resolve("2.0.0"));
Path delistedVersion2 = Files.createDirectory(tempDir.resolve("1.0.0"));

//create extra version
Path extraVersion1 = Files.createDirectory(tempDir.resolve("1.1.0"));

//verify existence of files
assertTrue(Files.exists(acceptedVersion1));
assertTrue(Files.exists(acceptedVersion2));
assertTrue(Files.exists(extraVersion1));
assertTrue(Files.exists(delistedVersion1));
assertTrue(Files.exists(delistedVersion2));

lspFetcher = createFetcher();
lspFetcher.cleanup(tempDir);

//verify compatible versions still exist
assertTrue(Files.exists(acceptedVersion1));
assertTrue(Files.exists(acceptedVersion2));

//verify delisted versions were deleted
assertFalse(Files.exists(delistedVersion1));
assertFalse(Files.exists(delistedVersion2));
verify(mockLogger).info("Cleaning up 2 cached de-listed versions for Amazon Q Language Server");

//verify extra versions were deleted
assertFalse(Files.exists(extraVersion1));
verify(mockLogger).info("Cleaning up 1 cached extra versions for Amazon Q Language Server");
}

@Test
void testCleanupNullManifest() throws IOException {
sampleManifest = null;
Path delistedVersion1 = Files.createDirectory(tempDir.resolve("1.0.0"));
lspFetcher = createFetcher();
lspFetcher.cleanup(tempDir);

assertTrue(Files.exists(tempDir));
assertTrue(Files.exists(delistedVersion1));
}

private HttpResponse<Path> createMockHttpResponse(final Path file, final int statusCode) {
@SuppressWarnings("unchecked")
HttpResponse<Path> response = mock(HttpResponse.class);
Expand Down

0 comments on commit a9971da

Please sign in to comment.