Skip to content

Commit c252c79

Browse files
authored
fix asserts in tests (#107)
So that `actual` and `expected` are in the correct positions.
1 parent 98ee13b commit c252c79

20 files changed

+131
-127
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nflx-spectator",
3-
"version": "3.0.15",
3+
"version": "3.0.16",
44
"license": "Apache-2.0",
55
"homepage": "https://github.com/Netflix/spectator-js",
66
"author": "Netflix Telemetry Engineering <[email protected]>",

test/common_tags.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("Common Tags Tests", (): void => {
2626

2727
it("get tags from env vars", (): void => {
2828
setup_environment();
29-
assert.deepEqual(all_expected_tags(), tags_from_env_vars());
29+
assert.deepEqual(tags_from_env_vars(), all_expected_tags());
3030
clear_environment();
3131
});
3232

@@ -36,7 +36,7 @@ describe("Common Tags Tests", (): void => {
3636

3737
const expected_tags: Record<string, string> = all_expected_tags();
3838
delete expected_tags["nf.container"];
39-
assert.deepEqual(expected_tags, tags_from_env_vars());
39+
assert.deepEqual(tags_from_env_vars(), expected_tags);
4040

4141
clear_environment();
4242
});
@@ -47,20 +47,20 @@ describe("Common Tags Tests", (): void => {
4747

4848
const expected_tags: Record<string, string> = all_expected_tags();
4949
delete expected_tags["nf.container"];
50-
assert.deepEqual(expected_tags, tags_from_env_vars());
50+
assert.deepEqual(tags_from_env_vars(), expected_tags);
5151

5252
clear_environment();
5353
});
5454

5555
it("get tags from env vars with whitespace ignored", (): void => {
5656
setup_environment();
5757
process.env.TITUS_CONTAINER_NAME = " main \t\t";
58-
assert.deepEqual(all_expected_tags(), tags_from_env_vars());
58+
assert.deepEqual(tags_from_env_vars(), all_expected_tags());
5959
clear_environment();
6060
});
6161

6262
it("validate tags skips zero length strings", (): void => {
6363
const tags = {"a": "", "": "b", "cc": "1"};
64-
assert.deepEqual({"cc": "1"}, validate_tags(tags));
64+
assert.deepEqual(validate_tags(tags), {"cc": "1"});
6565
});
6666
});

test/config.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ describe("Config Tests", (): void => {
3232
setup_environment();
3333
const config = new Config();
3434
assert.deepEqual(all_expected_tags(), config.extra_common_tags);
35-
assert.equal("udp", config.location);
35+
assert.equal(config.location, "udp");
3636
clear_environment();
3737
});
3838

3939
it("env location override", (): void => {
4040
process.env.SPECTATOR_OUTPUT_LOCATION = "memory";
4141
const config = new Config();
42-
assert.equal("memory", config.location);
42+
assert.equal(config.location, "memory");
4343
clear_environment();
4444
});
4545

@@ -52,19 +52,19 @@ describe("Config Tests", (): void => {
5252
it("extra common tags", (): void => {
5353
setup_environment();
5454
const config = new Config(undefined, {"extra-tag": "foo"});
55-
assert.equal("udp", config.location);
56-
assert.deepEqual({"extra-tag": "foo", "nf.container": "main", "nf.process": "nodejs"}, config.extra_common_tags);
55+
assert.equal(config.location, "udp");
56+
assert.deepEqual(config.extra_common_tags, {"extra-tag": "foo", "nf.container": "main", "nf.process": "nodejs"});
5757
clear_environment();
5858
});
5959

6060
it("valid output locations", (): void => {
61-
assert.equal("none", get_location("none"));
62-
assert.equal("memory", get_location("memory"));
63-
assert.equal("stderr", get_location("stderr"));
64-
assert.equal("stdout", get_location("stdout"));
65-
assert.equal("udp", get_location("udp"));
66-
assert.equal("file://", get_location("file://"));
67-
assert.equal("udp://", get_location("udp://"));
61+
assert.equal(get_location("none"), "none");
62+
assert.equal(get_location("memory"), "memory");
63+
assert.equal(get_location("stderr"), "stderr");
64+
assert.equal(get_location("stdout"), "stdout");
65+
assert.equal(get_location("udp"), "udp");
66+
assert.equal(get_location("file://"), "file://");
67+
assert.equal(get_location("udp://"), "udp://");
6868
});
6969

7070
it("invalid output location throws", (): void => {

test/logger/logger.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ describe("Logger Tests", (): void => {
6262
log.warn("stern warning");
6363
log.error("error message");
6464

65-
assert.deepEqual(["WARN: stern warning", "ERROR: error message"], messages);
65+
const expected: string[] = [
66+
"WARN: stern warning",
67+
"ERROR: error message"
68+
];
69+
assert.deepEqual(messages, expected);
6670
console.log = f;
6771
});
6872
});

test/meter/age_gauge.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("AgeGauge Tests", (): void => {
1212
assert.isTrue(writer.is_empty());
1313

1414
g.now();
15-
assert.equal("A:age_gauge:0", writer.last_line());
15+
assert.equal(writer.last_line(), "A:age_gauge:0");
1616
});
1717

1818
it("set", (): void => {
@@ -21,6 +21,6 @@ describe("AgeGauge Tests", (): void => {
2121
assert.isTrue(writer.is_empty());
2222

2323
g.set(10);
24-
assert.equal("A:age_gauge:10", writer.last_line());
24+
assert.equal(writer.last_line(), "A:age_gauge:10");
2525
});
2626
});

test/meter/counter.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ describe("Counter Tests", (): void => {
1212
assert.isTrue(writer.is_empty());
1313

1414
c.add();
15-
assert.equal("c:counter:1", writer.last_line());
15+
assert.equal(writer.last_line(), "c:counter:1");
1616

1717
c.add(2);
18-
assert.equal("c:counter:2", writer.last_line());
18+
assert.equal(writer.last_line(), "c:counter:2");
1919
});
2020

2121
it("increment", (): void => {
@@ -24,10 +24,10 @@ describe("Counter Tests", (): void => {
2424
assert.isTrue(writer.is_empty());
2525

2626
c.increment();
27-
assert.equal("c:counter:1", writer.last_line());
27+
assert.equal(writer.last_line(), "c:counter:1");
2828

2929
c.increment(2);
30-
assert.equal("c:counter:2", writer.last_line());
30+
assert.equal(writer.last_line(), "c:counter:2");
3131
});
3232

3333
it("increment negative", (): void => {

test/meter/dist_summary.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("DistributionSummary Tests", (): void => {
1212
assert.isTrue(writer.is_empty());
1313

1414
d.record(42);
15-
assert.equal("d:dist_summary:42", writer.last_line());
15+
assert.equal(writer.last_line(), "d:dist_summary:42");
1616
});
1717

1818
it("record negative", (): void => {
@@ -26,6 +26,6 @@ describe("DistributionSummary Tests", (): void => {
2626
const d = new DistributionSummary(tid, new MemoryWriter());
2727
const writer = d.writer() as MemoryWriter;
2828
d.record(0);
29-
assert.equal("d:dist_summary:0", writer.last_line());
29+
assert.equal(writer.last_line(), "d:dist_summary:0");
3030
});
3131
});

test/meter/gauge.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("Gauge Tests", (): void => {
1212
assert.isTrue(writer.is_empty());
1313

1414
g.set(1);
15-
assert.equal("g:gauge:1", writer.last_line());
15+
assert.equal(writer.last_line(), "g:gauge:1");
1616
});
1717

1818
it("update delegates to set", (): void => {
@@ -21,13 +21,13 @@ describe("Gauge Tests", (): void => {
2121
assert.isTrue(writer.is_empty());
2222

2323
g.update(1);
24-
assert.equal("g:gauge:1", writer.last_line());
24+
assert.equal(writer.last_line(), "g:gauge:1");
2525
});
2626

2727
it("ttl_seconds", (): void => {
2828
const g = new Gauge(tid, new MemoryWriter(), 120);
2929
const writer = g.writer() as MemoryWriter;
3030
g.set(42);
31-
assert.equal("g,120:gauge:42", writer.last_line());
31+
assert.equal(writer.last_line(), "g,120:gauge:42");
3232
});
3333
});

test/meter/max_gauge.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("MaxGauge Tests", (): void => {
1212
assert.isTrue(writer.is_empty());
1313

1414
g.set(0);
15-
assert.equal("m:max_gauge:0", writer.last_line());
15+
assert.equal(writer.last_line(), "m:max_gauge:0");
1616
});
1717

1818
it("update delegates to set", (): void => {
@@ -21,6 +21,6 @@ describe("MaxGauge Tests", (): void => {
2121
assert.isTrue(writer.is_empty());
2222

2323
g.update(0);
24-
assert.equal("m:max_gauge:0", writer.last_line());
24+
assert.equal(writer.last_line(), "m:max_gauge:0");
2525
});
2626
});

test/meter/monotonic_counter.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("MonotonicCounter Tests", (): void => {
1212
assert.isTrue(writer.is_empty());
1313

1414
c.set(1);
15-
assert.equal("C:monotonic_counter:1", writer.last_line());
15+
assert.equal(writer.last_line(), "C:monotonic_counter:1");
1616
});
1717

1818
it("set negative", (): void => {
@@ -21,6 +21,6 @@ describe("MonotonicCounter Tests", (): void => {
2121
assert.isTrue(writer.is_empty());
2222

2323
c.set(-1);
24-
assert.equal("C:monotonic_counter:-1", writer.last_line());
24+
assert.equal(writer.last_line(), "C:monotonic_counter:-1");
2525
});
2626
});

0 commit comments

Comments
 (0)