Skip to content

Commit

Permalink
Fixed tests. Due to removed youtube-dl all commands use yt-dlp's para…
Browse files Browse the repository at this point in the history
…meters '--compat-options' and 'all'. They need to be taken into account in the tests
  • Loading branch information
scavchik committed Sep 12, 2023
1 parent 58b136e commit 2a31db8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@ static void setUp() {
}

private void doAssertions(List<String> command, String key) {
assertThat(command).hasSize(2);
assertThat(command).contains(key, atIndex(1));
assertThat(command).hasSize(4);
assertThat(command)
.contains("--compat-options", atIndex(1))
.contains("all", atIndex(2))
.contains(key, atIndex(3));
}

private void doAssertions(List<String> command, String key, String value) {
assertThat(command).hasSize(3);
assertThat(command).contains(key, atIndex(1));
assertThat(command).contains(value, atIndex(2));
assertThat(command).hasSize(5);
assertThat(command)
.contains("--compat-options", atIndex(1))
.contains("all", atIndex(2))
.contains(key, atIndex(3))
.contains(value, atIndex(4));
}

@Nested
Expand Down Expand Up @@ -129,7 +135,7 @@ class SubtutlesOptionsTests {
void shouldCreateWriteSubWithSubLang() {
List<String> command = YoutubeDlCommandBuilder.newInstance().writeSub(Set.of("en", "ru")).buildAsList();
assertThat(command)
.hasSize(4)
.hasSize(6)
.containsAll(List.of("--write-sub", "--sub-lang"))
.containsAnyOf("en,ru", "ru,en"); // Since set is passed, can't be sure what order is going to be when joining the elements
}
Expand All @@ -138,7 +144,7 @@ void shouldCreateWriteSubWithSubLang() {
void shouldCreateWriteSubAndAllSubsWithoutSubLang() {
List<String> command = YoutubeDlCommandBuilder.newInstance().writeSub(Set.of()).buildAsList();
assertThat(command)
.hasSize(3)
.hasSize(5)
.contains("--write-sub", "--all-subs");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.function.Consumer;

import com.github.engatec.vdl.TestHelper;
import com.github.engatec.vdl.core.ApplicationContext;
Expand Down Expand Up @@ -66,6 +67,16 @@ private void doAssertions(List<String> command, String key, String value) {
assertThat(command).contains(value, atIndex(2));
}

private List<String> buildCommandGeneric(Consumer<YoutubeDlCommandBuilder> propertiesSetter) {
YoutubeDlCommandBuilder commandBuilder = YoutubeDlCommandBuilder.newInstance();
propertiesSetter.accept(commandBuilder);
List<String> commandList = commandBuilder.buildAsList();
return commandList.stream()
.filter(it -> !it.equals("--compat-options"))
.filter(it -> !it.equals("all"))
.toList();
}

@Nested
@DisplayName("General options")
class GeneralOptionsTests {
Expand All @@ -81,9 +92,7 @@ void setUp() {
}

private List<String> buildCommand() {
YoutubeDlCommandBuilder commandBuilder = YoutubeDlCommandBuilder.newInstance();
YoutubeDlCommandHelper.setGeneralOptions(commandBuilder);
return commandBuilder.buildAsList();
return buildCommandGeneric(YoutubeDlCommandHelper::setGeneralOptions);
}

@Test
Expand Down Expand Up @@ -157,9 +166,7 @@ void setUp() {
}

private List<String> buildCommand() {
YoutubeDlCommandBuilder commandBuilder = YoutubeDlCommandBuilder.newInstance();
YoutubeDlCommandHelper.setSubtitlesOptions(commandBuilder);
return commandBuilder.buildAsList();
return buildCommandGeneric(YoutubeDlCommandHelper::setSubtitlesOptions);
}

@Test
Expand Down Expand Up @@ -211,9 +218,7 @@ void setUp() {
}

private List<String> buildCommand() {
YoutubeDlCommandBuilder commandBuilder = YoutubeDlCommandBuilder.newInstance();
YoutubeDlCommandHelper.setDownloadOptions(commandBuilder);
return commandBuilder.buildAsList();
return buildCommandGeneric(YoutubeDlCommandHelper::setDownloadOptions);
}

@ParameterizedTest
Expand Down Expand Up @@ -247,9 +252,7 @@ void setUp() {
}

private List<String> buildCommand() {
YoutubeDlCommandBuilder commandBuilder = YoutubeDlCommandBuilder.newInstance();
YoutubeDlCommandHelper.setNetworkOptions(commandBuilder);
return commandBuilder.buildAsList();
return buildCommandGeneric(YoutubeDlCommandHelper::setNetworkOptions);
}

@Test
Expand Down Expand Up @@ -336,9 +339,7 @@ void setUp() {
}

private List<String> buildCommand() {
YoutubeDlCommandBuilder commandBuilder = YoutubeDlCommandBuilder.newInstance();
YoutubeDlCommandHelper.setAuthenticationOptions(commandBuilder);
return commandBuilder.buildAsList();
return buildCommandGeneric(YoutubeDlCommandHelper::setAuthenticationOptions);
}

@Test
Expand Down

0 comments on commit 2a31db8

Please sign in to comment.