-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(git): Removed errornous gitignore entry
- Loading branch information
1 parent
f63e47e
commit ec6f108
Showing
5 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
app | ||
.idea | ||
|
||
dist/ | ||
geocodio | ||
geocodio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |