github.com/cs3org/reva/v2@v2.27.7/pkg/share/manager/jsoncs3/sharecache/sharecache_test.go (about)

     1  // Copyright 2018-2022 CERN
     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  // In applying this license, CERN does not waive the privileges and immunities
    16  // granted to it by virtue of its status as an Intergovernmental Organization
    17  // or submit itself to any jurisdiction.
    18  
    19  package sharecache_test
    20  
    21  import (
    22  	"context"
    23  	"os"
    24  	"time"
    25  
    26  	. "github.com/onsi/ginkgo/v2"
    27  	. "github.com/onsi/gomega"
    28  
    29  	"github.com/cs3org/reva/v2/pkg/share/manager/jsoncs3/sharecache"
    30  	"github.com/cs3org/reva/v2/pkg/storage/utils/metadata"
    31  )
    32  
    33  var _ = Describe("Sharecache", func() {
    34  	var (
    35  		c       sharecache.Cache
    36  		storage metadata.Storage
    37  
    38  		userid  = "user"
    39  		shareID = "storageid$spaceid!share1"
    40  		ctx     context.Context
    41  		tmpdir  string
    42  	)
    43  
    44  	BeforeEach(func() {
    45  		ctx = context.Background()
    46  
    47  		var err error
    48  		tmpdir, err = os.MkdirTemp("", "providercache-test")
    49  		Expect(err).ToNot(HaveOccurred())
    50  
    51  		err = os.MkdirAll(tmpdir, 0755)
    52  		Expect(err).ToNot(HaveOccurred())
    53  
    54  		storage, err = metadata.NewDiskStorage(tmpdir)
    55  		Expect(err).ToNot(HaveOccurred())
    56  
    57  		c = sharecache.New(storage, "users", "created.json", 0*time.Second)
    58  		Expect(c).ToNot(BeNil()) //nolint:all
    59  	})
    60  
    61  	AfterEach(func() {
    62  		if tmpdir != "" {
    63  			os.RemoveAll(tmpdir)
    64  		}
    65  	})
    66  
    67  	Describe("Persist", func() {
    68  		Context("with an existing entry", func() {
    69  			BeforeEach(func() {
    70  				Expect(c.Add(ctx, userid, shareID)).To(Succeed())
    71  			})
    72  
    73  			It("updates the etag", func() {
    74  				uc, _ := c.UserShares.Load(userid)
    75  				oldEtag := uc.Etag
    76  				Expect(oldEtag).ToNot(BeEmpty())
    77  
    78  				Expect(c.Persist(ctx, userid)).To(Succeed())
    79  
    80  				uc, _ = c.UserShares.Load(userid)
    81  				Expect(uc.Etag).ToNot(Equal(oldEtag))
    82  			})
    83  		})
    84  	})
    85  })