-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(itest): fix GraphQLTest.java (#395)
Co-authored-by: Andrew Azores <[email protected]>
- Loading branch information
1 parent
8ce2568
commit c5ea2a3
Showing
6 changed files
with
1,679 additions
and
839 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/test/java/io/cryostat/graphql/matchers/LabelSelectorMatcherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright The Cryostat Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.cryostat.graphql.matchers; | ||
|
||
import java.util.Map; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
class LabelSelectorMatcherTest { | ||
|
||
private static final Map<String, String> TEST_LABELS = | ||
Map.of( | ||
"foo", "bar", | ||
"something", "else", | ||
"my.prefixed/label", "expectedValue", | ||
"env", "prod", | ||
"present", "irrelevant"); | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"this is not a valid expression"}) | ||
void testDoesNotMatchBadSyntax(String expr) { | ||
Assertions.assertThrows( | ||
IllegalArgumentException.class, () -> LabelSelectorMatcher.parse(expr)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"foo=bar, true", | ||
"something=wrong, false", | ||
"my.prefixed/label = expectedValue, true", | ||
"env = Expected Value, false", | ||
"env = prod, true", | ||
"env = prod , true", | ||
"env = dev, false", | ||
"env = dev , false", | ||
}) | ||
void testSingleEquality(String expr, boolean pass) { | ||
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr); | ||
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"foo==bar, true", | ||
"something==wrong, false", | ||
"my.prefixed/label == expectedValue, true" | ||
}) | ||
void testDoubleEquality(String expr, boolean pass) { | ||
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr); | ||
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"foo!=bar, false", | ||
"something!=wrong, true", | ||
"my.prefixed/label != expectedValue, false" | ||
}) | ||
void testInequality(String expr, boolean pass) { | ||
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr); | ||
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource( | ||
value = { | ||
"foo in (bar, baz) : true", | ||
"something In (else, orother) : true", | ||
"env IN (stage,qa) : false", | ||
}, | ||
delimiter = ':') | ||
void testSetIn(String expr, boolean pass) { | ||
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr); | ||
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource( | ||
value = { | ||
"foo notin (bar, baz) : false", | ||
"something NotIn (orother, else, third) : false", | ||
"env NOTIN (stage,qa) : true", | ||
}, | ||
delimiter = ':') | ||
void testSetNotIn(String expr, boolean pass) { | ||
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr); | ||
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"foo, true", | ||
"something, true", | ||
"my.prefixed/label, true", | ||
"another/missing-label, false", | ||
"present, true" | ||
}) | ||
void testExists(String expr, boolean pass) { | ||
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr); | ||
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({"!foo, false", "!something, false", "!present, false"}) | ||
void testNotExists(String expr, boolean pass) { | ||
LabelSelectorMatcher matcher = LabelSelectorMatcher.parse(expr); | ||
MatcherAssert.assertThat(expr, matcher.test(TEST_LABELS), Matchers.is(pass)); | ||
} | ||
} |
Oops, something went wrong.