diff --git a/Makefile b/Makefile index 22d5b16..9f786e6 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,7 @@ NAME := net-agent RELEASE_TARBALL := $(NAME)-$(STAMP).tgz RELEASE_MANIFEST := $(NAME)-$(STAMP).manifest RELSTAGEDIR := /tmp/$(NAME)-$(STAMP) -NODEUNIT = $(TOP)/node_modules/.bin/nodeunit +TAPE = $(TOP)/node_modules/.bin/tape # # Due to the unfortunate nature of npm, the Node Package Manager, there appears @@ -78,14 +78,14 @@ RUN_NPM_INSTALL = $(NPM_ENV) $(NPM) install all: $(SMF_MANIFESTS) | $(NPM_EXEC) $(REPO_DEPS) $(RUN_NPM_INSTALL) -$(NODEUNIT): | $(NPM_EXEC) +$(TAPE): | $(NPM_EXEC) $(RUN_NPM_INSTALL) CLEAN_FILES += $(TAP) ./node_modules/tap .PHONY: test -test: $(TAP) - TAP=1 $(TAP) test/*.test.js +test: $(TAPE) + $(NODE) $(TAPE) test/unit/*.test.js .PHONY: release release: all deps docs $(SMF_MANIFESTS) diff --git a/lib/common.js b/lib/common.js index b7dae15..fd3b9c9 100644 --- a/lib/common.js +++ b/lib/common.js @@ -34,7 +34,7 @@ function hasChanged(fields, cur, old) { } return fields.some(function (field) { - return mod_jsprim.deepEqual(cur[field], old[field]); + return !mod_jsprim.deepEqual(cur[field], old[field]); }); } diff --git a/package.json b/package.json index 340cfd7..cd620e0 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "restify": "4.3.0", "sdc-bunyan-serializers": "git+https://github.com/joyent/sdc-bunyan-serializers.git#aefc119", "sdc-clients": "^10.5.0", + "tape": "4.5.1", "triton-mockcloud-common": "git+http://github.com/joyent/triton-mockcloud-common.git#master", "triton-netconfig": "1.1.0", "uuid": "3.2.1", diff --git a/test/unit/util.test.js b/test/unit/util.test.js new file mode 100644 index 0000000..5108cd6 --- /dev/null +++ b/test/unit/util.test.js @@ -0,0 +1,51 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* + * Copyright (c) 2019 Joyent, Inc. + */ + +/* + * Tests that verify that NIC changes made in NAPI are reflected locally. + */ + +'use strict'; + +var mod_common = require('../../lib/common'); +var test = require('tape'); + +// --- Tests + +test('hasChanged() tests', function (t) { + var OBJ1 = { a: 5, b: [ 1, 2, 3, 4 ] }; + var OBJ2 = { a: 6, b: [ 1, 2, 3, 4 ] }; + var OBJ3 = { a: 5, b: [ 1, 2, 3, 5 ] }; + + t.equal(mod_common.hasChanged([], OBJ1, null), true); + t.equal(mod_common.hasChanged([ 'a' ], OBJ1, OBJ2), true); + t.equal(mod_common.hasChanged([ 'b' ], OBJ1, OBJ3), true); + + t.equal(mod_common.hasChanged([ 'a', 'b' ], OBJ1, OBJ3), true); + t.equal(mod_common.hasChanged([ 'a', 'b' ], OBJ1, OBJ2), true); + t.equal(mod_common.hasChanged([ 'a', 'b' ], OBJ2, OBJ3), true); + + t.equal(mod_common.hasChanged([ 'a', 'b', 'c' ], OBJ1, OBJ3), true); + t.equal(mod_common.hasChanged([ 'a', 'b', 'c' ], OBJ1, OBJ2), true); + t.equal(mod_common.hasChanged([ 'a', 'b', 'c' ], OBJ2, OBJ3), true); + + t.equal(mod_common.hasChanged([], {}, {}), false); + t.equal(mod_common.hasChanged([], OBJ1, OBJ2), false); + t.equal(mod_common.hasChanged([ 'a' ], OBJ1, OBJ3), false); + t.equal(mod_common.hasChanged([ 'b' ], OBJ1, OBJ2), false); + t.equal(mod_common.hasChanged([ 'c' ], OBJ1, OBJ2), false); + + t.equal(mod_common.hasChanged([], OBJ1, OBJ1), false); + t.equal(mod_common.hasChanged([ 'a' ], OBJ1, OBJ1), false); + t.equal(mod_common.hasChanged([ 'b' ], OBJ1, OBJ1), false); + t.equal(mod_common.hasChanged([ 'c' ], OBJ1, OBJ1), false); + + t.end(); +});