Skip to content

Commit

Permalink
fix(git): Removed errornous gitignore entry
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniCodeMonkey committed Jan 15, 2022
1 parent f63e47e commit ec6f108
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
app
.idea

dist/
geocodio
geocodio
45 changes: 45 additions & 0 deletions app/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package app

import (
"github.com/geocodio/geocodio-cli/create"
"github.com/geocodio/geocodio-cli/download"
"github.com/geocodio/geocodio-cli/list"
"github.com/geocodio/geocodio-cli/release"
"github.com/geocodio/geocodio-cli/remove"
"github.com/geocodio/geocodio-cli/status"
"github.com/urfave/cli/v2"
)

func BuildApp() *cli.App {
app := cli.NewApp()
app.Name = "Geocodio"
app.Usage = "Geocode lists using the Geocodio API"
app.Version = release.Version()
app.EnableBashCompletion = true
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "hostname",
Aliases: []string{"n"},
Value: "api.geocod.io",
Usage: "Geocodio hostname to use, change this for Geocodio+HIPAA or on-premise environments",
EnvVars: []string{"GEOCODIO_HOSTNAME"},
},
&cli.StringFlag{
Name: "apikey",
Aliases: []string{"k"},
Value: "",
Usage: "Geocodio API Key to use. Generate a new one in the Geocodio Dashboard",
EnvVars: []string{"GEOCODIO_API_KEY"},
Required: true,
},
}
app.Commands = []*cli.Command{
create.RegisterCommand(),
list.RegisterCommand(),
status.RegisterCommand(),
remove.RegisterCommand(),
download.RegisterCommand(),
}

return app
}
21 changes: 21 additions & 0 deletions app/cli_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package app

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestNoArgs(t *testing.T) {
err, output := RunAppForTesting([]string{})

assert.Contains(t, err.Error(), "\"apikey\" not set", "apikey flag should be required")
assert.Contains(t, output, "Geocodio - Geocode lists using the Geocodio API", "Output should contain expected string")
}

func TestWithDummyAPIKey(t *testing.T) {
err, output := RunAppForTesting([]string{"--apikey=DEMO"})

assert.Nil(t, err)
assert.Contains(t, output, "Geocodio - Geocode lists using the Geocodio API", "Output should contain expected string")
}

28 changes: 28 additions & 0 deletions app/status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package app

import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)

func TestStatusWithoutArgument(t *testing.T) {
err, output := RunAppForTesting([]string{"--apikey=" + os.Getenv("GEOCODIO_TEST_API_KEY"), "status"})

assert.Contains(t, err.Error(), "Invalid spreadsheet job id specified")
assert.Equal(t, "", output, "No standard output should be present")
}

func TestStatusWithInvalidSpreadsheetId(t *testing.T) {
err, output := RunAppForTesting([]string{"--apikey=" + os.Getenv("GEOCODIO_TEST_API_KEY"), "status", "1"})

assert.Contains(t, err.Error(), " No spreadsheet job with that id found")
assert.Equal(t, "", output, "No standard output should be present")
}

func TestStatusWithValidSpreadsheetId(t *testing.T) {
err, output := RunAppForTesting([]string{"--apikey=" + os.Getenv("GEOCODIO_TEST_API_KEY"), "status", "11471563"})

assert.Nil(t, err)
assert.Contains(t, output, "State: COMPLETED")
}
24 changes: 24 additions & 0 deletions app/testutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package app

import (
"bytes"
"github.com/urfave/cli/v2"
"os"
)

func RunAppForTesting(args []string) (error, string) {
w := new(bytes.Buffer)

program := os.Args[0:1]
args = append(program, args...)

app := BuildApp()
app.ExitErrHandler = func(context *cli.Context, err error) {
// Do nothing
}
app.Writer = w

err := app.Run(args)

return err, w.String()
}

0 comments on commit ec6f108

Please sign in to comment.