Skip to content

Commit

Permalink
fixup! WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Mar 29, 2024
1 parent ac2d0be commit c29fb30
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,20 @@ export const redisPrimary = kubernetesAddress("redis-primary", {
],
},
});

// constraints
const const redisPrimary = kubernetesAddress("redis-primary", {
constraints: [
{
description: "must be allowed",
constrain: ({ host, port }) =>
[
"insecure.redis.example.org:80",
"secure.redis.example.org:443",
].includes(`${host}:${port}`) || "not allowed",
},
],
});
```

### `networkPortNumber`
Expand Down
52 changes: 52 additions & 0 deletions test/suite/declaration/kubernetes-address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,58 @@ describe("Kubernetes address declarations", () => {
});
});

describe("when the declaration has the constraints from the README", () => {
beforeEach(() => {
declaration = kubernetesAddress("redis-primary", {
constraints: [
{
description: "must be allowed",
constrain: ({ host, port }) =>
[
"insecure.redis.example.org:80",
"secure.redis.example.org:443",
].includes(`${host}:${port}`) || "not allowed",
},
],
});
});

describe("when the value satisfies the constraints", () => {
beforeEach(() => {
process.env.REDIS_PRIMARY_SERVICE_HOST = "secure.redis.example.org";
process.env.REDIS_PRIMARY_SERVICE_PORT = "443";

initialize({ onInvalid: noop });
});

describe(".value()", () => {
it("returns the value", () => {
expect(declaration.value()).toEqual({
host: "secure.redis.example.org",
port: 443,
});
});
});
});

describe("when the value violates the constraints", () => {
beforeEach(() => {
process.env.REDIS_PRIMARY_SERVICE_HOST = "secure.redis.example.org";
process.env.REDIS_PRIMARY_SERVICE_PORT = "80";

initialize({ onInvalid: noop });
});

describe(".value()", () => {
it("throws", () => {
expect(() => {
declaration.value();
}).toThrow("not allowed");
});
});
});
});

describe.each`
description | host
${"IPv4"} | ${"192.168.1.2"}
Expand Down

0 comments on commit c29fb30

Please sign in to comment.