Files
influx-cli/clients/v1_shell/v1_shell_test.go
Andrew Lee c695e601a5 Add REPL autocompletion & go-prompt (#392)
* add v1-compatible query path and refactor other paths to de-duplicate "/query"

* add initial influxQL repl

* add ping endpoint to schema

* improve prompt UX, implement some commands

* fix json column type in schema and improve completion

* feat: add table formatter and move to forked go-prompt

* improve formatting and add table pagination

* implement more REPL commands, including insert and history

* implement "INSERT INTO"

* move repl command to "v1 repl"

* refactor and improve documentation

* clean up v1_repl cmd

* update to latest openapi, use some openapi paths instead of overrides

* remove additional files that were moved to openapi

* compute historyFilePath at REPL start

* clean up REPL use command logic flow

* clean up comments for TODOs now in issues

* move gopher (chonky boi)

* remove autocompletion for separate PR

* run go mod tidy

* add back autocompletion & go-prompt

* add rfc3339 precision option

* allow left and right column scrolling to display whole table

* add error to JSON query response

* add tags and partial to JSON response series schema

* fix csv formatting and add column formatting

* remove table format for separate PR

* fix getDatabases

* move from write to legacy write endpoint for INSERT

* remove history vestiges

* allow multiple spaces in INSERT commands

* add precision comment

* remove auth for separate PR

* separate parseInsert and add unit test

* add additional test case and improve error messages

* fix missing errors import

* fix format suggestion

* re-add history implementation with history limit

* build: upgrade to Go 1.18.3 (#395)

* feat: add back the InfluxQL REPL (#386)

* add v1-compatible query path and refactor other paths to de-duplicate "/query"

* add initial influxQL repl

* add ping endpoint to schema

* improve prompt UX, implement some commands

* fix json column type in schema and improve completion

* feat: add table formatter and move to forked go-prompt

* improve formatting and add table pagination

* implement more REPL commands, including insert and history

* implement "INSERT INTO"

* move repl command to "v1 repl"

* refactor and improve documentation

* clean up v1_repl cmd

* update to latest openapi, use some openapi paths instead of overrides

* remove additional files that were moved to openapi

* compute historyFilePath at REPL start

* clean up REPL use command logic flow

* clean up comments for TODOs now in issues

* move gopher (chonky boi)

* remove autocompletion for separate PR

* run go mod tidy

* add rfc3339 precision option

* allow left and right column scrolling to display whole table

* add error to JSON query response

* add tags and partial to JSON response series schema

* fix csv formatting and add column formatting

* remove table format for separate PR

* fix getDatabases

* move from write to legacy write endpoint for INSERT

* remove history vestiges

* allow multiple spaces in INSERT commands

* add precision comment

* remove auth for separate PR

* separate parseInsert and add unit test

* add additional test case and improve error messages

* fix missing errors import

* print rfc3339 precision

* add rfc3339 to help output

* run tidy

* restructure autocomplete and handle review items

* improve autocompletion with leftover handling

* improve comments and add autocomplete for DELETE & DROP MEASUREMENT

* rename repl to shell

* remove unsupported CREATE & DROP autocompletions

* additional refactor for autocompletion

Co-authored-by: Dane Strandboge <dstrandboge@influxdata.com>
2022-06-14 15:18:27 -06:00

143 lines
3.1 KiB
Go

package v1shell_test
import (
"testing"
v1shell "github.com/influxdata/influx-cli/v2/clients/v1_shell"
)
var point = `weather,location=us-midwest temperature=82 1465839830100400200`
var db = "test_database"
var quotedDb = `"test_database"`
var rp = "test_retention_policy"
var quotedRp = `"test_retention_policy"`
type InsertTestCase struct {
cmd string
expectedDb string
expectedRp string
expectedPoint string
}
func (it *InsertTestCase) Test(t *testing.T) {
db, rp, point, isInsert := v1shell.ParseInsert(it.cmd)
if !isInsert {
t.Errorf("%q should be a valid INSERT command", it.cmd)
} else {
if db != it.expectedDb {
t.Errorf("Db mismatch: expected: %s, got: %s", it.expectedDb, db)
}
if rp != it.expectedRp {
t.Errorf("Rp mismatch: expected: %s, got: %s", it.expectedRp, rp)
}
if point != it.expectedPoint {
t.Errorf("Point mismatch: expected: %s, got: %s", it.expectedPoint, point)
}
}
}
var insertIntoCmds = []InsertTestCase{
{
cmd: `insert into ` + quotedDb + " " + point,
expectedDb: db,
expectedRp: "",
expectedPoint: point,
},
{
cmd: `insert into ` + quotedDb + "." + quotedRp + " " + point,
expectedDb: db,
expectedRp: rp,
expectedPoint: point,
},
{
cmd: `insert into ` + quotedDb + " " + point,
expectedDb: db,
expectedRp: "",
expectedPoint: point,
},
{
cmd: `insert into ` + quotedDb + "." + quotedRp + " " + point,
expectedDb: db,
expectedRp: rp,
expectedPoint: point,
},
{
cmd: `insert into ` + quotedDb + " " + point,
expectedDb: db,
expectedRp: "",
expectedPoint: point,
},
{
cmd: `InSeRt INtO ` + quotedDb + "." + quotedRp + " " + point,
expectedDb: db,
expectedRp: rp,
expectedPoint: point,
},
{
cmd: `INSERT INTO ` + quotedDb + "." + quotedRp + " " + point,
expectedDb: db,
expectedRp: rp,
expectedPoint: point,
},
}
var insertCmds = []InsertTestCase{
{
cmd: `INSERT ` + point,
expectedDb: "",
expectedRp: "",
expectedPoint: point,
},
{
cmd: `insert ` + point,
expectedDb: "",
expectedRp: "",
expectedPoint: point,
},
{
cmd: `INSERT ` + point,
expectedDb: "",
expectedRp: "",
expectedPoint: point,
},
{
cmd: `insert ` + point,
expectedDb: "",
expectedRp: "",
expectedPoint: point,
},
}
var invalidCmds = []string{
`insert` + point,
`insert into ` + point,
`INSERT` + point,
`insert into . ` + point,
`insert into ` + quotedDb + `. ` + point,
`insertinto ` + quotedDb + ` ` + point,
`insert into ` + quotedDb + `.` + quotedRp + ". " + point,
}
func TestParseInsert(t *testing.T) {
t.Parallel()
for _, insertCmd := range insertCmds {
insertCmd.Test(t)
}
}
func TestParseInsertInto(t *testing.T) {
t.Parallel()
for _, insertIntoCmd := range insertIntoCmds {
insertIntoCmd.Test(t)
}
}
func TestParseInsertInvalid(t *testing.T) {
t.Parallel()
for _, cmd := range invalidCmds {
if _, _, _, isValid := v1shell.ParseInsert(cmd); isValid {
t.Errorf("%q should be an invalid INSERT command", cmd)
}
}
}