This is a solution for Gojek parking lot test
To build this locally you should either have Go or Docker installed.
$ cd parking-lot
$ go install
$ parking-lot -h
Usage of parking-lot:
-f string
Execute parking lot instructions from given file
-i Execute parking lot instructions from interactive shell
$ cd parking-lot
$ docker build -t parking-lot
$ docker run -ti parking-lot -h
Usage of parking-lot:
-f string
Execute parking lot instructions from given file
-i Execute parking lot instructions from interactive shell
Usage of parking-lot:
-f string
Execute parking lot instructions from given file
-i Execute parking lot instructions from interactive shell
-stdin
Execute parking lot instructions from standard streams
$ parking-lot -f file_inputs.txt
Created a parking lot with 6 slots
Allocated slot number: 1
Allocated slot number: 2
Allocated slot number: 3
Allocated slot number: 5
Allocated slot number: 5
Allocated slot number: 6
...
$ cat file_inputs.txt | docker run -i parking-lot -i -stdin
created a parking lot with 6 slots
allocated slot number: 1
allocated slot number: 2
allocated slot number: 3
allocated slot number: 5
allocated slot number: 5
allocated slot number: 6
...
$ cat file_inputs.txt | parking-lot -i -stdin
created a parking lot with 6 slots
allocated slot number: 1
allocated slot number: 2
allocated slot number: 3
allocated slot number: 5
allocated slot number: 5
allocated slot number: 6
...
$ docker run -ti parking-lot -i
parking-lot> create_parking_lot 6
Created a parking lot with 6 slots
parking-lot> park KA-01-HH-1234 White
...
$ parking-lot -i
parking-lot> create_parking_lot 6
Created a parking lot with 6 slots
parking-lot> park KA-01-HH-1234 White
Allocated slot number: 1
parking-lot> park KA-01-HH-1234 White
Allocated slot number: 2
...
$ cd parking-lot
$ go test -v ./...
- Abstract out error handling in cli.Context