Refactor main to accept commands and arguments
This commit is contained in:
parent
d624a3ca21
commit
6c09ee3826
3 changed files with 163 additions and 111 deletions
|
@ -3,10 +3,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
@ -15,42 +14,50 @@ import (
|
|||
|
||||
func Test_InnerMain(t *testing.T) {
|
||||
|
||||
// Use temporary local user data
|
||||
tmp, err := ioutil.TempDir(os.TempDir(), "rove-*")
|
||||
assert.NoError(t, err)
|
||||
os.Setenv("USER_DATA", tmp)
|
||||
|
||||
// Used for configuring this test
|
||||
var address = os.Getenv("ROVE_GRPC")
|
||||
if len(address) == 0 {
|
||||
log.Fatal("Must set $ROVE_GRPC")
|
||||
}
|
||||
|
||||
// Set up the flags to act locally and use a temporary file
|
||||
flag.Set("data", path.Join(os.TempDir(), uuid.New().String()))
|
||||
|
||||
// First attempt should error
|
||||
assert.Error(t, InnerMain("status"))
|
||||
|
||||
// Now set the host
|
||||
flag.Set("host", address)
|
||||
|
||||
// Then set the host
|
||||
// No error now as we have a host
|
||||
os.Setenv("ROVE_HOST", address)
|
||||
assert.NoError(t, InnerMain("status"))
|
||||
|
||||
// Set the host in the config
|
||||
assert.NoError(t, InnerMain("config", address))
|
||||
assert.NoError(t, InnerMain("status"))
|
||||
|
||||
// Register should fail without a name
|
||||
assert.Error(t, InnerMain("register"))
|
||||
|
||||
// These methods should fail without an account
|
||||
assert.Error(t, InnerMain("move"))
|
||||
assert.Error(t, InnerMain("radar"))
|
||||
assert.Error(t, InnerMain("rover"))
|
||||
|
||||
// Now set the name
|
||||
flag.Set("name", uuid.New().String())
|
||||
|
||||
// Perform the register
|
||||
assert.NoError(t, InnerMain("register"))
|
||||
assert.NoError(t, InnerMain("register", uuid.New().String()))
|
||||
|
||||
// These should now work
|
||||
assert.NoError(t, InnerMain("radar"))
|
||||
assert.NoError(t, InnerMain("rover"))
|
||||
|
||||
// Move should work with arguments
|
||||
flag.Set("bearing", "N")
|
||||
assert.NoError(t, InnerMain("move"))
|
||||
// Commands should fail with no commands
|
||||
assert.Error(t, InnerMain("commands"))
|
||||
|
||||
// Give it commands
|
||||
assert.NoError(t, InnerMain("commands", "move", "N"))
|
||||
assert.NoError(t, InnerMain("commands", "stash"))
|
||||
|
||||
// Give it malformed commands
|
||||
assert.Error(t, InnerMain("commands", "move", "stash"))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue