al3rez / parking-lot

Parking lot - Gojek :car:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

parking-lot Build Status codebeat badge

This is a solution for Gojek parking lot test

Installation

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

Building parking-lot binary inside a Docker container:

$ 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

CLI Usage

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

Read instructions from a file (locally)

$ 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
...

Read instructions from a file (it's actually standard stream) (Docker)

$ 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
...

Read instructions from interactive shell (locally/Docker)

$ 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
...

Running tests

$ cd parking-lot
$ go test -v ./...

TODO

  • Abstract out error handling in cli.Context

About

Parking lot - Gojek :car:


Languages

Language:Go 76.8%Language:Ruby 21.2%Language:Shell 1.2%Language:Dockerfile 0.8%