Skip to content

Commit

Permalink
#7 Update unit tests to support new variables
Browse files Browse the repository at this point in the history
  • Loading branch information
danielemery committed Jul 26, 2024
1 parent 88db08e commit 96d50bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
run: deno lint

- name: Run tests
env:
DOPPLER_ENVIRONMENT: gitlab_ci
KEYS_VERSION: gitlab_ci
run: |
deno test --coverage=coverage
deno coverage ./coverage --lcov --output=coverage.lcov
Expand Down
27 changes: 21 additions & 6 deletions src/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,46 @@ import {
import { parseEnvironmentVariables } from "./environment.ts";
import { ZodError } from "../deps.ts";

const baseVariables = {
DOPPLER_ENVIRONMENT: "unit_tests",
KEYS_VERSION: "unit_tests",
};

Deno.test(
"parseEnvironmentVariables: must convert string variables to correct types",
() => {
const variables = {
...baseVariables,
PORT: "1234",
};

assertEquals(parseEnvironmentVariables(variables), { PORT: 1234 });
},
assertEquals(parseEnvironmentVariables(variables), {
...baseVariables,
PORT: 1234,
});
}
);
Deno.test(
"parseEnvironmentVariables: must use defaults if variables are not supplied",
() => {
const variables = {};
const variables = {
...baseVariables,
};

assertEquals(parseEnvironmentVariables(variables), { PORT: 8000 });
},
assertEquals(parseEnvironmentVariables(variables), {
...baseVariables,
PORT: 8000,
});
}
);
Deno.test(
"parseEnvironmentVariables: must throw ZodError if input is invalid",
() => {
const variables = {
...baseVariables,
PORT: "not-a-number",
};

assertThrows(() => parseEnvironmentVariables(variables), ZodError);
},
}
);

0 comments on commit 96d50bb

Please sign in to comment.