diff --git a/clients/bucket_schema/client.go b/clients/bucket_schema/client.go index 25f4759..e87b491 100644 --- a/clients/bucket_schema/client.go +++ b/clients/bucket_schema/client.go @@ -40,11 +40,7 @@ func (c Client) resolveMeasurement(ctx context.Context, ids orgBucketID, name st } func (c Client) resolveOrgBucketIds(ctx context.Context, params clients.OrgBucketParams) (*orgBucketID, error) { - if params.OrgID.Valid() && params.BucketID.Valid() { - return &orgBucketID{OrgID: params.OrgID.String(), BucketID: params.BucketID.String()}, nil - } - - if params.BucketName == "" { + if params.BucketName == "" && !params.BucketID.Valid() { return nil, errors.New("bucket missing: specify bucket ID or bucket name") } @@ -52,7 +48,15 @@ func (c Client) resolveOrgBucketIds(ctx context.Context, params clients.OrgBucke return nil, errors.New("org missing: specify org ID or org name") } - req := c.GetBuckets(ctx).Name(params.BucketName) + req := c.GetBuckets(ctx) + var nameID string + if params.BucketID.Valid() { + req = req.Id(params.BucketID.String()) + nameID = params.BucketID.String() + } else { + req = req.Name(params.BucketName) + nameID = params.BucketName + } if params.OrgID.Valid() { req = req.OrgID(params.OrgID.String()) } else if params.OrgName != "" { @@ -63,11 +67,11 @@ func (c Client) resolveOrgBucketIds(ctx context.Context, params clients.OrgBucke resp, err := req.Execute() if err != nil { - return nil, fmt.Errorf("failed to find bucket %q: %w", params.BucketName, err) + return nil, fmt.Errorf("failed to find bucket %q: %w", nameID, err) } buckets := resp.GetBuckets() if len(buckets) == 0 { - return nil, fmt.Errorf("bucket %q not found", params.BucketName) + return nil, fmt.Errorf("bucket %q not found", nameID) } return &orgBucketID{OrgID: buckets[0].GetOrgID(), BucketID: buckets[0].GetId()}, nil diff --git a/clients/bucket_schema/create_test.go b/clients/bucket_schema/create_test.go index 93dc112..5a86391 100644 --- a/clients/bucket_schema/create_test.go +++ b/clients/bucket_schema/create_test.go @@ -3,6 +3,7 @@ package bucket_schema_test import ( "bytes" "context" + "fmt" "os" "path/filepath" "strings" @@ -16,6 +17,7 @@ import ( "github.com/influxdata/influx-cli/v2/clients/bucket_schema" "github.com/influxdata/influx-cli/v2/internal/mock" "github.com/influxdata/influx-cli/v2/internal/testutils" + "github.com/influxdata/influx-cli/v2/pkg/influxid" "github.com/stretchr/testify/assert" tmock "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -25,9 +27,9 @@ func TestClient_Create(t *testing.T) { t.Parallel() var ( - orgID = "dead" - bucketID = "f00d" - measurementID = "1010" + orgID = influxid.MustIDFromString("deadf00dbaadf00d") + bucketID = influxid.MustIDFromString("f00ddeadf00dbaad") + measurementID = influxid.MustIDFromString("1010f00ddeedfeed") createdAt = time.Date(2004, 4, 9, 2, 15, 0, 0, time.UTC) ) @@ -44,7 +46,9 @@ func TestClient_Create(t *testing.T) { type args struct { OrgName string + OrgID influxid.ID BucketName string + BucketID influxid.ID Name string ColumnsFile string ExtendedOutput bool @@ -60,8 +64,8 @@ func TestClient_Create(t *testing.T) { a.params = bucket_schema.CreateParams{ OrgBucketParams: clients.OrgBucketParams{ - OrgParams: clients.OrgParams{OrgName: args.OrgName}, - BucketParams: clients.BucketParams{BucketName: args.BucketName}, + OrgParams: clients.OrgParams{OrgName: args.OrgName, OrgID: args.OrgID}, + BucketParams: clients.BucketParams{BucketName: args.BucketName, BucketID: args.BucketID}, }, Name: args.Name, ColumnsFile: colFile, @@ -77,8 +81,8 @@ func TestClient_Create(t *testing.T) { var buckets []api.Bucket if len(n) == 1 { bucket := api.NewBucket(n[0], nil) - bucket.SetOrgID(orgID) - bucket.SetId(bucketID) + bucket.SetOrgID(orgID.String()) + bucket.SetId(bucketID.String()) bucket.SetName(n[0]) buckets = []api.Bucket{*bucket} } @@ -91,7 +95,11 @@ func TestClient_Create(t *testing.T) { a.buckets.EXPECT(). GetBucketsExecute(tmock.MatchedBy(func(in api.ApiGetBucketsRequest) bool { - return cmp.Equal(in.GetOrg(), &a.params.OrgName) && cmp.Equal(in.GetName(), &a.params.BucketName) + matchOrg := (in.GetOrg() != nil && *in.GetOrg() == a.params.OrgName) || + (in.GetOrgID() != nil && a.params.OrgID.Valid() && *in.GetOrgID() == a.params.OrgID.String()) + matchBucket := (in.GetName() != nil && *in.GetName() == a.params.BucketName) || + (in.GetId() != nil && a.params.BucketID.Valid() && *in.GetId() == a.params.BucketID.String()) + return matchOrg && matchBucket })). Return(api.Buckets{Buckets: &buckets}, nil) } @@ -115,18 +123,19 @@ func TestClient_Create(t *testing.T) { return func(t *testing.T, a *setupArgs) { t.Helper() - req := api.ApiCreateMeasurementSchemaRequest{ApiService: a.schemas}.BucketID(bucketID) + req := api.ApiCreateMeasurementSchemaRequest{ApiService: a.schemas}.BucketID(bucketID.String()) a.schemas.EXPECT(). - CreateMeasurementSchema(gomock.Any(), bucketID). + CreateMeasurementSchema(gomock.Any(), bucketID.String()). Return(req) a.schemas.EXPECT(). CreateMeasurementSchemaExecute(tmock.MatchedBy(func(in api.ApiCreateMeasurementSchemaRequest) bool { - return cmp.Equal(in.GetOrgID(), &orgID) && cmp.Equal(in.GetBucketID(), bucketID) + orgIDPtr := orgID.String() + return cmp.Equal(in.GetOrgID(), &orgIDPtr) && cmp.Equal(in.GetBucketID(), bucketID.String()) })). Return(api.MeasurementSchema{ - Id: measurementID, + Id: measurementID.String(), Name: a.params.Name, Columns: a.cols, CreatedAt: createdAt, @@ -172,7 +181,7 @@ func TestClient_Create(t *testing.T) { expErr: `bucket "my-bucket" not found`, }, { - name: "create succeeds with csv", + name: "create succeeds with csv using org name and bucket name", opts: opts( withArgs(args{OrgName: "my-org", BucketName: "my-bucket", Name: "cpu", ColumnsFile: "columns.csv"}), withCols("columns.csv"), @@ -181,7 +190,46 @@ func TestClient_Create(t *testing.T) { ), expLines: lines( `^ID\s+Measurement Name\s+Bucket ID$`, - `^1010\s+cpu\s+f00d$`, + fmt.Sprintf(`^%s\s+cpu\s+%s`, measurementID, bucketID), + ), + }, + { + name: "create succeeds with csv using org id and bucket name", + opts: opts( + withArgs(args{OrgID: orgID, BucketName: "my-bucket", Name: "cpu", ColumnsFile: "columns.csv"}), + withCols("columns.csv"), + expGetBuckets("my-bucket"), + expCreate(), + ), + expLines: lines( + `^ID\s+Measurement Name\s+Bucket ID$`, + fmt.Sprintf(`^%s\s+cpu\s+%s`, measurementID, bucketID), + ), + }, + { + name: "create succeeds with csv using org name and bucket id", + opts: opts( + withArgs(args{OrgName: "my-org", BucketID: bucketID, Name: "cpu", ColumnsFile: "columns.csv"}), + withCols("columns.csv"), + expGetBuckets("my-bucket"), + expCreate(), + ), + expLines: lines( + `^ID\s+Measurement Name\s+Bucket ID$`, + fmt.Sprintf(`^%s\s+cpu\s+%s`, measurementID, bucketID), + ), + }, + { + name: "create succeeds with csv using org id and bucket id", + opts: opts( + withArgs(args{OrgID: orgID, BucketID: bucketID, Name: "cpu", ColumnsFile: "columns.csv"}), + withCols("columns.csv"), + expGetBuckets("my-bucket"), + expCreate(), + ), + expLines: lines( + `^ID\s+Measurement Name\s+Bucket ID$`, + fmt.Sprintf(`^%s\s+cpu\s+%s`, measurementID, bucketID), ), }, { @@ -194,7 +242,7 @@ func TestClient_Create(t *testing.T) { ), expLines: lines( `^ID\s+Measurement Name\s+Bucket ID$`, - `^1010\s+cpu\s+f00d$`, + fmt.Sprintf(`^%s\s+cpu\s+%s`, measurementID, bucketID), ), }, { @@ -207,7 +255,7 @@ func TestClient_Create(t *testing.T) { ), expLines: lines( `^ID\s+Measurement Name\s+Bucket ID$`, - `^1010\s+cpu\s+f00d$`, + fmt.Sprintf(`^%s\s+cpu\s+%s`, measurementID, bucketID), ), }, { @@ -220,9 +268,9 @@ func TestClient_Create(t *testing.T) { ), expLines: lines( `^ID\s+Measurement Name\s+Column Name\s+Column Type\s+Column Data Type\s+Bucket ID$`, - `^1010\s+cpu\s+time\s+timestamp\s+f00d$`, - `^1010\s+cpu\s+host\s+tag\s+f00d$`, - `^1010\s+cpu\s+usage_user\s+field\s+float\s+f00d$`, + fmt.Sprintf(`^%s\s+cpu\s+time\s+timestamp\s+%s$`, measurementID, bucketID), + fmt.Sprintf(`^%s\s+cpu\s+host\s+tag\s+%s$`, measurementID, bucketID), + fmt.Sprintf(`^%s\s+cpu\s+usage_user\s+field\s+float\s+%s$`, measurementID, bucketID), ), }, } diff --git a/clients/bucket_schema/list_test.go b/clients/bucket_schema/list_test.go index 861870c..5441fc3 100644 --- a/clients/bucket_schema/list_test.go +++ b/clients/bucket_schema/list_test.go @@ -3,6 +3,7 @@ package bucket_schema_test import ( "bytes" "context" + "fmt" "os" "path/filepath" "strings" @@ -15,6 +16,7 @@ import ( "github.com/influxdata/influx-cli/v2/clients/bucket_schema" "github.com/influxdata/influx-cli/v2/internal/mock" "github.com/influxdata/influx-cli/v2/internal/testutils" + "github.com/influxdata/influx-cli/v2/pkg/influxid" "github.com/stretchr/testify/assert" tmock "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -24,9 +26,9 @@ func TestClient_List(t *testing.T) { t.Parallel() var ( - orgID = "dead" - bucketID = "f00d" - measurementID = "1010" + orgID = influxid.MustIDFromString("deadf00dbaadf00d") + bucketID = influxid.MustIDFromString("f00ddeadf00dbaad") + measurementID = influxid.MustIDFromString("1010f00ddeedfeed") createdAt = time.Date(2004, 4, 9, 2, 15, 0, 0, time.UTC) updatedAt = time.Date(2009, 9, 1, 2, 15, 0, 0, time.UTC) ) @@ -44,7 +46,9 @@ func TestClient_List(t *testing.T) { type args struct { OrgName string + OrgID influxid.ID BucketName string + BucketID influxid.ID Name string ExtendedOutput bool } @@ -54,8 +58,8 @@ func TestClient_List(t *testing.T) { t.Helper() a.params = bucket_schema.ListParams{ OrgBucketParams: clients.OrgBucketParams{ - OrgParams: clients.OrgParams{OrgName: args.OrgName}, - BucketParams: clients.BucketParams{BucketName: args.BucketName}, + OrgParams: clients.OrgParams{OrgName: args.OrgName, OrgID: args.OrgID}, + BucketParams: clients.BucketParams{BucketName: args.BucketName, BucketID: args.BucketID}, }, Name: args.Name, ExtendedOutput: args.ExtendedOutput, @@ -70,8 +74,8 @@ func TestClient_List(t *testing.T) { var buckets []api.Bucket if len(n) == 1 { bucket := api.NewBucket(n[0], nil) - bucket.SetOrgID(orgID) - bucket.SetId(bucketID) + bucket.SetOrgID(orgID.String()) + bucket.SetId(bucketID.String()) bucket.SetName(n[0]) buckets = []api.Bucket{*bucket} } @@ -84,8 +88,11 @@ func TestClient_List(t *testing.T) { a.buckets.EXPECT(). GetBucketsExecute(tmock.MatchedBy(func(in api.ApiGetBucketsRequest) bool { - return (in.GetOrg() != nil && *in.GetOrg() == a.params.OrgName) && - (in.GetName() != nil && *in.GetName() == a.params.BucketName) + matchOrg := (in.GetOrg() != nil && *in.GetOrg() == a.params.OrgName) || + (in.GetOrgID() != nil && a.params.OrgID.Valid() && *in.GetOrgID() == a.params.OrgID.String()) + matchBucket := (in.GetName() != nil && *in.GetName() == a.params.BucketName) || + (in.GetId() != nil && a.params.BucketID.Valid() && *in.GetId() == a.params.BucketID.String()) + return matchOrg && matchBucket })). Return(api.Buckets{Buckets: &buckets}, nil) } @@ -109,22 +116,22 @@ func TestClient_List(t *testing.T) { return func(t *testing.T, a *setupArgs) { t.Helper() - req := api.ApiGetMeasurementSchemasRequest{ApiService: a.schemas}.BucketID(bucketID) + req := api.ApiGetMeasurementSchemasRequest{ApiService: a.schemas}.BucketID(bucketID.String()) a.schemas.EXPECT(). - GetMeasurementSchemas(gomock.Any(), bucketID). + GetMeasurementSchemas(gomock.Any(), bucketID.String()). Return(req) a.schemas.EXPECT(). GetMeasurementSchemasExecute(tmock.MatchedBy(func(in api.ApiGetMeasurementSchemasRequest) bool { - return (in.GetOrgID() != nil && *in.GetOrgID() == orgID) && - in.GetBucketID() == bucketID && + return (in.GetOrgID() != nil && *in.GetOrgID() == orgID.String()) && + in.GetBucketID() == bucketID.String() && (in.GetName() != nil && *in.GetName() == a.params.Name) })). Return(api.MeasurementSchemaList{ MeasurementSchemas: []api.MeasurementSchema{ { - Id: measurementID, + Id: measurementID.String(), Name: a.params.Name, Columns: a.cols, CreatedAt: createdAt, @@ -153,7 +160,7 @@ func TestClient_List(t *testing.T) { expErr: "org missing: specify org ID or org name", }, { - name: "bucket arg missing", + name: "bucket args missing", opts: opts( withArgs(args{OrgName: "my-org"}), ), @@ -168,7 +175,15 @@ func TestClient_List(t *testing.T) { expErr: `bucket "my-bucket" not found`, }, { - name: "list succeeds", + name: "bucket not found by id", + opts: opts( + withArgs(args{OrgName: "my-org", BucketID: influxid.MustIDFromString("baadf00d7777deed")}), + expGetBuckets(), + ), + expErr: `bucket "baadf00d7777deed" not found`, + }, + { + name: "list succeeds with org name and bucket name", opts: opts( withArgs(args{OrgName: "my-org", BucketName: "my-bucket", Name: "cpu"}), withCols("columns.csv"), @@ -177,7 +192,46 @@ func TestClient_List(t *testing.T) { ), expLines: lines( `^ID\s+Measurement Name\s+Bucket ID$`, - `^1010\s+cpu\s+f00d$`, + fmt.Sprintf(`^%s\s+cpu\s+%s`, measurementID, bucketID), + ), + }, + { + name: "list succeeds with org id and bucket name", + opts: opts( + withArgs(args{OrgID: orgID, BucketName: "my-bucket", Name: "cpu"}), + withCols("columns.csv"), + expGetBuckets("my-bucket"), + expGetMeasurementSchemas(), + ), + expLines: lines( + `^ID\s+Measurement Name\s+Bucket ID$`, + fmt.Sprintf(`^%s\s+cpu\s+%s`, measurementID, bucketID), + ), + }, + { + name: "list succeeds with org name and bucket id", + opts: opts( + withArgs(args{OrgName: "my-org", BucketID: bucketID, Name: "cpu"}), + withCols("columns.csv"), + expGetBuckets("my-bucket"), + expGetMeasurementSchemas(), + ), + expLines: lines( + `^ID\s+Measurement Name\s+Bucket ID$`, + fmt.Sprintf(`^%s\s+cpu\s+%s`, measurementID, bucketID), + ), + }, + { + name: "list succeeds with org id and bucket id", + opts: opts( + withArgs(args{OrgID: orgID, BucketID: bucketID, Name: "cpu"}), + withCols("columns.csv"), + expGetBuckets("my-bucket"), + expGetMeasurementSchemas(), + ), + expLines: lines( + `^ID\s+Measurement Name\s+Bucket ID$`, + fmt.Sprintf(`^%s\s+cpu\s+%s`, measurementID, bucketID), ), }, { @@ -190,9 +244,9 @@ func TestClient_List(t *testing.T) { ), expLines: lines( `^ID\s+Measurement Name\s+Column Name\s+Column Type\s+Column Data Type\s+Bucket ID$`, - `^1010\s+cpu\s+time\s+timestamp\s+f00d$`, - `^1010\s+cpu\s+host\s+tag\s+f00d$`, - `^1010\s+cpu\s+usage_user\s+field\s+float\s+f00d$`, + fmt.Sprintf(`^%s\s+cpu\s+time\s+timestamp\s+%s`, measurementID, bucketID), + fmt.Sprintf(`^%s\s+cpu\s+host\s+tag\s+%s`, measurementID, bucketID), + fmt.Sprintf(`^%s\s+cpu\s+usage_user\s+field\s+float\s+%s`, measurementID, bucketID), ), }, } diff --git a/clients/bucket_schema/update_test.go b/clients/bucket_schema/update_test.go index b27eee9..42de6f2 100644 --- a/clients/bucket_schema/update_test.go +++ b/clients/bucket_schema/update_test.go @@ -3,6 +3,7 @@ package bucket_schema_test import ( "bytes" "context" + "fmt" "os" "path/filepath" "strings" @@ -16,6 +17,7 @@ import ( "github.com/influxdata/influx-cli/v2/clients/bucket_schema" "github.com/influxdata/influx-cli/v2/internal/mock" "github.com/influxdata/influx-cli/v2/internal/testutils" + "github.com/influxdata/influx-cli/v2/pkg/influxid" "github.com/stretchr/testify/assert" tmock "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -25,9 +27,9 @@ func TestClient_Update(t *testing.T) { t.Parallel() var ( - orgID = "dead" - bucketID = "f00d" - measurementID = "1010" + orgID = influxid.MustIDFromString("deadf00dbaadf00d") + bucketID = influxid.MustIDFromString("f00ddeadf00dbaad") + measurementID = influxid.MustIDFromString("1010f00ddeedfeed") createdAt = time.Date(2004, 4, 9, 2, 15, 0, 0, time.UTC) updatedAt = time.Date(2009, 9, 1, 2, 15, 0, 0, time.UTC) ) @@ -45,7 +47,9 @@ func TestClient_Update(t *testing.T) { type args struct { OrgName string + OrgID influxid.ID BucketName string + BucketID influxid.ID Name string ColumnsFile string ExtendedOutput bool @@ -61,8 +65,8 @@ func TestClient_Update(t *testing.T) { a.params = bucket_schema.UpdateParams{ OrgBucketParams: clients.OrgBucketParams{ - OrgParams: clients.OrgParams{OrgName: args.OrgName}, - BucketParams: clients.BucketParams{BucketName: args.BucketName}, + OrgParams: clients.OrgParams{OrgName: args.OrgName, OrgID: args.OrgID}, + BucketParams: clients.BucketParams{BucketName: args.BucketName, BucketID: args.BucketID}, }, Name: args.Name, ColumnsFile: colFile, @@ -78,8 +82,8 @@ func TestClient_Update(t *testing.T) { var buckets []api.Bucket if len(n) == 1 { bucket := api.NewBucket(n[0], nil) - bucket.SetOrgID(orgID) - bucket.SetId(bucketID) + bucket.SetOrgID(orgID.String()) + bucket.SetId(bucketID.String()) bucket.SetName(n[0]) buckets = []api.Bucket{*bucket} } @@ -92,8 +96,11 @@ func TestClient_Update(t *testing.T) { a.buckets.EXPECT(). GetBucketsExecute(tmock.MatchedBy(func(in api.ApiGetBucketsRequest) bool { - return (in.GetOrg() != nil && *in.GetOrg() == a.params.OrgName) && - (in.GetName() != nil && *in.GetName() == a.params.BucketName) + matchOrg := (in.GetOrg() != nil && *in.GetOrg() == a.params.OrgName) || + (in.GetOrgID() != nil && a.params.OrgID.Valid() && *in.GetOrgID() == a.params.OrgID.String()) + matchBucket := (in.GetName() != nil && *in.GetName() == a.params.BucketName) || + (in.GetId() != nil && a.params.BucketID.Valid() && *in.GetId() == a.params.BucketID.String()) + return matchOrg && matchBucket })). Return(api.Buckets{Buckets: &buckets}, nil) } @@ -117,22 +124,22 @@ func TestClient_Update(t *testing.T) { return func(t *testing.T, a *setupArgs) { t.Helper() - req := api.ApiGetMeasurementSchemasRequest{ApiService: a.schemas}.BucketID(bucketID) + req := api.ApiGetMeasurementSchemasRequest{ApiService: a.schemas}.BucketID(bucketID.String()) a.schemas.EXPECT(). - GetMeasurementSchemas(gomock.Any(), bucketID). + GetMeasurementSchemas(gomock.Any(), bucketID.String()). Return(req) a.schemas.EXPECT(). GetMeasurementSchemasExecute(tmock.MatchedBy(func(in api.ApiGetMeasurementSchemasRequest) bool { - return (in.GetOrgID() != nil && *in.GetOrgID() == orgID) && - in.GetBucketID() == bucketID && + return (in.GetOrgID() != nil && *in.GetOrgID() == orgID.String()) && + in.GetBucketID() == bucketID.String() && (in.GetName() != nil && *in.GetName() == a.params.Name) })). Return(api.MeasurementSchemaList{ MeasurementSchemas: []api.MeasurementSchema{ { - Id: measurementID, + Id: measurementID.String(), Name: a.params.Name, Columns: a.cols, CreatedAt: createdAt, @@ -147,21 +154,22 @@ func TestClient_Update(t *testing.T) { return func(t *testing.T, a *setupArgs) { t.Helper() - req := api.ApiUpdateMeasurementSchemaRequest{ApiService: a.schemas}.BucketID(bucketID).MeasurementID(measurementID) + req := api.ApiUpdateMeasurementSchemaRequest{ApiService: a.schemas}.BucketID(bucketID.String()).MeasurementID(measurementID.String()) a.schemas.EXPECT(). - UpdateMeasurementSchema(gomock.Any(), bucketID, measurementID). + UpdateMeasurementSchema(gomock.Any(), bucketID.String(), measurementID.String()). Return(req) a.schemas.EXPECT(). UpdateMeasurementSchemaExecute(tmock.MatchedBy(func(in api.ApiUpdateMeasurementSchemaRequest) bool { - return cmp.Equal(in.GetOrgID(), &orgID) && - cmp.Equal(in.GetBucketID(), bucketID) && - cmp.Equal(in.GetMeasurementID(), measurementID) && + orgIDPtr := orgID.String() + return cmp.Equal(in.GetOrgID(), &orgIDPtr) && + cmp.Equal(in.GetBucketID(), bucketID.String()) && + cmp.Equal(in.GetMeasurementID(), measurementID.String()) && cmp.Equal(in.GetMeasurementSchemaUpdateRequest().Columns, a.cols) })). Return(api.MeasurementSchema{ - Id: measurementID, + Id: measurementID.String(), Name: a.params.Name, Columns: a.cols, CreatedAt: createdAt, @@ -207,7 +215,7 @@ func TestClient_Update(t *testing.T) { expErr: `bucket "my-bucket" not found`, }, { - name: "update succeeds", + name: "update succeeds with org name and bucket name", opts: opts( withArgs(args{OrgName: "my-org", BucketName: "my-bucket", Name: "cpu", ColumnsFile: "columns.csv"}), withCols("columns.csv"), @@ -218,7 +226,52 @@ func TestClient_Update(t *testing.T) { ), expLines: lines( `^ID\s+Measurement Name\s+Bucket ID$`, - `^1010\s+cpu\s+f00d$`, + fmt.Sprintf(`^%s\s+cpu\s+%s$`, measurementID, bucketID), + ), + }, + { + name: "update succeeds with org id and bucket name", + opts: opts( + withArgs(args{OrgID: orgID, BucketName: "my-bucket", Name: "cpu", ColumnsFile: "columns.csv"}), + withCols("columns.csv"), + + expGetBuckets("my-bucket"), + expGetMeasurementSchema(), + expUpdate(), + ), + expLines: lines( + `^ID\s+Measurement Name\s+Bucket ID$`, + fmt.Sprintf(`^%s\s+cpu\s+%s$`, measurementID, bucketID), + ), + }, + { + name: "update succeeds with org id and bucket id", + opts: opts( + withArgs(args{OrgID: orgID, BucketID: bucketID, Name: "cpu", ColumnsFile: "columns.csv"}), + withCols("columns.csv"), + + expGetBuckets("my-bucket"), + expGetMeasurementSchema(), + expUpdate(), + ), + expLines: lines( + `^ID\s+Measurement Name\s+Bucket ID$`, + fmt.Sprintf(`^%s\s+cpu\s+%s$`, measurementID, bucketID), + ), + }, + { + name: "update succeeds with org name and bucket id", + opts: opts( + withArgs(args{OrgName: "my-org", BucketID: bucketID, Name: "cpu", ColumnsFile: "columns.csv"}), + withCols("columns.csv"), + + expGetBuckets("my-bucket"), + expGetMeasurementSchema(), + expUpdate(), + ), + expLines: lines( + `^ID\s+Measurement Name\s+Bucket ID$`, + fmt.Sprintf(`^%s\s+cpu\s+%s$`, measurementID, bucketID), ), }, { @@ -232,9 +285,9 @@ func TestClient_Update(t *testing.T) { ), expLines: lines( `^ID\s+Measurement Name\s+Column Name\s+Column Type\s+Column Data Type\s+Bucket ID$`, - `^1010\s+cpu\s+time\s+timestamp\s+f00d$`, - `^1010\s+cpu\s+host\s+tag\s+f00d$`, - `^1010\s+cpu\s+usage_user\s+field\s+float\s+f00d$`, + fmt.Sprintf(`^%s\s+cpu\s+time\s+timestamp\s+%s$`, measurementID, bucketID), + fmt.Sprintf(`^%s\s+cpu\s+host\s+tag\s+%s$`, measurementID, bucketID), + fmt.Sprintf(`^%s\s+cpu\s+usage_user\s+field\s+float\s+%s$`, measurementID, bucketID), ), }, }