Skip to content

Commit

Permalink
TRITON-1653 net-agent thinks that networks are always changing
Browse files Browse the repository at this point in the history
Reviewed by: Jordan Hendricks <jordan.hendricks@joyent.com>
Approved by: Jordan Hendricks <jordan.hendricks@joyent.com>
  • Loading branch information
melloc committed May 10, 2019
1 parent 79ad705 commit 078bd4d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Makefile
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/common.js
Expand Up @@ -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]);
});
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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",
Expand Down
51 changes: 51 additions & 0 deletions 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();
});

0 comments on commit 078bd4d

Please sign in to comment.