Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Deno v0.42 #112

Merged
merged 7 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
- name: Install deno
uses: denolib/setup-deno@master
with:
deno-version: 0.41.0
deno-version: 0.42.0

- name: Check formatting
run: deno fmt --check

- name: Run tests
run: deno run -r --allow-net --allow-env test.ts
run: deno test --allow-net --allow-env test.ts
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ When contributing to repository make sure to:

a) open an issue for what you're working on

b) use strict mode in TypeScript code (use `tsconfig.test.json` configuration)

```shell
$ deno run -c tsconfig.test.json -A test.ts
```

c) properly format code using `deno fmt`
b) properly format code using `deno fmt`

```shell
$ deno fmt -- --check
Expand Down
22 changes: 12 additions & 10 deletions connection_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { parseDsn } from "./utils.ts";

function getPgEnv(): IConnectionParams {
try {
const env = Deno.env();
const env = Deno.env;
return {
database: env.PGDATABASE,
host: env.PGHOST,
port: env.PGPORT,
user: env.PGUSER,
password: env.PGPASSWORD,
application_name: env.PGAPPNAME,
database: env.get("PGDATABASE"),
host: env.get("PGHOST"),
port: env.get("PGPORT"),
user: env.get("PGUSER"),
password: env.get("PGPASSWORD"),
application_name: env.get("PGAPPNAME"),
};
} catch (e) {
// PermissionDenied (--allow-env not passed)
Expand Down Expand Up @@ -110,9 +110,11 @@ export class ConnectionParams {

if (missingParams.length) {
throw new ConnectionParamsError(
`Missing connection parameters: ${missingParams.join(
", ",
)}. Connection parameters can be read
`Missing connection parameters: ${
missingParams.join(
", ",
)
}. Connection parameters can be read
from environment only if Deno is run with env permission (deno run --allow-env)`,
);
}
Expand Down
6 changes: 3 additions & 3 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export {
BufReader,
BufWriter,
} from "https://deno.land/std@v0.41.0/io/bufio.ts";
} from "https://deno.land/std@v0.42.0/io/bufio.ts";

export { copyBytes } from "https://deno.land/std@v0.41.0/io/util.ts";
export { copyBytes } from "https://deno.land/std@v0.42.0/io/util.ts";

export {
Deferred,
deferred,
} from "https://deno.land/std@v0.41.0/util/async.ts";
} from "https://deno.land/std@v0.42.0/util/async.ts";

export { Hash } from "https://deno.land/x/[email protected]/mod.ts";
4 changes: 1 addition & 3 deletions test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#! /usr/bin/env deno run --allow-net --allow-env test.ts
#! /usr/bin/env deno test --allow-net --allow-env test.ts
import "./tests/data_types.ts";
import "./tests/queries.ts";
import "./tests/connection_params.ts";
import "./tests/client.ts";
import "./tests/pool.ts";
import "./tests/utils.ts";

await Deno.runTests();
2 changes: 1 addition & 1 deletion test_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export {
assertEquals,
assertStrContains,
assertThrowsAsync,
} from "https://deno.land/std@v0.41.0/testing/asserts.ts";
} from "https://deno.land/std@v0.42.0/testing/asserts.ts";
2 changes: 1 addition & 1 deletion tests/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Client, PostgresError } from "../mod.ts";
import { assert, assertStrContains } from "../test_deps.ts";
import { TEST_CONNECTION_PARAMS } from "./constants.ts";

test(async function badAuthData() {
test("badAuthData", async function () {
const badConnectionData = { ...TEST_CONNECTION_PARAMS };
badConnectionData.password += "foobar";
const client = new Client(badConnectionData);
Expand Down
28 changes: 14 additions & 14 deletions tests/connection_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { test } = Deno;
import { assertEquals, assertStrContains } from "../test_deps.ts";
import { ConnectionParams } from "../connection_params.ts";

test(async function dsnStyleParameters() {
test("dsnStyleParameters", async function () {
const p = new ConnectionParams(
"postgres://some_user@some_host:10101/deno_postgres",
);
Expand All @@ -13,7 +13,7 @@ test(async function dsnStyleParameters() {
assertEquals(p.port, "10101");
});

test(async function objectStyleParameters() {
test("objectStyleParameters", async function () {
const p = new ConnectionParams({
user: "some_user",
host: "some_host",
Expand All @@ -28,13 +28,13 @@ test(async function objectStyleParameters() {
});

// TODO: add test when env is not allowed
test(async function envParameters() {
const currentEnv = Deno.env();
test("envParameters", async function () {
const currentEnv = Deno.env;

currentEnv.PGUSER = "some_user";
currentEnv.PGHOST = "some_host";
currentEnv.PGPORT = "10101";
currentEnv.PGDATABASE = "deno_postgres";
currentEnv.set("PGUSER", "some_user");
currentEnv.set("PGHOST", "some_host");
currentEnv.set("PGPORT", "10101");
currentEnv.set("PGDATABASE", "deno_postgres");

const p = new ConnectionParams();
assertEquals(p.database, "deno_postgres");
Expand All @@ -43,13 +43,13 @@ test(async function envParameters() {
assertEquals(p.port, "10101");

// clear out env
currentEnv.PGUSER = "";
currentEnv.PGHOST = "";
currentEnv.PGPORT = "";
currentEnv.PGDATABASE = "";
currentEnv.set("PGUSER", "");
currentEnv.set("PGHOST", "");
currentEnv.set("PGPORT", "");
currentEnv.set("PGDATABASE", "");
});

test(async function defaultParameters() {
test("defaultParameters", async function () {
const p = new ConnectionParams({
database: "deno_postgres",
user: "deno_postgres",
Expand All @@ -61,7 +61,7 @@ test(async function defaultParameters() {
assertEquals(p.password, undefined);
});

test(async function requiredParameters() {
test("requiredParameters", async function () {
let thrown = false;

try {
Expand Down
29 changes: 15 additions & 14 deletions tests/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function overrideTimezoneOffset(offset: number) {
};
}

test(function encodeDatetime() {
test("encodeDatetime", function () {
// GMT
overrideTimezoneOffset(0);

Expand All @@ -36,53 +36,54 @@ test(function encodeDatetime() {
resetTimezoneOffset();
});

test(function encodeUndefined() {
test("encodeUndefined", function () {
assertEquals(encode(undefined), null);
});

test(function encodeNull() {
test("encodeNull", function () {
assertEquals(encode(null), null);
});

test(function encodeBoolean() {
test("encodeBoolean", function () {
assertEquals(encode(true), "true");
assertEquals(encode(false), "false");
});

test(function encodeNumber() {
test("encodeNumber", function () {
assertEquals(encode(1), "1");
assertEquals(encode(1.2345), "1.2345");
});

test(function encodeString() {
test("encodeString", function () {
assertEquals(encode("deno-postgres"), "deno-postgres");
});

test(function encodeObject() {
test("encodeObject", function () {
assertEquals(encode({ x: 1 }), '{"x":1}');
});

test(function encodeUint8Array() {
const buf = new Uint8Array([1, 2, 3]);
const encoded = encode(buf);
test("encodeUint8Array", function () {
const buf_1 = new Uint8Array([1, 2, 3]);
const buf_2 = new Uint8Array([2, 10, 500]);

assertEquals(buf, encoded);
assertEquals("\\x010203", encode(buf_1));
assertEquals("\\x02af4", encode(buf_2));
});

test(function encodeArray() {
test("encodeArray", function () {
const array = [null, "postgres", 1, ["foo", "bar"]];
const encodedArray = encode(array);

assertEquals(encodedArray, '{NULL,"postgres","1",{"foo","bar"}}');
});

test(function encodeObjectArray() {
test("encodeObjectArray", function () {
const array = [{ x: 1 }, { y: 2 }];
const encodedArray = encode(array);
assertEquals(encodedArray, '{"{\\"x\\":1}","{\\"y\\":2}"}');
});

test(function encodeDateArray() {
test("encodeDateArray", function () {
overrideTimezoneOffset(0);

const array = [new Date(2019, 1, 10, 20, 30, 40, 5)];
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { test } = Deno;
import { assertEquals } from "../test_deps.ts";
import { parseDsn, DsnResult } from "../utils.ts";

test(function testParseDsn() {
test("testParseDsn", function () {
let c: DsnResult;

c = parseDsn(
Expand Down
6 changes: 3 additions & 3 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export function readInt32BE(buffer: Uint8Array, offset: number): number {

return (
(buffer[offset] << 24) |
(buffer[offset + 1] << 16) |
(buffer[offset + 2] << 8) |
buffer[offset + 3]
(buffer[offset + 1] << 16) |
(buffer[offset + 2] << 8) |
buffer[offset + 3]
);
}

Expand Down