feat: Add bucket schema management commands (#52)
* feat: update generated client to include schema-management APIs * feat: implement interfaces to decode flags and CSV * feat: implement decoders for different measurement schema column formats * feat: extend bucket CLI commands to support schema type property * feat: add CLI commands to manage measurement schema * test: add unit tests for bucket schema create, update and list commands
This commit is contained in:
70
internal/cmd/bucket_schema/json_test.go
Normal file
70
internal/cmd/bucket_schema/json_test.go
Normal file
@ -0,0 +1,70 @@
|
||||
package bucket_schema
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/MakeNowJust/heredoc/v2"
|
||||
"github.com/influxdata/influx-cli/v2/internal/api"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDecodeJson(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
data string
|
||||
exp []api.MeasurementSchemaColumn
|
||||
expErr string
|
||||
}{
|
||||
{
|
||||
name: "valid",
|
||||
data: heredoc.Doc(`
|
||||
[
|
||||
{ "name": "time", "type": "timestamp" },
|
||||
{ "name": "host", "type": "tag" },
|
||||
{ "name": "usage_user", "type": "field", "dataType": "float" }
|
||||
]
|
||||
`),
|
||||
exp: cols(colTs(), colT("host"), colFF("usage_user")),
|
||||
},
|
||||
{
|
||||
name: "invalid column type",
|
||||
data: heredoc.Doc(`
|
||||
[
|
||||
{ "name": "time", "type": "foo" }
|
||||
]
|
||||
`),
|
||||
expErr: `error decoding JSON: foo is not a valid ColumnSemanticType`,
|
||||
},
|
||||
{
|
||||
name: "invalid column data type",
|
||||
data: heredoc.Doc(`
|
||||
[
|
||||
{ "name": "time", "type": "field", "dataType": "floaty" }
|
||||
]
|
||||
`),
|
||||
expErr: `error decoding JSON: floaty is not a valid ColumnDataType`,
|
||||
},
|
||||
{
|
||||
name: "invalid JSON",
|
||||
data: heredoc.Doc(`
|
||||
[
|
||||
{ "name": "time", "type": "field", "dataType": "floaty" }
|
||||
`),
|
||||
expErr: `error decoding JSON: unexpected EOF`,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := strings.NewReader(tt.data)
|
||||
got, err := decodeJson(r)
|
||||
if tt.expErr != "" {
|
||||
assert.EqualError(t, err, tt.expErr)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.exp, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user