Skip to content

Commit

Permalink
Merge pull request #154 from sbt/wip/rpm-tests
Browse files Browse the repository at this point in the history
Adding tests for #76
  • Loading branch information
jsuereth committed Feb 6, 2014
2 parents 1970748 + bbfce5b commit bb8d1d9
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/sbt-test/rpm/scriptlets-rpm/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import NativePackagerKeys._

packagerSettings

mapGenericFilesToLinux

name := "rpm-test"

version := "0.1.0"

maintainer := "Josh Suereth <[email protected]>"

packageSummary := "Test rpm package"

packageDescription := """A fun package description of our software,
with multiple lines."""

rpmRelease := "1"

rpmVendor := "typesafe"

rpmUrl := Some("https://github.com/sbt/sbt-native-packager")

rpmLicense := Some("BSD")

rpmPre := Some("""echo "pre-install"""")

rpmPost := Some("""echo "post-install"""")

rpmPretrans := Some("""echo "pretrans"""")

rpmPosttrans := Some("""echo "posttrans"""")

rpmPreun := Some("""echo "pre-uninstall"""")

rpmPostun := Some("""echo "post-uninstall"""")

TaskKey[Unit]("check-spec-file") <<= (target, streams) map { (target, out) =>
val spec = IO.read(target / "rpm" / "SPECS" / "rpm-test.spec")
assert(spec contains "%pre\necho \"pre-install\"", "Spec doesn't contain %pre scriptlet")
assert(spec contains "%post\necho \"post-install\"", "Spec doesn't contain %post scriptlet")
assert(spec contains "%pretrans\necho \"pretrans\"", "Spec doesn't contain %pretrans scriptlet")
assert(spec contains "%posttrans\necho \"posttrans\"", "Spec doesn't contain %posttrans scriptlet")
assert(spec contains "%preun\necho \"pre-uninstall\"", "Spec doesn't contain %preun scriptlet")
assert(spec contains "%postun\necho \"post-uninstall\"", "Spec doesn't contain %postun scriptlet")
out.log.success("Successfully tested rpm test file")
()
}

TaskKey[Unit]("check-rpm-version") <<= (target, streams) map { (target, out) =>
val fullRpmVersion = Process("rpm", Seq("--version")) !!
val firstDigit = fullRpmVersion indexWhere Character.isDigit
val rpmVersion = fullRpmVersion substring firstDigit
out.log.info("Found rpmVersion: " + rpmVersion)
val (major, minor, patch) = rpmVersion.trim.split("\\.").map(_.toInt) match {
case Array(major) => (major, 0, 0)
case Array(major, minor) => (major, minor, 0)
case Array(major, minor, patch, _*) => (major, minor, patch)
}
assert(major >= 4, "RPM version must be greater than than 4.x.x. Is " + fullRpmVersion)
()
}

1 change: 1 addition & 0 deletions src/sbt-test/rpm/scriptlets-rpm/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
1 change: 1 addition & 0 deletions src/sbt-test/rpm/scriptlets-rpm/src/universal/conf/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Test configuration file!
8 changes: 8 additions & 0 deletions src/sbt-test/rpm/scriptlets-rpm/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Run the debian packaging.
> rpm:package-bin
$ exists target/rpm/RPMS/noarch/rpm-test-0.1.0-1.noarch.rpm
$ exists target/rpm/SPECS/rpm-test.spec

# Check files for defaults
> check-spec-file
> check-rpm-version

0 comments on commit bb8d1d9

Please sign in to comment.