From 99c02e8a48bfc5d7c8854456136467824b919547 Mon Sep 17 00:00:00 2001 From: az Date: Fri, 21 Apr 2023 19:16:18 +0200 Subject: [PATCH] [skip ci] add checkPackageInstalled and refactor FirefoxKtTest.kt --- .../framework/ubuntu/install/base/Install.kt | 8 ++++++++ .../desktop/infrastructure/FirefoxKtTest.kt | 18 ++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/install/base/Install.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/install/base/Install.kt index 88bcbea..65f5a03 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/install/base/Install.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/install/base/Install.kt @@ -72,6 +72,14 @@ fun Prov.isPackageInstalled(packageName: String): Boolean { } +/** + * Returns true if a package is installed else false + */ +fun Prov.checkPackageInstalled(packageName: String): ProvResult = taskWithResult { + cmd("dpkg -s $packageName") +} + + /** * Removes a package including its configuration and data file */ diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/FirefoxKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/FirefoxKtTest.kt index 4381a6b..018a36d 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/FirefoxKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/FirefoxKtTest.kt @@ -1,6 +1,6 @@ package org.domaindrivenarchitecture.provs.desktop.infrastructure -import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.isPackageInstalled +import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.checkPackageInstalled import org.domaindrivenarchitecture.provs.test.defaultTestContainer import org.domaindrivenarchitecture.provs.test.tags.ExtensiveContainerTest import org.junit.jupiter.api.Assertions.assertTrue @@ -9,15 +9,13 @@ internal class FirefoxKtTest { @ExtensiveContainerTest fun installFirefox() { - defaultTestContainer().session { - // when - val res = installFirefox() - - // then - assertTrue(res.success) - - val ffIsInstalled = isPackageInstalled("firefox") - assertTrue(ffIsInstalled) + // when + val result = defaultTestContainer().session { + installFirefox() + checkPackageInstalled("firefox") } + + // then + assertTrue(result.success) } }