Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tests for #76 #154

Merged
merged 2 commits into from
Feb 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("http://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