How to use File.shouldNotBeWriteable method of io.kotest.matchers.file.matchers class

Best Kotest code snippet using io.kotest.matchers.file.matchers.File.shouldNotBeWriteable

matchers.kt

Source:matchers.kt Github

copy

Full Screen

1package io.kotest.matchers.file2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.collections.shouldBeSameSizeAs5import io.kotest.matchers.paths.beSymbolicLink6import io.kotest.matchers.should7import io.kotest.matchers.shouldBe8import io.kotest.matchers.shouldNot9import io.kotest.matchers.shouldNotBe10import java.io.File11import java.io.FileFilter12import java.nio.file.Path13private fun File.safeList(): List<String> = this.list()?.toList() ?: emptyList()14private fun File.safeListFiles(): List<File> = this.listFiles()?.toList() ?: emptyList()15private fun File.safeListFiles(filter: FileFilter): List<File> = this.listFiles(filter)?.toList() ?: emptyList()16fun File.shouldBeEmptyDirectory() = this should beEmptyDirectory()17fun File.shouldNotBeEmptyDirectory() = this shouldNot beEmptyDirectory()18fun beEmptyDirectory(): Matcher<File> = object : Matcher<File> {19   override fun test(value: File): MatcherResult {20      val contents = if (value.isDirectory) value.safeList() else emptyList()21      return MatcherResult(22         contents.isEmpty(),23         { "$value should be an empty directory but contained ${contents.size} file(s) [${contents.joinToString(", ")}]" },24         { "$value should not be a non empty directory" }25      )26   }27}28infix fun File.shouldContainNFiles(n: Int) = this shouldBe containNFiles(n)29infix fun File.shouldNotContainNFiles(n: Int) = this shouldNotBe containNFiles(n)30fun containNFiles(n: Int): Matcher<File> = object : Matcher<File> {31   override fun test(value: File): MatcherResult = MatcherResult(32      value.isDirectory && value.safeList().size == n,33      { "$value should be a directory and contain $n files" },34      { "$value should not be a directory containing $n files" }35   )36}37fun File.shouldBeEmpty() = this shouldBe emptyFile()38fun File.shouldNotBeEmpty() = this shouldNotBe emptyFile()39fun emptyFile(): Matcher<File> = object : Matcher<File> {40   override fun test(value: File): MatcherResult =41      MatcherResult(42         value.length() == 0L,43         { "File $value should be empty" },44         { "File $value should not be empty" }45      )46}47fun File.shouldExist() = this should exist()48fun File.shouldNotExist() = this shouldNot exist()49fun exist() = object : Matcher<File> {50   override fun test(value: File) =51      MatcherResult(52         value.exists(),53         { "File $value should exist" },54         { "File $value should not exist" }55      )56}57infix fun File.shouldContainFile(name: String) = this should containFile(name)58infix fun File.shouldNotContainFile(name: String) = this shouldNot containFile(name)59fun containFile(name: String) = object : Matcher<File> {60   override fun test(value: File): MatcherResult {61      val contents = value.safeList()62      val passed = value.isDirectory && contents.contains(name)63      return MatcherResult(64         passed,65         { "Directory $value should contain a file with filename $name (detected ${contents.size} other files)" },66         { "Directory $value should not contain a file with filename $name" }67      )68   }69}70fun File.shouldBeSymbolicLink() = this.toPath() should beSymbolicLink()71fun File.shouldNotBeSymbolicLink() = this.toPath() shouldNot beSymbolicLink()72infix fun File.shouldHaveParent(name: String) = this should haveParent(name)73infix fun File.shouldNotHaveParent(name: String) = this shouldNot haveParent(name)74fun haveParent(name: String) = object : Matcher<File> {75   private fun isParentEqualExpected(parent: File?): Boolean =76      parent != null && (parent.name == name || isParentEqualExpected(parent.parentFile))77   override fun test(value: File) = MatcherResult(78      isParentEqualExpected(value.parentFile),79      { "File $value should have parent $name" },80      { "File $value should not have parent $name" }81   )82}83fun File.shouldBeADirectory() = this should aDirectory()84fun File.shouldNotBeADirectory() = this shouldNot aDirectory()85fun aDirectory(): Matcher<File> = object : Matcher<File> {86   override fun test(value: File): MatcherResult = MatcherResult(87      value.isDirectory,88      { "File $value should be a directory" },89      { "File $value should not be a directory" }90   )91}92fun File.shouldBeAFile() = this should aFile()93fun File.shouldNotBeAFile() = this shouldNot aFile()94fun aFile(): Matcher<File> = object : Matcher<File> {95   override fun test(value: File): MatcherResult =96      MatcherResult(97         value.isFile,98         { "File $value should be a file" },99         { "File $value should not be a file" })100}101infix fun File.shouldBeSmaller(other: Path) = this should beSmaller(other.toFile())102infix fun File.shouldBeSmaller(other: File) = this should beSmaller(other)103infix fun File.shouldNotBeSmaller(other: Path) = this shouldNot beSmaller(other.toFile())104infix fun File.shouldNotBeSmaller(other: File) = this shouldNot beSmaller(other)105fun beSmaller(other: File): Matcher<File> = object : Matcher<File> {106   override fun test(value: File): MatcherResult {107      val sizea = value.length()108      val sizeb = other.length()109      return MatcherResult(110         value.length() < other.length(),111         { "File $value ($sizea bytes) should be smaller than $other ($sizeb bytes)" },112         { "File $value ($sizea bytes) should not be smaller than $other ($sizeb bytes)" }113      )114   }115}116infix fun File.shouldBeLarger(other: Path) = this should beLarger(other.toFile())117infix fun File.shouldBeLarger(other: File) = this should beLarger(other)118infix fun File.shouldNotBeLarger(other: Path) = this shouldNot beLarger(other.toFile())119infix fun File.shouldNotBeLarger(other: File) = this shouldNot beLarger(other)120fun beLarger(other: File): Matcher<File> = object : Matcher<File> {121   override fun test(value: File): MatcherResult {122      val sizea = value.length()123      val sizeb = other.length()124      return MatcherResult(125         value.length() > other.length(),126         { "File $value ($sizea bytes) should be larger than $other ($sizeb bytes)" },127         { "File $value ($sizea bytes) should not be larger than $other ($sizeb bytes)" }128      )129   }130}131fun File.shouldBeCanonical() = this should beCanonicalPath()132fun File.shouldNotBeCanonical() = this shouldNot beCanonicalPath()133fun beCanonicalPath(): Matcher<File> = object : Matcher<File> {134   override fun test(value: File): MatcherResult = MatcherResult(135      value.canonicalPath == value.path,136      { "File $value should be canonical" },137      { "File $value should not be canonical" }138   )139}140fun File.shouldBeAbsolute() = this should beAbsolute()141fun File.shouldNotBeAbsolute() = this shouldNot beAbsolute()142fun beAbsolute(): Matcher<File> = object : Matcher<File> {143   override fun test(value: File): MatcherResult =144      MatcherResult(145         value.isAbsolute,146         { "File $value should be absolute" },147         { "File $value should not be absolute" })148}149fun File.shouldBeRelative() = this should beRelative()150fun File.shouldNotBeRelative() = this shouldNot beRelative()151fun beRelative(): Matcher<File> = object : Matcher<File> {152   override fun test(value: File): MatcherResult =153      MatcherResult(154         !value.isAbsolute,155         { "File $value should be relative" },156         { "File $value should not be relative" })157}158infix fun File.shouldHaveFileSize(size: Long) = this should haveFileSize(size)159infix fun File.shouldNotHaveFileSize(size: Long) = this shouldNot haveFileSize(size)160fun haveFileSize(size: Long): Matcher<File> = object : Matcher<File> {161   override fun test(value: File): MatcherResult = MatcherResult(162      value.length() == size,163      { "File $value should have size $size" },164      { "File $value should not have size $size" }165   )166}167fun File.shouldBeWriteable() = this should beWriteable()168fun File.shouldNotBeWriteable() = this shouldNot beWriteable()169fun beWriteable(): Matcher<File> = object : Matcher<File> {170   override fun test(value: File): MatcherResult =171      MatcherResult(172         value.canWrite(),173         { "File $value should be writeable" },174         { "File $value should not be writeable" })175}176fun File.shouldBeExecutable() = this should beExecutable()177fun File.shouldNotBeExecutable() = this shouldNot beExecutable()178fun beExecutable(): Matcher<File> = object : Matcher<File> {179   override fun test(value: File): MatcherResult = MatcherResult(180      value.canExecute(),181      { "File $value should be executable" },182      { "File $value should not be executable" }183   )184}185fun File.shouldBeHidden() = this should beHidden()186fun File.shouldNotBeHidden() = this shouldNot beHidden()187fun beHidden(): Matcher<File> = object : Matcher<File> {188   override fun test(value: File): MatcherResult =189      MatcherResult(190         value.isHidden,191         { "File $value should be hidden" },192         { "File $value should not be hidden" })193}194fun File.shouldBeReadable() = this should beReadable()195fun File.shouldNotBeReadable() = this shouldNot beReadable()196fun beReadable(): Matcher<File> = object : Matcher<File> {197   override fun test(value: File): MatcherResult =198      MatcherResult(199         value.canRead(),200         { "File $value should be readable" },201         { "File $value should not be readable" })202}203infix fun File.shouldStartWithPath(path: Path) = this should startWithPath(path)204infix fun File.shouldNotStartWithPath(path: Path) = this shouldNot startWithPath(path)205infix fun File.shouldStartWithPath(prefix: String) = this should startWithPath(prefix)206infix fun File.shouldNotStartWithPath(prefix: String) = this shouldNot startWithPath(prefix)207infix fun File.shouldStartWithPath(file: File) = this should startWithPath(file)208infix fun File.shouldNotStartWithPath(file: File) = this shouldNot startWithPath(file)209infix fun Path.shouldStartWithPath(path: Path) = this.toFile() should startWithPath(path)210infix fun Path.shouldNotStartWithPath(path: Path) = this.toFile() shouldNot startWithPath(path)211fun startWithPath(path: Path) = startWithPath(path.toFile())212fun startWithPath(file: File) = startWithPath(file.toString())213fun startWithPath(prefix: String) = object : Matcher<File> {214   override fun test(value: File): MatcherResult = MatcherResult(215      value.toString().startsWith(prefix),216      { "File $value should start with $prefix" },217      { "File $value should not start with $prefix" }218   )219}220infix fun File.shouldHaveSameStructureAs(file: File) {221   this.shouldHaveSameStructureAs(file) { _, _ -> false }222}223fun File.shouldHaveSameStructureAs(224   file: File,225   compare: (expect: File, actual: File) -> Boolean,226) {227   val expectFiles = this.walkTopDown().toList()228   val actualFiles = file.walkTopDown().toList()229   val expectParentPath = this.path230   val actualParentPath = file.path231   expectFiles shouldBeSameSizeAs actualFiles232   expectFiles.zip(actualFiles) { expect, actual ->233      when {234         compare(expect, actual) -> {}235         expect.isDirectory -> actual.shouldBeADirectory()236         expect.isFile -> {237            expect.path.removePrefix(expectParentPath)238               .shouldBe(actual.path.removePrefix(actualParentPath))239         }240         else -> error("There is an unexpected error analyzing file trees")241      }242   }243}244fun File.shouldHaveSameStructureAs(245   file: File,246   filterLhs: (File) -> Boolean = { false },247   filterRhs: (File) -> Boolean = { false },248) {249   this.shouldHaveSameStructureAs(file) { expect, actual ->250      filterLhs(expect) || filterRhs(actual)251   }252}253infix fun File.shouldHaveSameStructureAndContentAs(file: File) {254   this.shouldHaveSameStructureAndContentAs(file) { _, _ -> false }255}256fun File.shouldHaveSameStructureAndContentAs(257   file: File,258   compare: (expect: File, actual: File) -> Boolean,259) {260   val expectFiles = this.walkTopDown().toList()261   val actualFiles = file.walkTopDown().toList()262   val expectParentPath = this.path263   val actualParentPath = file.path264   expectFiles shouldBeSameSizeAs actualFiles265   expectFiles.zip(actualFiles) { expect, actual ->266      when {267         compare(expect, actual) -> {}268         expect.isDirectory -> actual.shouldBeADirectory()269         expect.isFile -> {270            expect.path.removePrefix(expectParentPath)271               .shouldBe(actual.path.removePrefix(actualParentPath))272            expect.shouldHaveSameContentAs(actual)273         }274         else -> error("There is an unexpected error analyzing file trees")275      }276   }277}278fun File.shouldHaveSameStructureAndContentAs(279   file: File,280   filterLhs: (File) -> Boolean = { false },281   filterRhs: (File) -> Boolean = { false },282) {283   this.shouldHaveSameStructureAndContentAs(file) { expect, actual ->284      filterLhs(expect) || filterRhs(actual)285   }286}...

Full Screen

Full Screen

paths.kt

Source:paths.kt Github

copy

Full Screen

1package io.kotest.matchers.paths2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.file.beLarger5import io.kotest.matchers.file.beEmptyDirectory6import io.kotest.matchers.file.containNFiles7import io.kotest.matchers.should8import io.kotest.matchers.shouldBe9import io.kotest.matchers.shouldNot10import io.kotest.matchers.shouldNotBe11import java.io.File12import java.nio.file.Files13import java.nio.file.Path14import kotlin.streams.toList15infix fun Path.shouldStartWithPath(file: File) = this should startWithPath(file)16infix fun Path.shouldNotStartWithPath(file: File) = this shouldNot startWithPath(file)17infix fun Path.shouldStartWithPath(prefix: String) = this should startWithPath(prefix)18infix fun Path.shouldNotStartWithPath(prefix: String) = this shouldNot startWithPath(prefix)19infix fun Path.shouldStartWithPath(path: Path) = this should startWithPath(path)20infix fun Path.shouldNotStartWithPath(path: Path) = this shouldNot startWithPath(path)21fun startWithPath(path: Path) = startWithPath(path.toString())22fun startWithPath(file: File) = startWithPath(file.toPath())23fun startWithPath(prefix: String) = object : Matcher<Path> {24   override fun test(value: Path): MatcherResult = MatcherResult(25      value.toString().startsWith(prefix),26      { "Path $value should start with $prefix" },27      { "Path $value should not start with $prefix" })28}29fun Path.shouldExist() = this should exist()30fun Path.shouldNotExist() = this shouldNot exist()31fun exist() = object : Matcher<Path> {32   override fun test(value: Path) =33      MatcherResult(34         Files.exists(value),35         { "Path $value should exist" },36         { "Path $value should not exist" })37}38infix fun Path.shouldHaveFileSize(size: Long) = this should haveFileSize(size)39infix fun Path.shouldNotHaveFileSize(size: Long) = this shouldNot haveFileSize(size)40fun haveFileSize(size: Long): Matcher<Path> = object : Matcher<Path> {41   override fun test(value: Path): MatcherResult = MatcherResult(42      Files.size(value) == size,43      { "Path $value should have size $size" },44      { "Path $value should not have size $size" })45}46fun Path.shouldBeADirectory() = this should aDirectory()47fun Path.shouldNotBeADirectory() = this shouldNot aDirectory()48fun aDirectory(): Matcher<Path> = object : Matcher<Path> {49   override fun test(value: Path): MatcherResult = MatcherResult(50      Files.isDirectory(value),51      { "File $value should be a directory" },52      { "File $value should not be a directory" })53}54fun Path.shouldBeAFile() = this should aFile()55fun Path.shouldNotBeAFile() = this shouldNot aFile()56fun aFile(): Matcher<Path> = object : Matcher<Path> {57   override fun test(value: Path): MatcherResult = MatcherResult(58      !Files.isDirectory(value),59      { "File $value should be a directory" },60      { "File $value should not be a directory" })61}62fun Path.shouldBeAbsolute() = this should beAbsolute()63fun Path.shouldNotBeAbsolute() = this shouldNot beAbsolute()64fun beAbsolute(): Matcher<Path> = object : Matcher<Path> {65   override fun test(value: Path): MatcherResult =66      MatcherResult(67         value.isAbsolute,68         { "Path $value should be absolute" },69         { "Path $value should not be absolute" })70}71fun Path.shouldBeRelative() = this should beRelative()72fun Path.shouldNotBeRelative() = this shouldNot beRelative()73fun beRelative(): Matcher<Path> = object : Matcher<Path> {74   override fun test(value: Path): MatcherResult =75      MatcherResult(76         !value.isAbsolute,77         { "Path $value should be relative" },78         { "Path $value should not be relative" })79}80fun Path.shouldBeReadable() = this should beReadable()81fun Path.shouldNotBeReadable() = this shouldNot beReadable()82fun beReadable(): Matcher<Path> = object : Matcher<Path> {83   override fun test(value: Path): MatcherResult =84      MatcherResult(85         Files.isReadable(value),86         { "Path $value should be readable" },87         { "Path $value should not be readable" }88      )89}90fun Path.shouldBeWriteable() = this should beWriteable()91fun Path.shouldNotBeWriteable() = this shouldNot beWriteable()92fun beWriteable(): Matcher<Path> = object : Matcher<Path> {93   override fun test(value: Path): MatcherResult =94      MatcherResult(95         Files.isWritable(value),96         { "Path $value should be writeable" },97         { "Path $value should not be writeable" }98      )99}100fun Path.shouldBeExecutable() = this should beExecutable()101fun Path.shouldNotBeExecutable() = this shouldNot beExecutable()102fun beExecutable(): Matcher<Path> = object : Matcher<Path> {103   override fun test(value: Path): MatcherResult = MatcherResult(104      Files.isExecutable(value),105      { "Path $value should be executable" },106      { "Path $value should not be executable" }107   )108}109infix fun Path.shouldContainNFiles(n: Int) = this.toFile() shouldBe containNFiles(n)110infix fun Path.shouldNotContainNFiles(n: Int) = this.toFile() shouldNotBe containNFiles(n)111@Deprecated(message ="checks if a directory is empty. Deprecated since 4.3.", replaceWith = ReplaceWith("shouldBeEmptyDirectory()"))112fun Path.shouldBeNonEmptyDirectory() = this.toFile() shouldNot beEmptyDirectory()113@Deprecated(message ="checks if a directory is not empty. Deprecated since 4.3.", replaceWith = ReplaceWith("shouldBeNonEmptyDirectory()"))114fun Path.shouldNotBeNonEmptyDirectory() = this.toFile() should beEmptyDirectory()115fun Path.shouldBeEmptyDirectory() = this.toFile() should beEmptyDirectory()116fun Path.shouldNotBeEmptyDirectory() = this.toFile() shouldNot beEmptyDirectory()117fun Path.shouldBeHidden() = this should beHidden()118fun Path.shouldNotBeHidden() = this shouldNot beHidden()119fun beHidden(): Matcher<Path> = object : Matcher<Path> {120   override fun test(value: Path): MatcherResult =121      MatcherResult(122         Files.isHidden(value),123         { "Path $value should be hidden" },124         { "Path $value should not be hidden" })125}126fun Path.shouldBeCanonical() = this should beCanonicalPath()127fun Path.shouldNotBeCanonical() = this shouldNot beCanonicalPath()128fun beCanonicalPath(): Matcher<Path> = object : Matcher<Path> {129   override fun test(value: Path): MatcherResult = MatcherResult(130      value.toFile().canonicalPath == value.toFile().path,131      { "File $value should be canonical" },132      { "File $value should not be canonical" })133}134infix fun Path.shouldContainFile(name: String) = this should containFile(name)135infix fun Path.shouldNotContainFile(name: String) = this shouldNot containFile(name)136fun containFile(name: String) = object : Matcher<Path> {137   override fun test(value: Path): MatcherResult {138      val contents = Files.list(value).map { it.fileName.toString() }.toList()139      val passed = Files.isDirectory(value) && contents.contains(name)140      return MatcherResult(141         passed,142         { "Directory $value should contain a file with filename $name (detected ${contents.size} other files)" },143         { "Directory $value should not contain a file with filename $name" })144   }145}146infix fun Path.shouldBeLarger(other: Path) = this.toFile() should beLarger(other.toFile())147infix fun Path.shouldBeLarger(other: File) = this.toFile() should beLarger(other)148infix fun Path.shouldNotBeLarger(other: Path) = this.toFile() shouldNot beLarger(other.toFile())149infix fun Path.shouldNotBeLarger(other: File) = this.toFile() shouldNot beLarger(other)150fun beLarger(other: Path): Matcher<Path> = object : Matcher<Path> {151   override fun test(value: Path): MatcherResult {152      val sizea = Files.size(value)153      val sizeb = Files.size(other)154      return MatcherResult(155         sizea > sizeb,156         { "Path $value ($sizea bytes) should be larger than $other ($sizeb bytes)" },157         { "Path $value ($sizea bytes) should not be larger than $other ($sizeb bytes)"})158   }159}160infix fun Path.shouldBeSmaller(other: Path) = this should beSmaller(other)161infix fun Path.shouldBeSmaller(other: File) = this should beSmaller(other.toPath())162infix fun Path.shouldNotBeSmaller(other: Path) = this shouldNot beSmaller(other)163infix fun Path.shouldNotBeSmaller(other: File) = this shouldNot beSmaller(other.toPath())164fun beSmaller(other: Path): Matcher<Path> = object : Matcher<Path> {165   override fun test(value: Path): MatcherResult {166      val sizea = Files.size(value)167      val sizeb = Files.size(other)168      return MatcherResult(169         sizea < sizeb,170         { "Path $value ($sizea bytes) should be smaller than $other ($sizeb bytes)" },171         { "Path $value ($sizea bytes) should not be smaller than $other ($sizeb bytes)" })172   }173}174infix fun Path.shouldContainFileDeep(name: String) = this should containFileDeep(name)175infix fun Path.shouldNotContainFileDeep(name: String) = this shouldNot containFileDeep(name)176fun containFileDeep(name: String): Matcher<Path> = object : Matcher<Path> {177   private fun fileExists(dir: Path): Boolean {178      val contents = Files.list(dir).toList()179      val (dirs, files) = contents.partition { Files.isDirectory(it) }180      return files.map { it.fileName.toString() }.contains(name) || dirs.any(::fileExists)181   }182   override fun test(value: Path): MatcherResult = MatcherResult(183      fileExists(value),184      { "Path $name should exist in $value" },185      { "Path $name should not exist in $value" }186   )187}188fun Path.shouldContainFiles(vararg files: String) = this should containFiles(files.asList())189fun Path.shouldNotContainFiles(vararg files: String) = this shouldNot containFiles(files.asList())190fun containFiles(names: List<String>) = object : Matcher<Path> {191   override fun test(value: Path): MatcherResult {192      val files = Files.list(value).toList().map { it.fileName.toString() }193      val existingFiles = names.intersect(files)194      val nonExistingFiles = names.subtract(existingFiles)195      return MatcherResult(196         nonExistingFiles.isEmpty(),197         { buildMessage(value, nonExistingFiles, false) },198         {199            buildMessage(value, existingFiles, true)200         })201   }202   private fun buildMessage(path: Path, fileList: Set<String>, isNegative: Boolean): String {203      val fileString = if (fileList.size > 1) "Files" else "File"204      val negativeWord = if (isNegative) " not" else ""205      val filesString = fileList.sorted().joinToString(", ")206      return "$fileString $filesString should$negativeWord exist in $path"207   }208}209fun Path.shouldBeSymbolicLink() = this should beSymbolicLink()210fun Path.shouldNotBeSymbolicLink() = this shouldNot beSymbolicLink()211fun beSymbolicLink() = object : Matcher<Path> {212   override fun test(value: Path) = MatcherResult(213      Files.isSymbolicLink(value),214      { "Path $value should be a symbolic link" },215      { "Path $value should not be a symbolic link" }216   )217}218infix fun Path.shouldHaveParent(name: String) = this should haveParent(name)219infix fun Path.shouldNotHaveParent(name: String) = this shouldNot haveParent(name)220fun haveParent(name: String) = object : Matcher<Path> {221   private fun isParentEqualExpected(parent: Path?): Boolean {222      if (parent == null) return false223      return parent.fileName?.toString() == name || isParentEqualExpected(parent.parent)224   }225   override fun test(value: Path) = MatcherResult(226      isParentEqualExpected(value.parent),227      { "Path $value should have parent $name" },228      { "Path $value should not have parent $name" }229   )230}...

Full Screen

Full Screen

CaPluginTest.kt

Source:CaPluginTest.kt Github

copy

Full Screen

1package family.haschka.wolkenschloss.gradle.ca2import family.haschka.wolkenschloss.testing.Template3import family.haschka.wolkenschloss.testing.createRunner4import io.kotest.assertions.assertSoftly5import io.kotest.core.spec.IsolationMode6import io.kotest.core.spec.style.FunSpec7import io.kotest.engine.spec.tempdir8import io.kotest.matchers.file.shouldBeReadable9import io.kotest.matchers.file.shouldContainFile10import io.kotest.matchers.file.shouldExist11import io.kotest.matchers.file.shouldNotBeWriteable12import io.kotest.matchers.ints.shouldBeGreaterThan13import io.kotest.matchers.shouldBe14import org.bouncycastle.asn1.x500.X500Name15import org.bouncycastle.asn1.x509.KeyUsage16import org.gradle.testkit.runner.TaskOutcome17import java.time.LocalDate18import java.time.LocalTime19import java.time.ZoneOffset20import java.time.ZonedDateTime21import java.util.*22class CaPluginTest : FunSpec({23    autoClose(Template("ca")).withClone {24        context("A project using com.github.wolkenschloss.ca gradle plugin") {25            val xdgDataHome = tempdir()26            val environment = mapOf("XDG_DATA_HOME" to xdgDataHome.absolutePath)27            context("executing ca task") {28                val result = createRunner()29                    .withArguments(CaPlugin.CREATE_TASK_NAME)30                    .withEnvironment(environment)31                    .build()32                test("should be successful") {33                    result.task(":${CaPlugin.CREATE_TASK_NAME}")!!.outcome shouldBe TaskOutcome.SUCCESS34                }35                test("should create self signed root certificate") {36                    assertSoftly(CertificateWrapper.read(xdgDataHome.resolve("wolkenschloss/ca/ca.crt"))) {37                        x509Certificate.basicConstraints shouldBeGreaterThan -138                        x509Certificate.basicConstraints shouldBe Int.MAX_VALUE39                        keyUsage.hasUsages(KeyUsage.keyCertSign) shouldBe true40                        issuer shouldBe X500Name(CaPlugin.TRUST_ANCHOR_DEFAULT_SUBJECT)41                        subject shouldBe X500Name(CaPlugin.TRUST_ANCHOR_DEFAULT_SUBJECT)42                    }43                }44                test("should create read only certificate") {45                    assertSoftly(xdgDataHome.resolve("wolkenschloss/ca/ca.crt")) {46                        shouldBeReadable()47                        shouldNotBeWriteable()48                    }49                }50                test("should create readonly private key") {51                    assertSoftly(xdgDataHome.resolve("wolkenschloss/ca/ca.key")) {52                        shouldNotBeWriteable()53                        shouldBeReadable()54                        readPrivateKey().algorithm shouldBe "RSA"55                    }56                }57            }58            context("executing truststore task") {59                val result = createRunner()60                    .withArguments(CaPlugin.TRUSTSTORE_TASK_NAME)61                    .withEnvironment(environment)62                    .build()63                test("should execute successfully") {64                    result.task(":${CaPlugin.TRUSTSTORE_TASK_NAME}")!!.outcome shouldBe TaskOutcome.SUCCESS65                }66                test("should create truststore file") {67                    xdgDataHome.resolve("wolkenschloss/ca/ca.jks").shouldExist()68                }69            }70            test("should customize validity") {71                val start = ZonedDateTime.of(72                    LocalDate.of(2022, 2, 4),73                    LocalTime.MIDNIGHT,74                    ZoneOffset.UTC75                )76                val end = ZonedDateTime.of(77                    LocalDate.of(2027, 2, 4),78                    LocalTime.MIDNIGHT,79                    ZoneOffset.UTC80                )81                val result = createRunner()82                    .withArguments(CaPlugin.CREATE_TASK_NAME, "-DnotBefore=$start", "-DnotAfter=$end")83                    .withEnvironment(environment)84                    .build()85                result.task(":${CaPlugin.CREATE_TASK_NAME}")!!.outcome shouldBe TaskOutcome.SUCCESS86                val certificate = xdgDataHome.resolve("wolkenschloss/ca/ca.crt")87                    .readX509Certificate()88                assertSoftly(certificate) {89                    notBefore.toUtc() shouldBe start90                    notAfter.toUtc() shouldBe end91                }92            }93            test("should create output in user defined location") {94                val result = createRunner()95                    .withArguments("createInUserDefinedLocation")96                    .withEnvironment(environment)97                    .build()98                result.task(":createInUserDefinedLocation")!!.outcome shouldBe TaskOutcome.SUCCESS99                assertSoftly(workingDirectory.resolve("build/ca")) {100                    shouldContainFile("ca.crt")101                    shouldContainFile("ca.key")102                }103            }104        }105    }106}) {107    override fun isolationMode(): IsolationMode = IsolationMode.InstancePerLeaf108}109private fun Date.toUtc(): ZonedDateTime {110    return ZonedDateTime.ofInstant(this.toInstant(), ZoneOffset.UTC)111}...

Full Screen

Full Screen

File.shouldNotBeWriteable

Using AI Code Generation

copy

Full Screen

1File(“/path/to/file”).shouldNotBeWriteable()2File(“/path/to/file”).shouldNotBeExecutable()3File(“/path/to/file”).shouldNotBeHidden()4File(“/path/to/file”).shouldNotBeReadable()5File(“/path/to/file”).shouldNotBeSymlink()6File(“/path/to/file”).shouldNotBeSymbolicLink()7File(“/path/to/file”).shouldNotBeDirectory()8File(“/path/to/file”).shouldNotBeFile()9File(“/path/to/file”).shouldNotBeHidden()10File(“/path/to/file”).shouldNotBeWritable()11File(“/path/to/file”).shouldNotBeExecutable()12File(“/path/to/file”).shouldNotBeHidden()13File(“/path/to/file”).shouldNotBeReadable()14File(“/path/to/file”).shouldNotBeSymlink()

Full Screen

Full Screen

File.shouldNotBeWriteable

Using AI Code Generation

copy

Full Screen

1File("myFile.txt").shouldNotBeWriteable()2File("myFile.txt").shouldBeExecutable()3File("myFile.txt").shouldNotBeExecutable()4File("myFile.txt").shouldBeHidden()5File("myFile.txt").shouldNotBeHidden()6File("myFile.txt").shouldBeEmpty()7File("myFile.txt").shouldNotBeEmpty()8File("myFile.txt").shouldBeAbsolute()9File("myFile.txt").shouldNotBeAbsolute()10File("myFile.txt").shouldBeRelative()11File("myFile.txt").shouldNotBeRelative()12File("myFile.txt").shouldBeCanonical()13File("myFile.txt").shouldNotBeCanonical()14File("myFile.txt").shouldBeSymbolicLink()15File("myFile.txt").shouldNotBeSymbolicLink()16File("myFile.txt").shouldBeDirectory()

Full Screen

Full Screen

File.shouldNotBeWriteable

Using AI Code Generation

copy

Full Screen

1File( "test.txt" ).shouldNotBeWriteable()2File( "test.txt" ).shouldNotBeExecutable()3File( "test.txt" ).shouldBeHidden()4File( "test.txt" ).shouldNotBeHidden()5File( "test.txt" ).shouldHaveSameContentAs( File ( "test.txt" ))6File( "test.txt" ).shouldHaveSameContentAs( "test.txt" )7File( "test.txt" ).shouldHaveSameContentAs( "test.txt" , "UTF-8" )8File( "test.txt" ).shouldExist()9File( "test.txt" ).shouldNotExist()10File( "test.txt" ).shouldBeEmpty()11File( "test.txt" ).shouldNotBeEmpty()12File( "test.txt" ).shouldBeADirectory()13File( "test.txt" ).shouldNotBeADirectory()14File( "test.txt" ).shouldBeAFile()15File( "test.txt

Full Screen

Full Screen

File.shouldNotBeWriteable

Using AI Code Generation

copy

Full Screen

1File.shouldNotBeWriteable()2File.shouldNotBeExecutable()3File.shouldBeHidden()4File.shouldNotBeHidden()5File.shouldBeSymbolicLink()6File.shouldNotBeSymbolicLink()7File.shouldHaveExtension()8File.shouldNotHaveExtension()9File.shouldHaveName()10File.shouldNotHaveName()11File.shouldHaveParent()12File.shouldNotHaveParent()13File.shouldHaveParentPath()14File.shouldNotHaveParentPath()15File.shouldHavePath()16File.shouldNotHavePath()17File.shouldHaveSameContentAs()18File.shouldHaveSameContentAsBytesAs()

Full Screen

Full Screen

File.shouldNotBeWriteable

Using AI Code Generation

copy

Full Screen

1File("build.gradle").shouldNotBeWriteable()2File("build.gradle").shouldNotBeExecutable()3File("build.gradle").shouldBeHidden()4File("build.gradle").shouldNotBeHidden()5File("build.gradle").shouldBeReadable()6File("build.gradle").shouldNotBeReadable()

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful