Skip to content

Commit 859048e

Browse files
authored
feat(bigquery): support authorized datasets (#5666)
* feat(bigquery): support dataset access entries as part of access entries This augments what you can express in a dataset ACL, and can include a dataset with a set of allowed resource types. In short, this allows for simplifying authorized views by allowing an entry that says "all views in this dataset are authorized" vs the current behavior, which requires views to be enumerated individually.
1 parent 10a6bd7 commit 859048e

5 files changed

Lines changed: 139 additions & 26 deletions

File tree

bigquery/dataset.go

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ func (d *Dataset) Metadata(ctx context.Context) (md *DatasetMetadata, err error)
207207
}); err != nil {
208208
return nil, err
209209
}
210-
return bqToDatasetMetadata(ds)
210+
return bqToDatasetMetadata(ds, d.c)
211211
}
212212

213-
func bqToDatasetMetadata(d *bq.Dataset) (*DatasetMetadata, error) {
213+
func bqToDatasetMetadata(d *bq.Dataset, c *Client) (*DatasetMetadata, error) {
214214
dm := &DatasetMetadata{
215215
CreationTime: unixMillisToTime(d.CreationTime),
216216
LastModifiedTime: unixMillisToTime(d.LastModifiedTime),
@@ -224,7 +224,7 @@ func bqToDatasetMetadata(d *bq.Dataset) (*DatasetMetadata, error) {
224224
ETag: d.Etag,
225225
}
226226
for _, a := range d.Access {
227-
e, err := bqToAccessEntry(a, nil)
227+
e, err := bqToAccessEntry(a, c)
228228
if err != nil {
229229
return nil, err
230230
}
@@ -257,7 +257,7 @@ func (d *Dataset) Update(ctx context.Context, dm DatasetMetadataToUpdate, etag s
257257
}); err != nil {
258258
return nil, err
259259
}
260-
return bqToDatasetMetadata(ds2)
260+
return bqToDatasetMetadata(ds2, d.c)
261261
}
262262

263263
func (dm *DatasetMetadataToUpdate) toBQ() (*bq.Dataset, error) {
@@ -658,11 +658,12 @@ func (it *DatasetIterator) fetch(pageSize int, pageToken string) (string, error)
658658

659659
// An AccessEntry describes the permissions that an entity has on a dataset.
660660
type AccessEntry struct {
661-
Role AccessRole // The role of the entity
662-
EntityType EntityType // The type of entity
663-
Entity string // The entity (individual or group) granted access
664-
View *Table // The view granted access (EntityType must be ViewEntity)
665-
Routine *Routine // The routine granted access (only UDF currently supported)
661+
Role AccessRole // The role of the entity
662+
EntityType EntityType // The type of entity
663+
Entity string // The entity (individual or group) granted access
664+
View *Table // The view granted access (EntityType must be ViewEntity)
665+
Routine *Routine // The routine granted access (only UDF currently supported)
666+
Dataset *DatasetAccessEntry // The resources within a dataset granted access.
666667
}
667668

668669
// AccessRole is the level of access to grant to a dataset.
@@ -703,6 +704,9 @@ const (
703704

704705
// RoutineEntity is a BigQuery routine, referencing a User Defined Function (UDF).
705706
RoutineEntity
707+
708+
// DatasetEntity is BigQuery dataset, present in the access list.
709+
DatasetEntity
706710
)
707711

708712
func (e *AccessEntry) toBQ() (*bq.DatasetAccess, error) {
@@ -722,6 +726,8 @@ func (e *AccessEntry) toBQ() (*bq.DatasetAccess, error) {
722726
q.IamMember = e.Entity
723727
case RoutineEntity:
724728
q.Routine = e.Routine.toBQ()
729+
case DatasetEntity:
730+
q.Dataset = e.Dataset.toBQ()
725731
default:
726732
return nil, fmt.Errorf("bigquery: unknown entity type %d", e.EntityType)
727733
}
@@ -752,8 +758,48 @@ func bqToAccessEntry(q *bq.DatasetAccess, c *Client) (*AccessEntry, error) {
752758
case q.Routine != nil:
753759
e.Routine = c.DatasetInProject(q.Routine.ProjectId, q.Routine.DatasetId).Routine(q.Routine.RoutineId)
754760
e.EntityType = RoutineEntity
761+
case q.Dataset != nil:
762+
e.Dataset = bqToDatasetAccessEntry(q.Dataset, c)
763+
e.EntityType = DatasetEntity
755764
default:
756765
return nil, errors.New("bigquery: invalid access value")
757766
}
758767
return e, nil
759768
}
769+
770+
// DatasetAccessEntry is an access entry that refers to resources within
771+
// another dataset.
772+
type DatasetAccessEntry struct {
773+
// The dataset to which this entry applies.
774+
Dataset *Dataset
775+
// The list of target types within the dataset
776+
// to which this entry applies.
777+
//
778+
// Current supported values:
779+
//
780+
// VIEWS - This entry applies to views in the dataset.
781+
TargetTypes []string
782+
}
783+
784+
func (dae *DatasetAccessEntry) toBQ() *bq.DatasetAccessEntry {
785+
if dae == nil {
786+
return nil
787+
}
788+
return &bq.DatasetAccessEntry{
789+
Dataset: &bq.DatasetReference{
790+
ProjectId: dae.Dataset.ProjectID,
791+
DatasetId: dae.Dataset.DatasetID,
792+
},
793+
TargetTypes: dae.TargetTypes,
794+
}
795+
}
796+
797+
func bqToDatasetAccessEntry(entry *bq.DatasetAccessEntry, c *Client) *DatasetAccessEntry {
798+
if entry == nil {
799+
return nil
800+
}
801+
return &DatasetAccessEntry{
802+
Dataset: c.DatasetInProject(entry.Dataset.ProjectId, entry.Dataset.DatasetId),
803+
TargetTypes: entry.TargetTypes,
804+
}
805+
}

bigquery/dataset_test.go

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"cloud.google.com/go/internal/testutil"
2626
"github.com/google/go-cmp/cmp"
27+
"github.com/google/go-cmp/cmp/cmpopts"
2728
bq "google.golang.org/api/bigquery/v2"
2829
itest "google.golang.org/api/iterator/testing"
2930
)
@@ -310,6 +311,7 @@ func TestDatasets(t *testing.T) {
310311
}
311312

312313
func TestDatasetToBQ(t *testing.T) {
314+
testClient := &Client{projectID: "p"}
313315
for _, test := range []struct {
314316
in *DatasetMetadata
315317
want *bq.Dataset
@@ -325,7 +327,16 @@ func TestDatasetToBQ(t *testing.T) {
325327
},
326328
Location: "EU",
327329
Labels: map[string]string{"x": "y"},
328-
Access: []*AccessEntry{{Role: OwnerRole, Entity: "example.com", EntityType: DomainEntity}},
330+
Access: []*AccessEntry{
331+
{Role: OwnerRole, Entity: "example.com", EntityType: DomainEntity},
332+
{
333+
EntityType: DatasetEntity,
334+
Dataset: &DatasetAccessEntry{
335+
Dataset: testClient.Dataset("otherdataset"),
336+
TargetTypes: []string{"VIEWS"},
337+
},
338+
},
339+
},
329340
}, &bq.Dataset{
330341
FriendlyName: "name",
331342
Description: "desc",
@@ -335,15 +346,26 @@ func TestDatasetToBQ(t *testing.T) {
335346
},
336347
Location: "EU",
337348
Labels: map[string]string{"x": "y"},
338-
Access: []*bq.DatasetAccess{{Role: "OWNER", Domain: "example.com"}},
349+
Access: []*bq.DatasetAccess{
350+
{Role: "OWNER", Domain: "example.com"},
351+
{
352+
Dataset: &bq.DatasetAccessEntry{
353+
Dataset: &bq.DatasetReference{
354+
ProjectId: "p",
355+
DatasetId: "otherdataset",
356+
},
357+
TargetTypes: []string{"VIEWS"},
358+
},
359+
},
360+
},
339361
}},
340362
} {
341363
got, err := test.in.toBQ()
342364
if err != nil {
343365
t.Fatal(err)
344366
}
345-
if !testutil.Equal(got, test.want) {
346-
t.Errorf("%v:\ngot %+v\nwant %+v", test.in, got, test.want)
367+
if diff := testutil.Diff(got, test.want, cmp.AllowUnexported(Dataset{})); diff != "" {
368+
t.Errorf("got=-, want=+:\n%s", diff)
347369
}
348370
}
349371

@@ -362,6 +384,7 @@ func TestDatasetToBQ(t *testing.T) {
362384
}
363385

364386
func TestBQToDatasetMetadata(t *testing.T) {
387+
testClient := &Client{projectID: "p"}
365388
cTime := time.Date(2017, 1, 26, 0, 0, 0, 0, time.Local)
366389
cMillis := cTime.UnixNano() / 1e6
367390
mTime := time.Date(2017, 10, 31, 0, 0, 0, 0, time.Local)
@@ -380,6 +403,15 @@ func TestBQToDatasetMetadata(t *testing.T) {
380403
Access: []*bq.DatasetAccess{
381404
{Role: "READER", UserByEmail: "joe@example.com"},
382405
{Role: "WRITER", GroupByEmail: "users@example.com"},
406+
{
407+
Dataset: &bq.DatasetAccessEntry{
408+
Dataset: &bq.DatasetReference{
409+
ProjectId: "p",
410+
DatasetId: "otherdataset",
411+
},
412+
TargetTypes: []string{"VIEWS"},
413+
},
414+
},
383415
},
384416
Etag: "etag",
385417
}
@@ -397,14 +429,21 @@ func TestBQToDatasetMetadata(t *testing.T) {
397429
Access: []*AccessEntry{
398430
{Role: ReaderRole, Entity: "joe@example.com", EntityType: UserEmailEntity},
399431
{Role: WriterRole, Entity: "users@example.com", EntityType: GroupEmailEntity},
432+
{
433+
EntityType: DatasetEntity,
434+
Dataset: &DatasetAccessEntry{
435+
Dataset: testClient.Dataset("otherdataset"),
436+
TargetTypes: []string{"VIEWS"},
437+
},
438+
},
400439
},
401440
ETag: "etag",
402441
}
403-
got, err := bqToDatasetMetadata(q)
442+
got, err := bqToDatasetMetadata(q, client)
404443
if err != nil {
405444
t.Fatal(err)
406445
}
407-
if diff := testutil.Diff(got, want); diff != "" {
446+
if diff := testutil.Diff(got, want, cmpopts.IgnoreUnexported(Dataset{})); diff != "" {
408447
t.Errorf("-got, +want:\n%s", diff)
409448
}
410449
}

bigquery/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ require (
1313
go.opencensus.io v0.23.0
1414
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
1515
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
16-
google.golang.org/api v0.70.0
17-
google.golang.org/genproto v0.0.0-20220303160752-862486edd9cc
16+
google.golang.org/api v0.71.0
17+
google.golang.org/genproto v0.0.0-20220304144024-325a89244dc8
1818
google.golang.org/grpc v1.44.0
1919
google.golang.org/protobuf v1.27.1
2020
)

bigquery/go.sum

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4g
3737
cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ=
3838
cloud.google.com/go/compute v0.1.0/go.mod h1:GAesmwr110a34z04OlxYkATPBEfVhkymfTBXtfbBFow=
3939
cloud.google.com/go/compute v1.2.0/go.mod h1:xlogom/6gr8RJGBe7nT2eGsQYAFUbbv8dbC29qE3Xmw=
40-
cloud.google.com/go/compute v1.3.0 h1:mPL/MzDDYHsh5tHRS9mhmhWlcgClCrCa6ApQCU6wnHI=
4140
cloud.google.com/go/compute v1.3.0/go.mod h1:cCZiE1NHEtai4wiufUhW8I8S1JKkAnhnQJWM7YD99wM=
41+
cloud.google.com/go/compute v1.5.0 h1:b1zWmYuuHz7gO9kDcM/EpHGr06UgsYNRpNJzI2kFiLM=
42+
cloud.google.com/go/compute v1.5.0/go.mod h1:9SMHyhJlzhlkJqrPAc839t2BZFTSk6Jdj6mkzQJeu0M=
4243
cloud.google.com/go/datacatalog v1.3.0 h1:3llKXv7cC1acsWjvWmG0NQQkYVSVgunMSfVk7h6zz8Q=
4344
cloud.google.com/go/datacatalog v1.3.0/go.mod h1:g9svFY6tuR+j+hrTw3J2dNcmI0dzmSiyOzm8kpLq0a0=
4445
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
@@ -278,8 +279,9 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
278279
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
279280
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
280281
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
281-
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
282282
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
283+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
284+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
283285
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
284286
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
285287
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -295,8 +297,9 @@ golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ
295297
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
296298
golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
297299
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
298-
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 h1:RerP+noqYHUQ8CMRcPlC2nvTa4dcBIjegkuWdcUDuqg=
299300
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
301+
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b h1:clP8eMhB30EHdc0bd2Twtq6kgU7yl5ub2cQLSdrv1Dg=
302+
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
300303
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
301304
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
302305
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -360,8 +363,9 @@ golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBc
360363
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
361364
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
362365
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
363-
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
364366
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
367+
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 h1:nhht2DYV/Sn3qOayu8lM+cU1ii9sTLUeBQwQQfUHtrs=
368+
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
365369
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
366370
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
367371
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -468,8 +472,9 @@ google.golang.org/api v0.64.0/go.mod h1:931CdxA8Rm4t6zqTFGSsgwbAEZ2+GMYurbndwSim
468472
google.golang.org/api v0.66.0/go.mod h1:I1dmXYpX7HGwz/ejRxwQp2qj5bFAz93HiCU1C1oYd9M=
469473
google.golang.org/api v0.67.0/go.mod h1:ShHKP8E60yPsKNw/w8w+VYaj9H6buA5UqDp8dhbQZ6g=
470474
google.golang.org/api v0.69.0/go.mod h1:boanBiw+h5c3s+tBPgEzLDRHfFLWV0qXxRHz3ws7C80=
471-
google.golang.org/api v0.70.0 h1:67zQnAE0T2rB0A3CwLSas0K+SbVzSxP+zTLkQLexeiw=
472475
google.golang.org/api v0.70.0/go.mod h1:Bs4ZM2HGifEvXwd50TtW70ovgJffJYw2oRCOFU/SkfA=
476+
google.golang.org/api v0.71.0 h1:SgWof18M8V2NylsX7bL4fM28j+nFdRopHZbdipaaw20=
477+
google.golang.org/api v0.71.0/go.mod h1:4PyU6e6JogV1f9eA4voyrTY2batOLdgZ5qZ5HOCc4j8=
473478
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
474479
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
475480
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
@@ -548,8 +553,8 @@ google.golang.org/genproto v0.0.0-20220211171837-173942840c17/go.mod h1:kGP+zUP2
548553
google.golang.org/genproto v0.0.0-20220216160803-4663080d8bc8/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
549554
google.golang.org/genproto v0.0.0-20220218161850-94dd64e39d7c/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
550555
google.golang.org/genproto v0.0.0-20220222213610-43724f9ea8cf/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
551-
google.golang.org/genproto v0.0.0-20220303160752-862486edd9cc h1:fb/ViRpv3ln/LvbqZtTpoOd1YQDNH12gaGZreoSFovE=
552-
google.golang.org/genproto v0.0.0-20220303160752-862486edd9cc/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
556+
google.golang.org/genproto v0.0.0-20220304144024-325a89244dc8 h1:U9V52f6rAgINH7kT+musA1qF8kWyVOxzF8eYuOVuFwQ=
557+
google.golang.org/genproto v0.0.0-20220304144024-325a89244dc8/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI=
553558
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
554559
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
555560
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=

bigquery/integration_test.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var (
5656
storageClient *storage.Client
5757
policyTagManagerClient *datacatalog.PolicyTagManagerClient
5858
dataset *Dataset
59+
otherDataset *Dataset
5960
schema = Schema{
6061
{Name: "name", Type: StringFieldType},
6162
{Name: "nums", Type: IntegerFieldType, Repeated: true},
@@ -221,13 +222,22 @@ func initTestState(client *Client, t time.Time) func() {
221222
Seed(t.UnixNano())
222223

223224
dataset = client.Dataset(datasetIDs.New())
225+
otherDataset = client.Dataset(datasetIDs.New())
226+
224227
if err := dataset.Create(ctx, nil); err != nil {
225228
log.Fatalf("creating dataset %s: %v", dataset.DatasetID, err)
226229
}
230+
if err := otherDataset.Create(ctx, nil); err != nil {
231+
log.Fatalf("creating other dataset %s: %v", dataset.DatasetID, err)
232+
}
233+
227234
return func() {
228235
if err := dataset.DeleteWithContents(ctx); err != nil {
229236
log.Printf("could not delete %s", dataset.DatasetID)
230237
}
238+
if err := otherDataset.DeleteWithContents(ctx); err != nil {
239+
log.Printf("could not delete %s", dataset.DatasetID)
240+
}
231241
}
232242
}
233243

@@ -955,6 +965,13 @@ func TestIntegration_DatasetUpdateAccess(t *testing.T) {
955965
EntityType: RoutineEntity,
956966
Routine: routine,
957967
},
968+
{
969+
EntityType: DatasetEntity,
970+
Dataset: &DatasetAccessEntry{
971+
Dataset: otherDataset,
972+
TargetTypes: []string{"VIEWS"},
973+
},
974+
},
958975
}
959976

960977
newAccess := append(md.Access, newEntries...)
@@ -970,8 +987,8 @@ func TestIntegration_DatasetUpdateAccess(t *testing.T) {
970987
}
971988
}()
972989

973-
if diff := testutil.Diff(md.Access, newAccess, cmpopts.SortSlices(lessAccessEntries), cmpopts.IgnoreUnexported(Routine{})); diff != "" {
974-
t.Fatalf("got=-, want=+:\n%s", diff)
990+
if diff := testutil.Diff(md.Access, newAccess, cmpopts.SortSlices(lessAccessEntries), cmpopts.IgnoreUnexported(Routine{}, Dataset{})); diff != "" {
991+
t.Errorf("got=-, want=+:\n%s", diff)
975992
}
976993
}
977994

@@ -998,6 +1015,12 @@ func lessAccessEntries(x, y *AccessEntry) bool {
9981015
if x.View == nil {
9991016
return y.View != nil
10001017
}
1018+
if x.Routine == nil {
1019+
return y.Routine == nil
1020+
}
1021+
if x.Dataset == nil {
1022+
return y.Dataset == nil
1023+
}
10011024
return false
10021025
}
10031026

0 commit comments

Comments
 (0)