112 lines
2.8 KiB
Java
112 lines
2.8 KiB
Java
package tk.antoine.roux.infrastructure.in;
|
|
|
|
import io.vavr.control.Either;
|
|
import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.Test;
|
|
import tk.antoine.roux.domain.usecases.ByLabelCriteria;
|
|
import tk.antoine.roux.domain.usecases.ByNameCriteria;
|
|
import tk.antoine.roux.domain.usecases.ByRegexCriteria;
|
|
import tk.antoine.roux.domain.usecases.CriteriaCommand;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class CriteriaTest {
|
|
|
|
@Test
|
|
@DisplayName("match a literal name")
|
|
void caseOne() {
|
|
// Given
|
|
Criteria worker = new Criteria("worker");
|
|
|
|
// When
|
|
Either<Exception, CriteriaCommand> command = worker.toCommand();
|
|
|
|
// Then
|
|
assertTrue(command.isRight());
|
|
assertInstanceOf(ByNameCriteria.class, command.get());
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("match literal name with dash")
|
|
void caseTwo() {
|
|
// Given
|
|
Criteria worker = new Criteria("worker-2");
|
|
|
|
// When
|
|
Either<Exception, CriteriaCommand> command = worker.toCommand();
|
|
|
|
// Then
|
|
assertTrue(command.isRight());
|
|
assertInstanceOf(ByNameCriteria.class, command.get());
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("match regex")
|
|
void caseThree() {
|
|
// Given
|
|
Criteria worker = new Criteria("worker*");
|
|
|
|
// When
|
|
Either<Exception, CriteriaCommand> command = worker.toCommand();
|
|
|
|
// Then
|
|
assertTrue(command.isRight());
|
|
assertInstanceOf(ByRegexCriteria.class, command.get());
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("match label")
|
|
void caseFour() {
|
|
// Given
|
|
Criteria worker = new Criteria("node=worker");
|
|
|
|
// When
|
|
Either<Exception, CriteriaCommand> command = worker.toCommand();
|
|
|
|
// Then
|
|
assertTrue(command.isRight());
|
|
assertInstanceOf(ByLabelCriteria.class, command.get());
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("match label with slash and dot")
|
|
void caseFive() {
|
|
// Given
|
|
Criteria worker = new Criteria("kubernetes.io/hostname=worker-2");
|
|
|
|
// When
|
|
Either<Exception, CriteriaCommand> command = worker.toCommand();
|
|
|
|
// Then
|
|
assertTrue(command.isRight());
|
|
assertInstanceOf(ByLabelCriteria.class, command.get());
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("match regex with wildcard")
|
|
void caseSix() {
|
|
// Given
|
|
Criteria worker = new Criteria("worker-*");
|
|
|
|
// When
|
|
Either<Exception, CriteriaCommand> command = worker.toCommand();
|
|
|
|
// Then
|
|
assertTrue(command.isRight());
|
|
assertInstanceOf(ByRegexCriteria.class, command.get());
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("don't match")
|
|
void errorCase() {
|
|
// Given
|
|
Criteria worker = new Criteria("worker [ltl");
|
|
|
|
// When
|
|
Either<Exception, CriteriaCommand> command = worker.toCommand();
|
|
|
|
// Then
|
|
assertTrue(command.isLeft());
|
|
}
|
|
}
|