aboutsummaryrefslogtreecommitdiff
path: root/pkg/api/api0/api0testutil
diff options
context:
space:
mode:
authorpg9182 <96569817+pg9182@users.noreply.github.com>2022-10-13 01:32:20 -0400
committerpg9182 <96569817+pg9182@users.noreply.github.com>2022-10-13 01:32:20 -0400
commitf9612dfa1e203550a097f40bb738ddc8a74cc239 (patch)
treed0e09dabf2a5b1a6a2d1ab2759c6af781a1f86e7 /pkg/api/api0/api0testutil
parent79375cc9de2a848b8f594de890f3bef806d154bf (diff)
downloadAtlas-f9612dfa1e203550a097f40bb738ddc8a74cc239.tar.gz
Atlas-f9612dfa1e203550a097f40bb738ddc8a74cc239.zip
pkg/{api/api0/*,storage/*}: Add GetPdataHash method for pdata storage
Diffstat (limited to 'pkg/api/api0/api0testutil')
-rw-r--r--pkg/api/api0/api0testutil/storage.go58
1 files changed, 53 insertions, 5 deletions
diff --git a/pkg/api/api0/api0testutil/storage.go b/pkg/api/api0/api0testutil/storage.go
index f88c27c..be3bd4a 100644
--- a/pkg/api/api0/api0testutil/storage.go
+++ b/pkg/api/api0/api0testutil/storage.go
@@ -25,6 +25,18 @@ func TestPdataStorage(t *testing.T, s api0.PdataStorage) {
pdata1SHA := sha256.Sum256(pdata1)
pdata2SHA := sha256.Sum256(pdata2)
+ t.Run("HashForNonexistentUser1", func(t *testing.T) {
+ hash, exists, err := s.GetPdataHash(user1)
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if exists {
+ t.Fatalf("exists should be false")
+ }
+ if hash != zeroSHA {
+ t.Fatalf("should not return hash")
+ }
+ })
t.Run("GetForNonexistentUser1", func(t *testing.T) {
for _, tc := range []struct {
Name string
@@ -52,6 +64,18 @@ func TestPdataStorage(t *testing.T, s api0.PdataStorage) {
t.Fatalf("unexpected error: %v", err)
}
})
+ t.Run("HashForExistingUser1Pdata1", func(t *testing.T) {
+ hash, exists, err := s.GetPdataHash(user1)
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if !exists {
+ t.Fatalf("exists should be true")
+ }
+ if hash != pdata1SHA {
+ t.Fatalf("should return correct hash")
+ }
+ })
t.Run("GetForExistingUser1", func(t *testing.T) {
for _, tc := range []struct {
Name string
@@ -92,6 +116,18 @@ func TestPdataStorage(t *testing.T, s api0.PdataStorage) {
t.Fatalf("unexpected error: %v", err)
}
})
+ t.Run("HashForExistingUser1Pdata2", func(t *testing.T) {
+ hash, exists, err := s.GetPdataHash(user1)
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if !exists {
+ t.Fatalf("exists should be true")
+ }
+ if hash != pdata2SHA {
+ t.Fatalf("should return correct hash")
+ }
+ })
t.Run("GetForExistingUser2", func(t *testing.T) {
for _, tc := range []struct {
Name string
@@ -170,36 +206,48 @@ func TestPdataStorage(t *testing.T, s api0.PdataStorage) {
}
randSched()
- if buf, exists, err := s.GetPdataCached(uid, data1sha); err != nil || !exists || buf != nil {
+ if hash, exists, err := s.GetPdataHash(uid); err != nil || !exists || hash != data1sha {
fail.Store(4)
return
}
randSched()
- if buf, exists, err := s.GetPdataCached(uid, data2sha); err != nil || !exists || !bytes.Equal(buf, data1) {
+ if buf, exists, err := s.GetPdataCached(uid, data1sha); err != nil || !exists || buf != nil {
fail.Store(5)
return
}
randSched()
- if err := s.SetPdata(uid, data2); err != nil {
+ if buf, exists, err := s.GetPdataCached(uid, data2sha); err != nil || !exists || !bytes.Equal(buf, data1) {
fail.Store(6)
return
}
randSched()
- if buf, exists, err := s.GetPdataCached(uid, data2sha); err != nil || !exists || buf != nil {
+ if err := s.SetPdata(uid, data2); err != nil {
fail.Store(7)
return
}
randSched()
- if buf, exists, err := s.GetPdataCached(uid, data1sha); err != nil || !exists || !bytes.Equal(buf, data2) {
+ if hash, exists, err := s.GetPdataHash(uid); err != nil || !exists || hash != data2sha {
fail.Store(8)
return
}
randSched()
+ if buf, exists, err := s.GetPdataCached(uid, data2sha); err != nil || !exists || buf != nil {
+ fail.Store(9)
+ return
+ }
+ randSched()
+
+ if buf, exists, err := s.GetPdataCached(uid, data1sha); err != nil || !exists || !bytes.Equal(buf, data2) {
+ fail.Store(10)
+ return
+ }
+ randSched()
+
}(uid)
}
if wg.Wait(); fail.Load() != 0 {