chore: Test to validate expected behavior of SHOW DATABASES
parent
50752f9a6a
commit
484f606a1e
|
@ -7,6 +7,11 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/influxdata/influxdb/v2"
|
||||||
|
icontext "github.com/influxdata/influxdb/v2/context"
|
||||||
|
"github.com/influxdata/influxdb/v2/tests"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Ensure parameterized queries can be executed
|
// Ensure parameterized queries can be executed
|
||||||
|
@ -82,3 +87,60 @@ func TestServer_Query_Chunked(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
test.Run(ctx, t, s)
|
test.Run(ctx, t, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServer_Query_ShowDatabases(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
s := OpenServer(t)
|
||||||
|
defer s.MustClose()
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
ctx = icontext.SetAuthorizer(ctx, tests.MakeAuthorization(s.DefaultOrgID, s.DefaultUserID, influxdb.OperPermissions()))
|
||||||
|
|
||||||
|
// create some buckets and mappings
|
||||||
|
buckets := []struct {
|
||||||
|
name string
|
||||||
|
db string
|
||||||
|
rp string
|
||||||
|
}{
|
||||||
|
{"my-bucket", "my-bucket", "autogen"},
|
||||||
|
{"telegraf/autogen", "telegraf", "autogen"},
|
||||||
|
{"telegraf/1_week", "telegraf", "1_week"},
|
||||||
|
{"telegraf/1_month", "telegraf", "1_month"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, bi := range buckets {
|
||||||
|
b := influxdb.Bucket{
|
||||||
|
OrgID: s.DefaultOrgID,
|
||||||
|
Type: influxdb.BucketTypeUser,
|
||||||
|
Name: bi.name,
|
||||||
|
RetentionPeriod: 0,
|
||||||
|
}
|
||||||
|
err := s.Launcher.
|
||||||
|
Launcher.
|
||||||
|
BucketService().
|
||||||
|
CreateBucket(ctx, &b)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
err = s.Launcher.
|
||||||
|
DBRPMappingServiceV2().
|
||||||
|
Create(ctx, &influxdb.DBRPMappingV2{
|
||||||
|
Database: bi.db,
|
||||||
|
RetentionPolicy: bi.rp,
|
||||||
|
Default: true,
|
||||||
|
OrganizationID: s.DefaultOrgID,
|
||||||
|
BucketID: b.ID,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
test := NewEmptyTest()
|
||||||
|
test.addQueries(
|
||||||
|
&Query{
|
||||||
|
name: "show databases does not return duplicates",
|
||||||
|
command: "SHOW DATABASES",
|
||||||
|
exp: `{"results":[{"statement_id":0,"series":[{"name":"databases","columns":["name"],"values":[["my-bucket"],["telegraf"]]}]}]}`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
test.Run(context.Background(), t, s)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue