...

Source file src/cloud.google.com/go/bigquery/iam_test.go

Documentation: cloud.google.com/go/bigquery

     1  // Copyright 2020 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package bigquery
    16  
    17  import (
    18  	"testing"
    19  
    20  	"cloud.google.com/go/iam/apiv1/iampb"
    21  	"cloud.google.com/go/internal/testutil"
    22  	bq "google.golang.org/api/bigquery/v2"
    23  )
    24  
    25  func TestPolicyConversions(t *testing.T) {
    26  
    27  	for _, test := range []struct {
    28  		bq  *bq.Policy
    29  		iam *iampb.Policy
    30  	}{
    31  		{&bq.Policy{}, &iampb.Policy{}},
    32  		{
    33  			&bq.Policy{
    34  				Bindings: []*bq.Binding{
    35  					{
    36  						Role:    "foo",
    37  						Members: []string{"a", "b", "c"},
    38  					},
    39  				},
    40  				Etag:    "etag",
    41  				Version: 1,
    42  			},
    43  			&iampb.Policy{
    44  				Bindings: []*iampb.Binding{
    45  					{
    46  						Role:    "foo",
    47  						Members: []string{"a", "b", "c"},
    48  					},
    49  				},
    50  				Etag:    []byte("etag"),
    51  				Version: 1,
    52  			},
    53  		},
    54  	} {
    55  		gotIAM := iamFromBigQueryPolicy(test.bq)
    56  		if diff := testutil.Diff(gotIAM, test.iam); diff != "" {
    57  			t.Errorf("%+v:\n, -got, +want:\n%s", test.iam, diff)
    58  		}
    59  
    60  		gotBQ := iamToBigQueryPolicy(test.iam)
    61  		if diff := testutil.Diff(gotBQ, test.bq); diff != "" {
    62  			t.Errorf("%+v:\n, -got, +want:\n%s", test.iam, diff)
    63  		}
    64  	}
    65  }
    66  

View as plain text