Skip to content

Commit

Permalink
Fix probe content type detection on Ubuntu 24.04 LTS (#921)
Browse files Browse the repository at this point in the history
* Fix pull request

* Fix pull request

* Fix pull request
  • Loading branch information
loicgreffier authored Jan 3, 2025
1 parent 9aaa594 commit b5e7898
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
back-end:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Checkout project
uses: actions/checkout@v4
Expand Down
39 changes: 21 additions & 18 deletions src/test/java/com/michelin/suricate/util/FilesUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.michelin.suricate.util;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.michelin.suricate.model.entity.Asset;
import java.io.File;
Expand All @@ -14,57 +16,58 @@ class FilesUtilsTest {
void shouldGetFolders() throws IOException {
List<File> actual = FilesUtils.getFolders(new File("src/test/resources/repository"));

assertThat(actual).hasSize(2);
assertThat(actual.get(0).getName()).contains("content");
assertThat(actual.get(1).getName()).contains("libraries");
assertEquals(2, actual.size());
assertTrue(actual.get(0).getName().contains("content"));
assertTrue(actual.get(1).getName().contains("libraries"));
}

@Test
void shouldGetNoFolder() throws IOException {
List<File> actual = FilesUtils.getFolders(null);

assertThat(actual).isEmpty();
assertTrue(actual.isEmpty());
}

@Test
void shouldGetFiles() throws IOException {
List<File> actual = FilesUtils.getFiles(new File("src/test/resources/repository/libraries"));

assertThat(actual).hasSize(1);
assertThat(actual.get(0).getName()).contains("test.js");
assertEquals(1, actual.size());
assertTrue(actual.getFirst().getName().contains("test.js"));
}

@Test
void shouldGetNoFile() throws IOException {
List<File> actual = FilesUtils.getFiles(null);

assertThat(actual).isEmpty();
assertTrue(actual.isEmpty());
}

@Test
void shouldReadJsAsset() throws IOException {
Asset actual = FilesUtils.readAsset(new File("src/test/resources/repository/libraries/test.js"));

assertThat(actual).isNotNull();
assertThat(actual.getContentType()).isEqualTo("application/javascript");
assertNotNull(actual);
assertEquals("application/javascript", actual.getContentType());
}

@Test
void shouldReadImageAsset() throws IOException {
Asset actual = FilesUtils.readAsset(
new File("src/test/resources/repository/content/github/widgets/count-issues/image.png"));
new File("src/test/resources/repository/content/github/widgets/count-issues/image.png")
);

assertThat(actual).isNotNull();
assertThat(actual.getContentType()).isEqualTo("image/png");
assertNotNull(actual);
assertEquals("image/png", actual.getContentType());
}

@Test
void shouldSetContentTypeToDefaultTextPlain() throws IOException {
Asset actual =
FilesUtils.readAsset(new File("src/test/resources/repository/content/other/description.yml"));
Asset actual = FilesUtils.readAsset(new File("src/test/resources/repository/content/other/description.yml"));

assertThat(actual.getContentType()).isEqualTo("text/plain");
assertThat(actual.getSize()).isPositive();
assertThat(actual.getContent()).isNotEmpty();
// Ubuntu 24.04 LTS returns "application/yaml"
assertTrue(List.of("text/plain", "application/yaml").contains(actual.getContentType()));
assertTrue(actual.getSize() > 0);
assertTrue(actual.getContent().length > 0);
}
}

0 comments on commit b5e7898

Please sign in to comment.