Skip to content

Commit

Permalink
feat(Node): add isPublic to node api
Browse files Browse the repository at this point in the history
We are using attributes.public_ip because the documentation states that
this indicates if the node is public. Please see:

https://docs.mesosphere.com/1.11/overview/architecture/node-types/#public-agent-nodes

Closes DCOS-39331
  • Loading branch information
Daniel Schmidt authored and nLight committed Jul 24, 2018
1 parent 8478adf commit 987648e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/js/structs/Node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export default class Node extends Item {
getOutput: () => any;
sumTaskTypesByState: (state: any) => any;
getUsedResources: () => any;
isPublic: () => boolean;
}
6 changes: 6 additions & 0 deletions src/js/structs/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ class Node extends Item {
}
);
}

isPublic() {
return (
findNestedPropertyInObject(this.get("attributes"), "public_ip") === "true"
);
}
}

module.exports = Node;
32 changes: 32 additions & 0 deletions src/js/structs/__tests__/Node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,36 @@ describe("Node", function() {
});
});
});

describe("#isPublic", function() {
const testCases = [
{
name: "returns true if attributes.public_ip is true",
expected: true,
value: { attributes: { public_ip: "true" } }
},
{
name: "returns false if attributes.public_ip is false",
expected: false,
value: { attributes: { public_ip: "false" } }
},
{
name: "returns false if attributes.public_ip is missing",
expected: false,
value: { attributes: {} }
},
{
name: "returns false if attributes is missing",
expected: false,
value: {}
}
];

testCases.forEach(function(test) {
it(test.name, function() {
const node = new Node(test.value);
expect(node.isPublic()).toEqual(test.expected);
});
});
});
});

0 comments on commit 987648e

Please sign in to comment.