From 0622ff26fce73aec6b0de7bdb5e8336114f5f357 Mon Sep 17 00:00:00 2001 From: Josh Girvin Date: Fri, 3 Mar 2017 13:03:32 +1000 Subject: [PATCH] v1.0.6 release: Fixes Docker version number issues This changes the logic involved in checking for a minimum Docker version. Previously, we had a maximum version as well; with the pending release of v17.3 this needed to be updated to be more robust. Tests for the change, including the upcoming version numbers have been added to `test/util_test.nim`, and pass. Version has been bumped to v1.0.6 --- dup.nimble | 2 +- src/container.nim | 2 +- src/dup.nim | 10 ++++------ src/util.nim | 8 ++++++++ test/runner.nim | 1 + test/util_test.nim | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 test/util_test.nim diff --git a/dup.nimble b/dup.nimble index 35969c1..0acb9c9 100644 --- a/dup.nimble +++ b/dup.nimble @@ -1,6 +1,6 @@ [Package] name = "dup" -version = "1.0.4" +version = "1.0.6" author = "Josh Girvin , Nathan Craike " description = "CLI wrapper for local Docker web development" license = "MIT" diff --git a/src/container.nim b/src/container.nim index 96a92ad..020aca0 100644 --- a/src/container.nim +++ b/src/container.nim @@ -46,7 +46,7 @@ proc checkDockerfile*() {.raises: [].} = if not existsFile(getCurrentDir() / "Dockerfile"): writeError("Missing \"Dockerfile\" in current directory") quit(254) - except OSError: + except: writeError(getCurrentExceptionMsg(), true) quit(1) diff --git a/src/dup.nim b/src/dup.nim index e1916b1..238e2f7 100644 --- a/src/dup.nim +++ b/src/dup.nim @@ -13,7 +13,7 @@ from database import newDBConfig from container import checkDockerfile, checkAndParseDupFile ## Define our version constant for re-use -const version = "dup 1.0.4" +const version = "dup 1.0.6" ## Define our docopt parsing schema let doc = """ @@ -47,11 +47,9 @@ var dbConf = newDBConfig(None) ## Default the database config to "None" conf: ProjectConfig ## Configuration ref object -## Check Docker version, bail-out if it's not 1.12.x -let - dv = docker.getVersion() - isWrong = if dv.major == 1 and dv.minor == 12: false else: true -if isWrong: +## Check Docker version, bail-out if it's less than v1.12 +let dv = docker.getVersion() +if isVersionTooOld(dv): writeError("Please install Docker >= v1.12.0", true) quit(5) diff --git a/src/util.nim b/src/util.nim index fb068ef..426e819 100644 --- a/src/util.nim +++ b/src/util.nim @@ -103,3 +103,11 @@ proc writeStatus*(name: string, status: bool) = stdout.write("not running") stdout.resetAttributes() stdout.write("\n") + +proc isVersionTooOld*(dv: VersionNumber): bool = + result = false + if dv.major < 1: + result = true + elif dv.major == 1: + if dv.minor < 12: + result = true diff --git a/test/runner.nim b/test/runner.nim index 815dfec..5244385 100644 --- a/test/runner.nim +++ b/test/runner.nim @@ -5,3 +5,4 @@ import ./docker_test import ./config_test +import ./util_test diff --git a/test/util_test.nim b/test/util_test.nim new file mode 100644 index 0000000..9155321 --- /dev/null +++ b/test/util_test.nim @@ -0,0 +1,33 @@ +## util.nim tests + +import unittest +import options +import typetraits +import ../src/private/types + +# Unit under test +import ../src/util + +suite "util.isVersionTooOld": + setup: discard + teardown: discard + + test "fails with incorrect major": + let version = newVersionNumber(0, 12, 0) + let result = isVersionTooOld(version) + check(result == true) + + test "fails with correct major, incorrect minor": + let version = newVersionNumber(1, 11, 0) + let result = isVersionTooOld(version) + check(result == true) + + test "passes with correct major/minor for version v1": + let version = newVersionNumber(1, 13, 0) + let result = isVersionTooOld(version) + check(result == false) + + test "passes with correct major/minor for new release numbers": + let version = newVersionNumber(17, 3, 0) + let result = isVersionTooOld(version) + check(result == false)