Skip to content

Commit 1c5929c

Browse files
committed
[ISSUE#51]: writing tests
Signed-off-by: ashish <ashishpatel0720@gmail.com>
1 parent 42c2b90 commit 1c5929c

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/commands/avro.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import Utilities from '../utilities/utilities'
88

99
export default class Avro extends Command {
1010
static description = 'Avro Utility command'
11-
static SupportedCommands = ['get_schema', 'to_json', 'to_avro']
11+
12+
static GET_SCHEMA = 'get_schema'
13+
static TO_JSON = 'to_json'
14+
static TO_AVRO = 'to_avro'
15+
16+
// do not change order otherwise we need to change order in getCommand() also
17+
static SupportedCommands = [Avro.GET_SCHEMA, Avro.TO_JSON, Avro.TO_AVRO]
1218
static flags = {
1319
help: flags.help({char: 'h'}),
1420
file: flags.string({char: 'f' , description: 'input file path'}),
@@ -30,16 +36,22 @@ export default class Avro extends Command {
3036

3137
// to check required parameters passed or not
3238
private checkParameters(flags: any, args: any) {
33-
if (flags.file === undefined || flags.file === '')
39+
if (!flags.file)
3440
Logger.error(this, 'Input file is not provided')
35-
if (flags.output === undefined || args.output === '')
36-
Logger.error(this, 'Output file is not provided')
37-
if (args.command === undefined || args.command === '')
41+
if (!args.command)
3842
Logger.error(this, 'Command is empty or not provided, supported:' + Avro.SupportedCommands)
43+
44+
// if exists then make it upperCase
45+
args.command = args.command.toLowerCase()
46+
47+
// output is not mendatory for 'get_schema' command
48+
if (args.command !== Avro.GET_SCHEMA && !flags.output)
49+
Logger.error(this, 'Output file is not provided')
50+
3951
}
4052

4153
private executeCommand(flags: any, args: any) {
42-
switch (args.command.toLowerCase()) {
54+
switch (args.command) {
4355
case Avro.SupportedCommands[0]:
4456
return this.getSchema(flags, args)
4557
case Avro.SupportedCommands[1]:

test/commands/avro.test.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {expect, test} from '@oclif/test'
55
describe('avro', () => {
66
//todo if file is invalid
77
test
8-
.timeout(10000) // added timeout to remove timeout problem
8+
.timeout(10000) // added timeout to resolve timeout problem
99
.stdout()
1010
.command(['avro'])
1111
.exit(0)
@@ -14,21 +14,21 @@ describe('avro', () => {
1414
})
1515
test
1616
.stdout()
17-
.command(['avro', '-f' ,'test/resources/avro/person.avro'])
17+
.command(['avro', '-f', 'test/resources/avro/person.avro', 'to_avro'])
1818
.exit(0)
19-
.it('if output is not passed', ctx => {
19+
.it('if output file is not passed when mendatory', ctx => {
2020
expect(ctx.stdout).to.contain('Output file is not provided')
2121
})
2222
test
2323
.stdout()
24-
.command(['avro', '-f' ,'test/resources/avro/person.avro', '-o', 'output_file.example'])
24+
.command(['avro', '-f', 'test/resources/avro/person.avro', '-o', 'output_file.example'])
2525
.exit(0)
2626
.it('if command not passed', ctx => {
2727
expect(ctx.stdout).to.contain('Command is empty or not provided')
2828
})
2929
test
3030
.stdout()
31-
.command(['avro', '-f' ,'test/resources/avro/person.avro', '-o', 'output_file.example', 'unsupported_command'])
31+
.command(['avro', '-f', 'test/resources/avro/person.avro', '-o', 'output_file.example', 'unsupported_command'])
3232
.exit(0)
3333
.it('if command is invalid', ctx => {
3434
expect(ctx.stdout).to.contain('Unsupported Command')
@@ -45,7 +45,7 @@ describe('avro', () => {
4545

4646
test
4747
.stdout()
48-
.command(['avro', '-f' ,'test/resources/avro/person.avro', '-o', 'output_file.example', 'to_avro'])
48+
.command(['avro', '-f', 'test/resources/avro/person.avro', '-o', 'output_file.example', 'to_avro'])
4949
.exit(0)
5050
.it('if schema file path is not passed for to_avro', ctx => {
5151
expect(ctx.stdout).to.contain('Schema file is not provided')
@@ -55,4 +55,13 @@ describe('avro', () => {
5555
// 1 - get schema
5656
// 2 - to json
5757
// 3 - to avro
58+
59+
test
60+
.stdout()
61+
.command(['avro', '-f', 'test/resources/avro/person.avro', 'get_schema'])
62+
.it('if get_schema outputs to console', ctx => {
63+
expect(ctx.stdout).to.contain('success')
64+
})
65+
66+
5867
})

test/commands/hash.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {expect, test} from '@oclif/test'
22

33
describe('hash', () => {
44
test
5+
.timeout(10000) // added timeout to resolve timeout problem
56
.stdout()
67
.command(['hash', 'ashish'])
78
.it("Check default type -> cdt hash 'ashish'", ctx => {

0 commit comments

Comments
 (0)