How to use names class of io.kotest.matchers.file package

Best Kotest code snippet using io.kotest.matchers.file.names

KloggingConfigurationTest.kt

Source:KloggingConfigurationTest.kt Github

copy

Full Screen

1/*2 Copyright 2021-2022 Michael Strasser.3 Licensed under the Apache License, Version 2.0 (the "License");4 you may not use this file except in compliance with the License.5 You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07 Unless required by applicable law or agreed to in writing, software8 distributed under the License is distributed on an "AS IS" BASIS,9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10 See the License for the specific language governing permissions and11 limitations under the License.12*/13package io.klogging.config14import io.klogging.Level.DEBUG15import io.klogging.Level.FATAL16import io.klogging.Level.INFO17import io.klogging.Level.NONE18import io.klogging.Level.WARN19import io.klogging.internal.KloggingEngine20import io.klogging.randomLevel21import io.klogging.randomString22import io.klogging.rendering.RENDER_CLEF23import io.klogging.rendering.RENDER_SIMPLE24import io.klogging.sending.STDERR25import io.klogging.sending.STDOUT26import io.kotest.core.spec.style.DescribeSpec27import io.kotest.matchers.collections.shouldContain28import io.kotest.matchers.collections.shouldContainAll29import io.kotest.matchers.collections.shouldContainExactly30import io.kotest.matchers.collections.shouldHaveSize31import io.kotest.matchers.maps.shouldContain32import io.kotest.matchers.maps.shouldHaveSize33import io.kotest.matchers.shouldBe34internal class KloggingConfigurationTest : DescribeSpec({35 describe("Klogging configuration") {36 describe("default configuration") {37 it("has no sinks and no logging") {38 with(KloggingConfiguration()) {39 sinks shouldHaveSize 040 configs shouldHaveSize 041 }42 }43 }44 describe("configuration DSL") {45 it("adds sinks to the map") {46 val sinkConfig = seq("http://localhost:5341")47 loggingConfiguration {48 sink("console", STDOUT_SIMPLE)49 sink("seq", sinkConfig)50 }51 KloggingEngine.sinkConfigs() shouldContain ("console" to STDOUT_SIMPLE)52 KloggingEngine.sinkConfigs() shouldContain ("seq" to sinkConfig)53 }54 it("adds the default console") {55 loggingConfiguration { DEFAULT_CONSOLE() }56 with(KloggingEngine) {57 sinkConfigs() shouldContain ("console" to STDOUT_SIMPLE)58 configs() shouldHaveSize 159 with(configs().first()) {60 nameMatcher shouldBe MATCH_ALL61 ranges shouldHaveSize 162 with(ranges.first()) {63 sinkNames shouldHaveSize 164 sinkNames.first() shouldBe "console"65 }66 }67 }68 }69 it("allows for complex logging configuration") {70 loggingConfiguration {71 // Dispatch to standout output stream with simple message rendering.72 sink("stdout", RENDER_SIMPLE, STDOUT)73 // Dispatch to standout error stream with simple message rendering.74 sink("stderr", RENDER_SIMPLE, STDERR)75 // Dispatch to a Seq server with CLEF rendering by default.76 sink("seq", seq(server = "http://localhost:5341"))77 logging {78 // Log everything from `com.example` base.79 fromLoggerBase("com.example")80 // INFO level only.81 atLevel(INFO) {82 // To both standard out and Seq.83 toSink("stdout")84 toSink("seq")85 }86 // WARN level and above (more severe).87 fromMinLevel(WARN) {88 // To both standard error and Seq.89 toSink("stderr")90 toSink("seq")91 }92 }93 logging {94 // Exact logger name (e.g. one class).95 exactLogger("com.example.service.FancyService")96 // Log from DEBUG to Seq.97 fromMinLevel(DEBUG) { toSink("seq") }98 }99 }100 with(KloggingEngine) {101 sinkConfigs() shouldHaveSize 3102 sinkConfigs().keys shouldContainExactly setOf("stdout", "stderr", "seq")103 sinkConfigs().values.map { it.stringSender } shouldContainAll setOf(104 STDOUT,105 STDERR106 )107 sinkConfigs().values.map { it.renderer }.toSet() shouldContainExactly setOf(108 RENDER_SIMPLE,109 RENDER_CLEF110 )111 configs() shouldHaveSize 2112 with(configs().first()) {113 ranges shouldHaveSize 2114 ranges.first() shouldBe LevelRange(INFO, INFO)115 with(ranges.first()) {116 sinkNames shouldHaveSize 2117 sinkNames.first() shouldBe "stdout"118 sinkNames.last() shouldBe "seq"119 }120 ranges.last() shouldBe LevelRange(WARN, FATAL)121 with(ranges.last()) {122 sinkNames shouldHaveSize 2123 sinkNames.first() shouldBe "stderr"124 sinkNames.last() shouldBe "seq"125 }126 }127 with(configs().last()) {128 ranges shouldHaveSize 1129 ranges.first() shouldBe LevelRange(DEBUG, FATAL)130 with(ranges.first()) {131 sinkNames shouldHaveSize 1132 sinkNames.first() shouldBe "seq"133 }134 }135 }136 }137 it("can combine configurations") {138 loggingConfiguration { DEFAULT_CONSOLE() }139 loggingConfiguration(append = true) {140 sink("stderr", RENDER_SIMPLE, STDERR)141 logging {142 exactLogger("Test")143 atLevel(WARN) { toSink("stderr") }144 }145 }146 with(KloggingEngine) {147 sinks() shouldHaveSize 2148 configs() shouldHaveSize 2149 }150 }151 }152 describe("minimumLevel() function") {153 it("returns NONE if there is no configuration") {154 KloggingEngine.minimumLevelOf(randomString()) shouldBe INFO155 }156 it("returns INFO from the default console configuration") {157 loggingConfiguration { DEFAULT_CONSOLE() }158 KloggingEngine.minimumLevelOf(randomString()) shouldBe INFO159 }160 it("returns the level of a single configuration that matches the logger name") {161 val name = randomString()162 val level = randomLevel()163 loggingConfiguration {164 sink("stdout", RENDER_SIMPLE, STDOUT)165 logging {166 exactLogger(name)167 atLevel(level) { toSink("stdout") }168 }169 }170 KloggingEngine.minimumLevelOf(name) shouldBe level171 }172 it("returns the minimum level of configurations that match the event name") {173 val name = randomString()174 loggingConfiguration {175 sink("stdout", RENDER_SIMPLE, STDOUT)176 logging { atLevel(WARN) { toSink("stdout") } }177 logging { exactLogger(name); atLevel(INFO) { toSink("stdout") } }178 }179 KloggingEngine.minimumLevelOf(name) shouldBe INFO180 }181 it("returns NONE if no configurations match the event name") {182 val name = randomString()183 loggingConfiguration {184 sink("stdout", RENDER_SIMPLE, STDOUT)185 logging { exactLogger(name); atLevel(INFO) { toSink("stdout") } }186 }187 KloggingEngine.minimumLevelOf(randomString()) shouldBe NONE188 }189 }190 describe("append() function") {191 it("combines sinks") {192 val config = KloggingConfiguration().apply { sink("stdout", STDOUT_SIMPLE) }193 config.append(194 KloggingConfiguration().apply { sink("stderr", seq("http://seq:5341")) }195 )196 with(config) {197 sinks shouldHaveSize 2198 sinks.keys shouldContainExactly setOf("stdout", "stderr")199 }200 }201 it("combines logging configurations") {202 val config = KloggingConfiguration().apply {203 sink("stdout", STDOUT_SIMPLE)204 logging { fromMinLevel(INFO) { toSink("stdout") } }205 }206 config.append(207 KloggingConfiguration().apply {208 logging { atLevel(DEBUG) { toSink("stdout") } }209 }210 )211 with(config) {212 configs shouldHaveSize 2213 }214 }215 it("selects the lower minimum level logging level") {216 val config = KloggingConfiguration().apply { kloggingMinLogLevel = INFO }217 config.append(KloggingConfiguration().apply { kloggingMinLogLevel = WARN })218 config.kloggingMinLogLevel shouldBe INFO219 config.append(KloggingConfiguration().apply { kloggingMinLogLevel = DEBUG })220 config.kloggingMinLogLevel shouldBe DEBUG221 }222 }223 }224})...

Full Screen

Full Screen

RobotLibTest.kt

Source:RobotLibTest.kt Github

copy

Full Screen

...22import java.io.File23import javax.annotation.ManagedBean24@ComponentScan(basePackageClasses = [RobotLibTest::class])25class RobotLibTest : FreeSpec({26 "Get Keyword names" - {27 "from annotation" {28 val origin = getLibTestKwdNames()29 origin shouldContain "publicKeywordWithNameFromAnnotation"30 }31 "from function" {32 val origin = getLibTestKwdNames()33 origin shouldContain "publicKeywordFromFunction"34 }35 "from protected methods are not considered" {36 val origin = getLibTestKwdNames()37 origin shouldNotContainAnyOf listOf("iAmProtected", "iAmProtectedKwd")38 }39 "from private methods are not considered" {40 val origin = getLibTestKwdNames()...

Full Screen

Full Screen

PolygonApiTests.kt

Source:PolygonApiTests.kt Github

copy

Full Screen

...25 Given("getTestGroup") {26 When("asking for problem with test group on all tests") {27 suspend fun result() = api.getTestGroup(problemWithTestGroups).extract()28 val expectedGroups = listOf("samples", "first", "second", "third", "fourth", "fifth")29 Then("returns correct group names") {30 result().map { it.name } should containExactlyInAnyOrder(expectedGroups)31 }32 Then("returns correct group dependencies") {33 val byName = result().associateBy { it.name }34 byName["second"].shouldNotBeNull().dependencies should containExactlyInAnyOrder("samples")35 byName["third"].shouldNotBeNull().dependencies should containExactlyInAnyOrder("first", "fifth")36 byName["fourth"].shouldNotBeNull().dependencies should containExactlyInAnyOrder("third")37 (expectedGroups - setOf("second", "third", "fourth")).forAll {38 byName[it].shouldNotBeNull().dependencies.shouldBeEmpty()39 }40 }41 Then("all groups except fourth should have points policy of EACH_TEST") {42 val result = result().associateBy { it.name }43 result.entries.filter { it.key != "fourth" }.map { it.value }44 .forAll { it.pointsPolicy shouldBe EACH_TEST }45 result["fourth"].shouldNotBeNull().pointsPolicy shouldBe COMPLETE_GROUP46 }47 Then("fourth group should have points policy of COMPLETE_GROUP") {48 result().single { it.name == "fourth" }.pointsPolicy shouldBe COMPLETE_GROUP49 }50 }51 When("asking for problem with test group on all tests except samples") {52 suspend fun result() = api.getTestGroup(problemWithTestGroupsExceptSamples).extract()53 val expectedGroups = listOf("first", "second", "third", "fourth", "fifth")54 Then("returns correct group names") {55 result().map { it.name } should containExactlyInAnyOrder(expectedGroups)56 }57 Then("returns correct group dependencies") {58 val byName = result().associateBy { it.name }59 byName["third"].shouldNotBeNull().dependencies should containExactlyInAnyOrder("first", "fifth")60 byName["fourth"].shouldNotBeNull().dependencies should containExactlyInAnyOrder("third")61 (expectedGroups - setOf("third", "fourth")).forAll {62 byName[it].shouldNotBeNull().dependencies.shouldBeEmpty()63 }64 }65 Then("all groups except fourth should have points policy of EACH_TEST") {66 val result = result().associateBy { it.name }67 result.entries.filter { it.key != "fourth" }.map { it.value }68 .forAll { it.pointsPolicy shouldBe EACH_TEST }...

Full Screen

Full Screen

AppTest.kt

Source:AppTest.kt Github

copy

Full Screen

...16 val minGroups = 017 val maxGroups = 1018 "Finds users connected by having common emails" {19 checkAll(Arb.int(minGroups..maxGroups)) { numGroups ->20 val groupsOfNamesWithEmails = namesWithEmailsToBeConnected(numGroups, maxGroups)21 val emailsForName = groupsOfNamesWithEmails22 .map { (names, emails) ->23 connectUserNamesByCommonEmails(names.toSet(), emails.toSet())24 }25 .fold(mapOf<String, Set<String>>()) { acc, y -> acc + y }26 val grouped = groupUsers(emailsForName)27 groupsOfNamesWithEmails.forAll { (names, emails) ->28 val chosenName = names.firstOrNull { it in grouped }29 chosenName.shouldNotBeNull()30 should {31 grouped[chosenName].shouldContainExactlyInAnyOrder(emails)32 }33 }34 }35 }36 "Should group users with common emails" {37 val input = mapOf(38 "user1" to setOf("a@b.com", "c@b.com"),39 "user2" to setOf("a@b.com", "d@b.com"),40 "user3" to setOf("e@b.com", "f@b.com"),41 )42 val correct = mapOf(43 "user1" to setOf("a@b.com", "c@b.com", "d@b.com"),44 "user3" to setOf("e@b.com", "f@b.com"),45 )46 val result = groupUsers(input)47 assertEquals(correct, result)48 }49 "Should not group users with no common emails" {50 val input = mapOf(51 "user1" to setOf("a@b.com", "c@b.com"),52 "user2" to setOf("d@b.com"),53 "user3" to setOf("e@b.com", "f@b.com"),54 )55 val correct = mapOf(56 "user1" to setOf("a@b.com", "c@b.com"),57 "user2" to setOf("d@b.com"),58 "user3" to setOf("e@b.com", "f@b.com"),59 )60 val result = groupUsers(input)61 assertEquals(correct, result)62 }63})64private fun namesWithEmailsToBeConnected(65 numGroups: Int,66 maxGroups: Int67): List<Pair<List<String>, List<String>>> {68 val groups = (0 until numGroups)69 val groupedNames = groups70 .map { genUniqueNames(it, rnd.nextInt(1, maxGroups)) }71 val groupedEmails = groups.map { g ->72 genUniqueEmails(g, rnd.nextInt(1, 10))73 }74 return groupedNames.zip(groupedEmails)75}76fun genUniqueNames(group: Int, num: Int) = (0 until num).map { "${group}_$it" }77fun genUniqueEmails(group: Int, num: Int) = (0 until num).map { "$it@$group.com" }78fun <T> MutableCollection<T>.popRandom(): T = random().also { remove(it) }79fun connectUserNamesByCommonEmails(80 names: Set<String>,81 emails: Set<String>,82) : MutableMap<String, MutableSet<String>>83{84 val disconnected = names.toMutableSet()85 val connected = mutableMapOf(86 disconnected.popRandom() to mutableSetOf<String>()87 )88 val usedEmails = mutableSetOf<String>()89 while (disconnected.isNotEmpty()) {90 val email = emails.random().also { usedEmails += it }91 connected.values.random() += email92 connected.getOrPut(disconnected.popRandom()) { mutableSetOf() } += email93 }94 val unusedEmails = emails - usedEmails95 unusedEmails.forEach { email ->96 connected[names.random()]!! += email97 }98 return connected99}...

Full Screen

Full Screen

TemplatingTest.kt

Source:TemplatingTest.kt Github

copy

Full Screen

...47 val items = templateItems("User {Name} logged in from {IpAddress}", "Sue")48 items shouldBe mapOf("Name" to "Sue")49 }50 }51 describe("extracting item names") {52 it("returns empty list if there are no holes in the template") {53 extractItemNames("There are no holes in this template") shouldBe listOf()54 }55 it("returns the name of an item at the start of a template") {56 val name = randomString()57 extractItemNames("{$name} was at the start") shouldContainInOrder listOf(name)58 }59 it("returns the name of an item in the middle of a template") {60 val name = randomString()61 extractItemNames("This {$name} is in the middle") shouldContainInOrder listOf(name)62 }63 it("returns the name of an item at the end of a template") {64 val name = randomString()65 extractItemNames("At the end is the {$name}") shouldContainInOrder listOf(name)66 }67 it("returns the name all items in a template") {68 val names = listOf(randomString(), randomString(), randomString())69 extractItemNames(70 "One: {${names[0]}}, two: {${names[1]}} and three: {${names[2]}}"71 ) shouldContainInOrder names72 }73 }74})...

Full Screen

Full Screen

ZygardeJpaDaoGeneratorTest.kt

Source:ZygardeJpaDaoGeneratorTest.kt Github

copy

Full Screen

1package zygarde.codegen.processor2import com.tschuchort.compiletesting.KotlinCompilation3import com.tschuchort.compiletesting.SourceFile4import io.kotest.matchers.collections.shouldContain5import io.kotest.matchers.collections.shouldNotContain6import io.kotest.matchers.shouldBe7import io.kotest.matchers.string.shouldContain8import org.jetbrains.kotlin.config.JvmTarget9import org.junit.jupiter.api.Test10import org.springframework.core.io.ClassPathResource11import zygarde.codegen.ZygardeKaptOptions12class ZygardeJpaDaoGeneratorTest {13 @Test14 fun `should able to generate Dao`() {15 val result = KotlinCompilation().apply {16 sources = listOf(17 ClassPathResource("codegen/jpa/TestGenerateDao.kt").file18 ).map { SourceFile.fromPath(it) }19 jvmTarget = JvmTarget.JVM_1_8.description20 annotationProcessors = listOf(ZygardeJpaProcessor())21 inheritClassPath = true22 messageOutputStream = System.out23 }.compile()24 result.exitCode shouldBe KotlinCompilation.ExitCode.OK25 val generatedFileNames = result.generatedFiles.map { it.name }26 generatedFileNames shouldContain "SimpleBookDao.kt"27 generatedFileNames shouldContain "AutoIntIdBookDao.kt"28 generatedFileNames shouldContain "AutoLongIdBookDao.kt"29 generatedFileNames shouldContain "AuditedAutoIntIdBookDao.kt"30 generatedFileNames shouldContain "SequenceAutoIntIdBookDao.kt"31 generatedFileNames shouldContain "IdClassBookDao.kt"32 generatedFileNames shouldContain "Dao.kt"33 }34 @Test35 fun `should able to generate Enhanced Dao`() {36 val result = KotlinCompilation().apply {37 sources = listOf(38 ClassPathResource("codegen/jpa/TestGenerateDao.kt").file39 ).map { SourceFile.fromPath(it) }40 jvmTarget = JvmTarget.JVM_1_8.description41 annotationProcessors = listOf(ZygardeJpaProcessor())42 inheritClassPath = true43 messageOutputStream = System.out44 kaptArgs.put(ZygardeKaptOptions.DAO_ENHANCED_IMPL, "true")45 kaptArgs.put(ZygardeKaptOptions.DAO_COMBINE, "false")46 }.compile()47 result.exitCode shouldBe KotlinCompilation.ExitCode.OK48 result.generatedFiles.filter { it.name.endsWith("Dao") }.forEach {49 it.readText() shouldContain "ZygardeEnhancedDao"50 }51 }52 @Test53 fun `should able to generate Dao with kaptOptions`() {54 val result = KotlinCompilation().apply {55 sources = listOf(56 ClassPathResource("codegen/jpa/TestGenerateDao.kt").file57 ).map { SourceFile.fromPath(it) }58 jvmTarget = JvmTarget.JVM_1_8.description59 annotationProcessors = listOf(ZygardeJpaProcessor())60 inheritClassPath = true61 messageOutputStream = System.out62 kaptArgs.put(ZygardeKaptOptions.BASE_PACKAGE, "foo.generated")63 kaptArgs.put(ZygardeKaptOptions.DAO_PACKAGE, "daos")64 kaptArgs.put(ZygardeKaptOptions.DAO_SUFFIX, "BaseDao")65 kaptArgs.put(ZygardeKaptOptions.DAO_COMBINE, "false")66 }.compile()67 result.exitCode shouldBe KotlinCompilation.ExitCode.OK68 val generatedFileNames = result.generatedFiles.map { it.name }69 generatedFileNames shouldContain "SimpleBookBaseDao.kt"70 generatedFileNames shouldContain "AutoIntIdBookBaseDao.kt"71 generatedFileNames shouldContain "AutoLongIdBookBaseDao.kt"72 generatedFileNames shouldContain "IdClassBookBaseDao.kt"73 generatedFileNames shouldNotContain "Dao.kt"74 }75}...

Full Screen

Full Screen

IOSpec.kt

Source:IOSpec.kt Github

copy

Full Screen

1package com.github.rougsig.core2import io.kotest.core.datatest.forAll3import io.kotest.core.spec.style.FunSpec4import io.kotest.matchers.file.shouldBeADirectory5import io.kotest.matchers.file.shouldBeAFile6import io.kotest.matchers.file.shouldExist7import io.kotest.matchers.shouldBe8import kotlinx.coroutines.runBlocking9import java.io.ByteArrayInputStream10import java.io.ByteArrayOutputStream11import java.io.File12import java.io.PrintStream13import java.nio.file.Paths14abstract class IOSpec(15 private val resourcesPath: String,16 private val testFun: IOEnvironment.() -> Unit17) : FunSpec({18 val projectRoot = File(".").absoluteFile.parent19 val resourcesDir = Paths.get(projectRoot, "src/test/resources", resourcesPath).toFile()20 context("File IO tests") {21 val inputDir = File("${resourcesDir.absoluteFile}/input")22 inputDir.shouldExist()23 inputDir.shouldBeADirectory()24 val outputDir = File("${resourcesDir.absoluteFile}/output")25 outputDir.shouldExist()26 val testNames = inputDir.listFiles()27 .map { it.nameWithoutExtension.removePrefix("input") }28 forAll(testNames) { testName: String ->29 val input = File("${inputDir.absoluteFile}/input${testName}.txt")30 input.shouldExist()31 input.shouldBeAFile()32 val output = File("${outputDir.absoluteFile}/output${testName}.txt")33 output.shouldExist()34 output.shouldBeAFile()35 val baos = ByteArrayOutputStream()36 runBlocking {37 // Set the same as hackerrank timeout limit38 // https://www.hackerrank.com/environment/languages39 withTimeoutOrInterrupt(4000L) {40 IOEnvironment(ByteArrayInputStream(input.readBytes()), PrintStream(baos)).testFun()41 }42 }43 val actual = baos.toString().trim().trimIndent()44 val expected = output.readText().trim().trimIndent()45 actual.shouldBe(expected)46 }47 }48})...

Full Screen

Full Screen

ZipFileNameTest.kt

Source:ZipFileNameTest.kt Github

copy

Full Screen

...11class ZipFileNameTest : StringSpec({12 "empty name should not be valid" {13 ZipFileName.of("").leftValueOrNull!!.shouldBeInstanceOf<BlankZipFileName>()14 }15 "blank names should not be valid" {16 forAll(Arb.string().filter { it.isBlank() }) { name ->17 ZipFileName.of(name).leftValueOrNull is BlankZipFileName18 }19 }20 "two instances should be equal if their names are equal" {21 (ZipFileName.of("equal name") == ZipFileName.of("equal name"))22 .shouldBeTrue()23 }24 "two instances should not be equal if their names differ" {25 (ZipFileName.of("some name") == ZipFileName.of("different name"))26 .shouldBeFalse()27 }28 "file extension should be .zip" {29 forAll(Arb.string().filter { it.isNotBlank() }) { name ->30 ZipFileName.of(name).orNull!!.nameWithExtension.endsWith(".zip")31 }32 }33})...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful