go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/gae/service/datastore/meta/eg_test.go (about)

     1  // Copyright 2015 The LUCI Authors.
     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 meta
    16  
    17  import (
    18  	"context"
    19  	"errors"
    20  	"testing"
    21  
    22  	"go.chromium.org/luci/gae/filter/featureBreaker"
    23  	"go.chromium.org/luci/gae/impl/memory"
    24  	ds "go.chromium.org/luci/gae/service/datastore"
    25  
    26  	. "github.com/smartystreets/goconvey/convey"
    27  )
    28  
    29  func TestGetEntityGroupVersion(t *testing.T) {
    30  	t.Parallel()
    31  
    32  	Convey("GetEntityGroupVersion", t, func() {
    33  		c := memory.Use(context.Background())
    34  		c, fb := featureBreaker.FilterRDS(c, errors.New("INTERNAL_ERROR"))
    35  
    36  		pm := ds.PropertyMap{
    37  			"$key": ds.MkPropertyNI(ds.MakeKey(c, "A", "")),
    38  			"Val":  ds.MkProperty(10),
    39  		}
    40  		So(ds.Put(c, pm), ShouldBeNil)
    41  		aKey := ds.KeyForObj(c, pm)
    42  		So(aKey, ShouldNotBeNil)
    43  
    44  		v, err := GetEntityGroupVersion(c, aKey)
    45  		So(err, ShouldBeNil)
    46  		So(v, ShouldEqual, 1)
    47  
    48  		So(ds.Delete(c, aKey), ShouldBeNil)
    49  
    50  		v, err = GetEntityGroupVersion(c, ds.NewKey(c, "madeUp", "thing", 0, aKey))
    51  		So(err, ShouldBeNil)
    52  		So(v, ShouldEqual, 2)
    53  
    54  		v, err = GetEntityGroupVersion(c, ds.NewKey(c, "madeUp", "thing", 0, nil))
    55  		So(err, ShouldBeNil)
    56  		So(v, ShouldEqual, 0)
    57  
    58  		fb.BreakFeatures(nil, "GetMulti")
    59  
    60  		v, err = GetEntityGroupVersion(c, aKey)
    61  		So(err.Error(), ShouldContainSubstring, "INTERNAL_ERROR")
    62  	})
    63  }