Skip to content

Commit 051a6aa

Browse files
authored
Clarify difference in virtual vs physical dbrps when listing (#439)
* fix: separate v1 dbrp list results into physical and virtual * fix: remove virtual column from v1 dbrp list * fix: update v1 dbrp list tests for new format * fix: add new test with virtual result
1 parent 65ff49f commit 051a6aa

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

clients/v1_dbrps/v1_dbrps.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,20 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
6868
if err != nil {
6969
return fmt.Errorf("failed to list dbrps: %w", err)
7070
}
71+
var virtDbrps []api.DBRP
72+
var physDbrps []api.DBRP
73+
for _, dbrp := range dbrps.GetContent() {
74+
if dbrp.GetVirtual() {
75+
virtDbrps = append(virtDbrps, dbrp)
76+
} else {
77+
physDbrps = append(physDbrps, dbrp)
78+
}
79+
}
7180

72-
c.printDBRPs(dbrpPrintOpts{dbrps: dbrps.GetContent()})
81+
c.printDBRPs(dbrpPrintOpts{dbrps: physDbrps})
82+
fmt.Fprintln(c.StdIO, "\nVIRTUAL DBRP MAPPINGS (READ-ONLY)")
83+
fmt.Fprintln(c.StdIO, "----------------------------------")
84+
c.printDBRPs(dbrpPrintOpts{dbrps: virtDbrps})
7385

7486
return nil
7587
}
@@ -207,7 +219,6 @@ func (c Client) printDBRPs(opts dbrpPrintOpts) error {
207219
"Bucket ID",
208220
"Retention Policy",
209221
"Default",
210-
"Virtual",
211222
"Organization ID",
212223
}
213224

@@ -222,7 +233,6 @@ func (c Client) printDBRPs(opts dbrpPrintOpts) error {
222233
"Database": t.Database,
223234
"Retention Policy": t.RetentionPolicy,
224235
"Default": t.Default,
225-
"Virtual": t.GetVirtual(),
226236
"Organization ID": t.OrgID,
227237
"Bucket ID": t.BucketID,
228238
}

clients/v1_dbrps/v1_dbrps_test.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestClient_List(t *testing.T) {
3131
registerExpectations func(*testing.T, *mock.MockDBRPsApi)
3232
expectedError error
3333
outLines []string
34+
virtLines []string
3435
}{
3536
{
3637
name: "no org id or org name",
@@ -74,14 +75,27 @@ func TestClient_List(t *testing.T) {
7475
BucketID: "456",
7576
RetentionPolicy: "someRP",
7677
Default: true,
78+
Virtual: api.PtrBool(false),
79+
OrgID: "1234123412341234",
80+
},
81+
{
82+
Id: "567",
83+
Database: "someDB",
84+
BucketID: "456",
85+
RetentionPolicy: "someRP",
86+
Default: true,
87+
Virtual: api.PtrBool(true),
7788
OrgID: "1234123412341234",
7889
},
7990
},
8091
}, nil)
8192
},
8293
outLines: []string{
83-
`123\s+someDB\s+456\s+someRP\s+false\s+false\s+1234123412341234`,
84-
`234\s+someDB\s+456\s+someRP\s+true\s+false\s+1234123412341234`,
94+
`123\s+someDB\s+456\s+someRP\s+false\s+1234123412341234`,
95+
`234\s+someDB\s+456\s+someRP\s+true\s+1234123412341234`,
96+
},
97+
virtLines: []string{
98+
`567\s+someDB\s+456\s+someRP\s+true\s+1234123412341234`,
8599
},
86100
},
87101
{
@@ -120,7 +134,15 @@ func TestClient_List(t *testing.T) {
120134
require.Equal(t, tc.expectedError, err)
121135

122136
if tc.expectedError == nil {
123-
testutils.MatchLines(t, append([]string{`ID\s+Database\s+Bucket\s+ID\s+Retention Policy\s+Default\s+Virtual\s+Organization ID`}, tc.outLines...), strings.Split(stdout.String(), "\n"))
137+
header := `ID\s+Database\s+Bucket\s+ID\s+Retention Policy\s+Default\s+Organization ID`
138+
testutils.MatchLines(t,
139+
append([]string{header},
140+
append(tc.outLines,
141+
append([]string{
142+
`VIRTUAL DBRP MAPPINGS \(READ-ONLY\)`,
143+
"----------------------------------",
144+
header}, tc.virtLines...)...)...),
145+
strings.Split(stdout.String(), "\n"))
124146
}
125147
})
126148
}
@@ -160,7 +182,7 @@ func TestClient_Create(t *testing.T) {
160182
}, nil)
161183
},
162184
outLines: []string{
163-
`123\s+someDB\s+456\s+someRP\s+false\s+false\s+1234123412341234`,
185+
`123\s+someDB\s+456\s+someRP\s+false\s+1234123412341234`,
164186
},
165187
},
166188
{
@@ -200,7 +222,7 @@ func TestClient_Create(t *testing.T) {
200222
require.Equal(t, tc.expectedError, err)
201223

202224
if tc.expectedError == nil {
203-
testutils.MatchLines(t, append([]string{`ID\s+Database\s+Bucket\s+ID\s+Retention Policy\s+Default\s+Virtual\s+Organization ID`}, tc.outLines...), strings.Split(stdout.String(), "\n"))
225+
testutils.MatchLines(t, append([]string{`ID\s+Database\s+Bucket\s+ID\s+Retention Policy\s+Default\s+Organization ID`}, tc.outLines...), strings.Split(stdout.String(), "\n"))
204226
}
205227
})
206228
}
@@ -243,7 +265,7 @@ func TestClient_Update(t *testing.T) {
243265
}, nil)
244266
},
245267
outLines: []string{
246-
`123\s+someDB\s+456\s+someRP\s+false\s+false\s+1234123412341234`,
268+
`123\s+someDB\s+456\s+someRP\s+false\s+1234123412341234`,
247269
},
248270
},
249271
{
@@ -268,7 +290,7 @@ func TestClient_Update(t *testing.T) {
268290
}, nil)
269291
},
270292
outLines: []string{
271-
`123\s+someDB\s+456\s+someRP\s+false\s+false\s+1234123412341234`,
293+
`123\s+someDB\s+456\s+someRP\s+false\s+1234123412341234`,
272294
},
273295
},
274296
{
@@ -308,7 +330,7 @@ func TestClient_Update(t *testing.T) {
308330
require.Equal(t, tc.expectedError, err)
309331

310332
if tc.expectedError == nil {
311-
testutils.MatchLines(t, append([]string{`ID\s+Database\s+Bucket\s+ID\s+Retention Policy\s+Default\s+Virtual\s+Organization ID`}, tc.outLines...), strings.Split(stdout.String(), "\n"))
333+
testutils.MatchLines(t, append([]string{`ID\s+Database\s+Bucket\s+ID\s+Retention Policy\s+Default\s+Organization ID`}, tc.outLines...), strings.Split(stdout.String(), "\n"))
312334
}
313335
})
314336
}
@@ -355,7 +377,7 @@ func TestClient_Delete(t *testing.T) {
355377
DBRPsApi.EXPECT().DeleteDBRPIDExecute(gomock.Any()).Return(nil)
356378
},
357379
outLines: []string{
358-
`123\s+someDB\s+456\s+someRP\s+false\s+false\s+1234123412341234`,
380+
`123\s+someDB\s+456\s+someRP\s+false\s+1234123412341234`,
359381
},
360382
},
361383
{
@@ -384,7 +406,7 @@ func TestClient_Delete(t *testing.T) {
384406
DBRPsApi.EXPECT().DeleteDBRPIDExecute(gomock.Any()).Return(nil)
385407
},
386408
outLines: []string{
387-
`123\s+someDB\s+456\s+someRP\s+false\s+false\s+1234123412341234`,
409+
`123\s+someDB\s+456\s+someRP\s+false\s+1234123412341234`,
388410
},
389411
},
390412
{
@@ -453,7 +475,7 @@ func TestClient_Delete(t *testing.T) {
453475
require.Equal(t, tc.expectedError, err)
454476

455477
if tc.expectedError == nil {
456-
testutils.MatchLines(t, append([]string{`ID\s+Database\s+Bucket\s+ID\s+Retention Policy\s+Default\s+Virtual\s+Organization ID`}, tc.outLines...), strings.Split(stdout.String(), "\n"))
478+
testutils.MatchLines(t, append([]string{`ID\s+Database\s+Bucket\s+ID\s+Retention Policy\s+Default\s+Organization ID`}, tc.outLines...), strings.Split(stdout.String(), "\n"))
457479
}
458480
})
459481
}

cmd/influx/v1_dbrp.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ func newV1DBRPListCmd() cli.Command {
2525
flags := append(commonFlags(), getOrgFlags(&params.OrgParams)...)
2626

2727
return cli.Command{
28-
Name: "list",
29-
Usage: "List database and retention policy mappings",
28+
Name: "list",
29+
Usage: "List database and retention policy mappings",
30+
Description: `List database and retention policy mappings, both standard and virtual.
31+
32+
Virtual DBRP mappings (InfluxDB OSS only) are created automatically using the bucket name.
33+
Virtual mappings are read-only. To modify a virtual DBRP mapping, create a new, explicit DBRP mapping.
34+
For more information, see https://docs.influxdata.com/influxdb/latest/query-data/influxql/dbrp/`,
3035
Aliases: []string{"find", "ls"},
3136
Flags: append(
3237
flags,

0 commit comments

Comments
 (0)