Skip to content

feat(testing): add test for parse when error in args + config #4866

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

Merged
merged 3 commits into from
Feb 15, 2022
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
10 changes: 10 additions & 0 deletions test/unit/node/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,16 @@ describe("parser", () => {
"$argon2i$v=19$m=4096,t=3,p=1$0qr/o+0t00hsbjfqcksfdq$ofcm4rl6o+b7oxpua4qlxubypbbpsf+8l531u7p9hyy",
})
})
it("should throw an error for invalid config values", async () => {
const fakePath = "/fake-config-path"
const expectedErrMsg = `error reading ${fakePath}: `

expect(() =>
parse(["--foo"], {
configFile: fakePath,
}),
).toThrowError(expectedErrMsg)
})
})

describe("cli", () => {
Expand Down
18 changes: 9 additions & 9 deletions test/unit/node/update.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as http from "http"
import { logger } from "@coder/logger"
import * as http from "http"
import { AddressInfo } from "net"
import * as path from "path"
import { SettingsProvider, UpdateSettings } from "../../../src/node/settings"
Expand Down Expand Up @@ -218,8 +218,8 @@ describe("update", () => {
it("should reject if response has status code 500", async () => {
if (isAddressInfo(_address)) {
const mockURL = `http://${_address.address}:${_address.port}/reject-status-code`
let provider = new UpdateProvider(mockURL, settings())
let update = await provider.getUpdate(true)
const provider = new UpdateProvider(mockURL, settings())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very strange...I didn't make this change but when I ran yarn lint or yarn fmt locally, this changed happened?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh I think we are passing --fix to auto-fix but I did not know they would change let to const.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't either! Maybe a new thing? Or maybe I did something janky...no idea

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be something new! Either way, const looks right since we are not changing these values.

const update = await provider.getUpdate(true)

expect(update.version).toBe("unknown")
expect(logger.error).toHaveBeenCalled()
Expand All @@ -233,8 +233,8 @@ describe("update", () => {
it("should reject if no location header provided", async () => {
if (isAddressInfo(_address)) {
const mockURL = `http://${_address.address}:${_address.port}/no-location-header`
let provider = new UpdateProvider(mockURL, settings())
let update = await provider.getUpdate(true)
const provider = new UpdateProvider(mockURL, settings())
const update = await provider.getUpdate(true)

expect(update.version).toBe("unknown")
expect(logger.error).toHaveBeenCalled()
Expand All @@ -249,8 +249,8 @@ describe("update", () => {
version = "4.1.1"
if (isAddressInfo(_address)) {
const mockURL = `http://${_address.address}:${_address.port}/with-location-header`
let provider = new UpdateProvider(mockURL, settings())
let update = await provider.getUpdate(true)
const provider = new UpdateProvider(mockURL, settings())
const update = await provider.getUpdate(true)

expect(logger.error).not.toHaveBeenCalled()
expect(update.version).toBe("4.1.1")
Expand All @@ -260,8 +260,8 @@ describe("update", () => {
it("should reject if more than 10 redirects", async () => {
if (isAddressInfo(_address)) {
const mockURL = `http://${_address.address}:${_address.port}/redirect/11`
let provider = new UpdateProvider(mockURL, settings())
let update = await provider.getUpdate(true)
const provider = new UpdateProvider(mockURL, settings())
const update = await provider.getUpdate(true)

expect(update.version).toBe("unknown")
expect(logger.error).toHaveBeenCalled()
Expand Down