How to use haveFileSize method of io.kotest.matchers.file.matchers class

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

matchers.kt

Source:matchers.kt Github

copy

Full Screen

...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" })...

Full Screen

Full Screen

paths.kt

Source:paths.kt Github

copy

Full Screen

...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()...

Full Screen

Full Screen

DownloaderFunTest.kt

Source:DownloaderFunTest.kt Github

copy

Full Screen

...20import io.kotest.assertions.throwables.shouldThrow21import io.kotest.core.spec.style.StringSpec22import io.kotest.core.test.TestCase23import io.kotest.matchers.file.aFile24import io.kotest.matchers.file.haveFileSize25import io.kotest.matchers.should26import io.kotest.matchers.shouldBe27import io.kotest.matchers.types.shouldBeTypeOf28import java.io.File29import org.ossreviewtoolkit.model.ArtifactProvenance30import org.ossreviewtoolkit.model.Hash31import org.ossreviewtoolkit.model.Identifier32import org.ossreviewtoolkit.model.Package33import org.ossreviewtoolkit.model.RemoteArtifact34import org.ossreviewtoolkit.model.RepositoryProvenance35import org.ossreviewtoolkit.model.SourceCodeOrigin36import org.ossreviewtoolkit.model.VcsInfo37import org.ossreviewtoolkit.model.VcsType38import org.ossreviewtoolkit.model.config.DownloaderConfiguration39import org.ossreviewtoolkit.utils.test.ExpensiveTag40import org.ossreviewtoolkit.utils.test.createTestTempDir41class DownloaderFunTest : StringSpec() {42 private lateinit var outputDir: File43 override suspend fun beforeTest(testCase: TestCase) {44 outputDir = createTestTempDir()45 }46 init {47 "Downloads and unpacks JAR source package".config(tags = setOf(ExpensiveTag)) {48 val pkg = Package(49 id = Identifier(50 type = "Maven",51 namespace = "junit",52 name = "junit",53 version = "4.12"54 ),55 declaredLicenses = sortedSetOf(),56 description = "",57 homepageUrl = "",58 binaryArtifact = RemoteArtifact.EMPTY,59 sourceArtifact = RemoteArtifact(60 url = "https://repo.maven.apache.org/maven2/junit/junit/4.12/junit-4.12-sources.jar",61 hash = Hash.create("a6c32b40bf3d76eca54e3c601e5d1470c86fcdfa")62 ),63 vcs = VcsInfo.EMPTY64 )65 val provenance = Downloader(DownloaderConfiguration()).download(pkg, outputDir)66 val licenseFile = outputDir.resolve("LICENSE-junit.txt")67 provenance.shouldBeTypeOf<ArtifactProvenance>().apply {68 sourceArtifact.url shouldBe pkg.sourceArtifact.url69 sourceArtifact.hash shouldBe pkg.sourceArtifact.hash70 }71 licenseFile shouldBe aFile()72 licenseFile should haveFileSize(11376L)73 outputDir.walk().count() shouldBe 23474 }75 "Download of JAR source package fails when hash is incorrect".config(tags = setOf(ExpensiveTag)) {76 val pkg = Package(77 id = Identifier(78 type = "Maven",79 namespace = "junit",80 name = "junit",81 version = "4.12"82 ),83 declaredLicenses = sortedSetOf(),84 description = "",85 homepageUrl = "",86 binaryArtifact = RemoteArtifact.EMPTY,87 sourceArtifact = RemoteArtifact(88 url = "https://repo.maven.apache.org/maven2/junit/junit/4.12/junit-4.12-sources.jar",89 hash = Hash.create("0123456789abcdef0123456789abcdef01234567")90 ),91 vcs = VcsInfo.EMPTY92 )93 val exception = shouldThrow<DownloadException> {94 Downloader(DownloaderConfiguration()).download(pkg, outputDir)95 }96 exception.suppressed.size shouldBe 297 exception.suppressed[0]!!.message shouldBe "No VCS URL provided for 'Maven:junit:junit:4.12'. " +98 "Please define the \"connection\" tag within the \"scm\" tag in the POM file, " +99 "see: http://maven.apache.org/pom.html#SCM"100 exception.suppressed[1]!!.message shouldBe "Source artifact does not match expected " +101 "Hash(value=0123456789abcdef0123456789abcdef01234567, algorithm=SHA-1)."102 }103 "Falls back to downloading source package when download from VCS fails".config(tags = setOf(ExpensiveTag)) {104 val downloaderConfiguration = DownloaderConfiguration(105 sourceCodeOrigins = listOf(SourceCodeOrigin.VCS, SourceCodeOrigin.ARTIFACT)106 )107 val pkg = Package(108 id = Identifier(109 type = "Maven",110 namespace = "junit",111 name = "junit",112 version = "4.12"113 ),114 declaredLicenses = sortedSetOf(),115 description = "",116 homepageUrl = "",117 binaryArtifact = RemoteArtifact.EMPTY,118 sourceArtifact = RemoteArtifact(119 url = "https://repo.maven.apache.org/maven2/junit/junit/4.12/junit-4.12-sources.jar",120 hash = Hash.create("a6c32b40bf3d76eca54e3c601e5d1470c86fcdfa")121 ),122 vcs = VcsInfo(123 type = VcsType.GIT,124 url = "https://example.com/invalid-repo-url",125 revision = "8964880d9bac33f0a7f030a74c7c9299a8f117c8"126 )127 )128 val provenance = Downloader(downloaderConfiguration).download(pkg, outputDir)129 val licenseFile = outputDir.resolve("LICENSE-junit.txt")130 provenance.shouldBeTypeOf<ArtifactProvenance>().apply {131 sourceArtifact.url shouldBe pkg.sourceArtifact.url132 sourceArtifact.hash shouldBe pkg.sourceArtifact.hash133 }134 licenseFile shouldBe aFile()135 licenseFile should haveFileSize(11376L)136 outputDir.walk().count() shouldBe 234137 }138 "Falls back to downloading from VCS when source package download fails".config(tags = setOf(ExpensiveTag)) {139 val downloaderConfiguration = DownloaderConfiguration(140 sourceCodeOrigins = listOf(SourceCodeOrigin.ARTIFACT, SourceCodeOrigin.VCS)141 )142 val pkg = Package(143 id = Identifier(144 type = "Maven",145 namespace = "junit",146 name = "junit",147 version = "4.12"148 ),149 declaredLicenses = sortedSetOf(),150 description = "",151 homepageUrl = "",152 binaryArtifact = RemoteArtifact.EMPTY,153 sourceArtifact = RemoteArtifact(154 url = "https://repo.example.com/invalid.jar",155 hash = Hash.create("a6c32b40bf3d76eca54e3c601e5d1470c86fcdfa")156 ),157 vcs = VcsInfo(158 type = VcsType.GIT,159 url = "https://github.com/junit-team/junit4.git",160 revision = "64155f8a9babcfcf4263cf4d08253a1556e75481"161 )162 )163 val provenance = Downloader(downloaderConfiguration).download(pkg, outputDir)164 val licenseFile = outputDir.resolve("LICENSE-junit.txt")165 provenance.shouldBeTypeOf<RepositoryProvenance>().apply {166 vcsInfo.url shouldBe pkg.vcs.url167 vcsInfo.revision shouldBe pkg.vcs.revision168 }169 licenseFile shouldBe aFile()170 licenseFile should haveFileSize(11376L)171 outputDir.walk().count() shouldBe 608172 }173 "Can download a TGZ source artifact from SourceForge".config(tags = setOf(ExpensiveTag)) {174 val artifactUrl = "https://master.dl.sourceforge.net/project/tyrex/tyrex/Tyrex%201.0.1/tyrex-1.0.1-src.tgz"175 val pkg = Package(176 id = Identifier(177 type = "Maven",178 namespace = "tyrex",179 name = "tyrex",180 version = "1.0.1"181 ),182 declaredLicenses = sortedSetOf(),183 description = "",184 homepageUrl = "",...

Full Screen

Full Screen

haveFileSize

Using AI Code Generation

copy

Full Screen

1haveFileSize( 1024 ) shouldBe true2haveFilePermissions( "rw-r--r--" ) shouldBe true3haveSameTextualContentAs( File ( "test.txt" ) ) shouldBe true4haveSameBinaryContentAs( File ( "test.txt" ) ) shouldBe true5haveSameLinesAs( File ( "test.txt" ) ) shouldBe true6haveSameContentAs( File ( "test.txt" ) ) shouldBe true7haveSameContentAs( File ( "test.txt" ) ) shouldBe true8haveSameContentAs( File ( "test.txt" ) ) shouldBe true9haveSameContentAs( File ( "test.txt" ) ) shouldBe true10haveSameContentAs( File ( "test.txt" ) ) shouldBe true11haveSameContentAs( File ( "test.txt" ) ) shouldBe true12haveSameContentAs( File ( "test.txt" ) ) shouldBe true13haveSameContentAs( File ( "test.txt" ) ) shouldBe true14haveSameContentAs( File ( "test.txt" ) ) shouldBe true

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