Skip to content

Commit

Permalink
Merge pull request #241 from ipfs-search/redis_tz_fixups
Browse files Browse the repository at this point in the history
Fixups for timezone mismatch in CI.
  • Loading branch information
dokterbob committed Oct 25, 2022
2 parents d211ca6 + 2ee2d2f commit a17ac09
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
19 changes: 9 additions & 10 deletions components/index/redis/exitsindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ExistsIndexTestSuite struct {
suite.Suite
ctx context.Context
instr *instr.Instrumentation
now *time.Time

i *ExistsIndex
}
Expand Down Expand Up @@ -48,6 +49,8 @@ func (s *ExistsIndexTestSuite) stubIndex(fn stubFunc) *Index {

func (s *ExistsIndexTestSuite) SetupTest() {
s.ctx = context.Background()
now := time.Now().Truncate(time.Second).UTC()
s.now = &now
}

func (s *ExistsIndexTestSuite) TestGetKey() {
Expand All @@ -60,18 +63,17 @@ func (s *ExistsIndexTestSuite) TestGetKey() {
}

func (s *ExistsIndexTestSuite) TestSetLastSeenOnly() {
now := time.Now().Truncate(time.Second)
i := s.stubIndex(func(_ context.Context, args []string) interface{} {
s.Len(args, 4)
s.Equal("HSET", args[0])
// We test key generation elsewhere, ignore args[1]
s.Equal("l", args[2]) // Use the `redis` tag.
s.Equal(now.Format(time.RFC3339), args[3])
s.Equal(s.now.Format(time.RFC3339), args[3])

return nil
})
u := &types.Update{
LastSeen: &now,
LastSeen: s.now,
}

err := i.set(s.ctx, testId, u)
Expand Down Expand Up @@ -130,8 +132,6 @@ func (s *ExistsIndexTestSuite) TestSetReferencesOnly() {
// }

func (s *ExistsIndexTestSuite) TestSetAll() {
now := time.Now().Truncate(time.Second)

r1 := types.Reference{
ParentHash: "p1",
Name: "f1",
Expand All @@ -140,7 +140,7 @@ func (s *ExistsIndexTestSuite) TestSetAll() {
r1,
}
u := &types.Update{
LastSeen: &now,
LastSeen: s.now,
References: r,
}

Expand All @@ -150,7 +150,7 @@ func (s *ExistsIndexTestSuite) TestSetAll() {
// We test key generation elsewhere, ignore args[1]

s.Equal("l", args[2]) // Use the `redis` tag.
s.Equal(now.Format(time.RFC3339), args[3])
s.Equal(s.now.Format(time.RFC3339), args[3])

s.Equal("r", args[4]) // Use the `redis` tag.

Expand Down Expand Up @@ -192,8 +192,7 @@ func (s *ExistsIndexTestSuite) TestDelete() {
}

func (s *ExistsIndexTestSuite) TestGetFound() {
now := time.Now().Truncate(time.Second)
nBytes, _ := now.MarshalText()
nBytes, _ := s.now.MarshalText()

r1 := types.Reference{
ParentHash: "p1",
Expand All @@ -205,7 +204,7 @@ func (s *ExistsIndexTestSuite) TestGetFound() {
rBytes, _ := r.MarshalBinary()

u := &types.Update{
LastSeen: &now,
LastSeen: s.now,
References: r,
}

Expand Down
21 changes: 9 additions & 12 deletions components/index/redis/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type RedisTestSuite struct {
suite.Suite
ctx context.Context
instr *instr.Instrumentation
now *time.Time

i *Index
}
Expand Down Expand Up @@ -54,6 +55,8 @@ func (s *RedisTestSuite) stubIndex(fn stubFunc) *Index {

func (s *RedisTestSuite) SetupTest() {
s.ctx = context.Background()
now := time.Now().Truncate(time.Second).UTC()
s.now = &now
}

func (s *RedisTestSuite) TestGetKey() {
Expand All @@ -66,18 +69,17 @@ func (s *RedisTestSuite) TestGetKey() {
}

func (s *RedisTestSuite) TestSetLastSeenOnly() {
now := time.Now().Truncate(time.Second)
i := s.stubIndex(func(_ context.Context, args []string) interface{} {
s.Len(args, 4)
s.Equal("HSET", args[0])
// We test key generation elsewhere, ignore args[1]
s.Equal("l", args[2]) // Use the `redis` tag.
s.Equal(now.Format(time.RFC3339), args[3])
s.Equal(s.now.Format(time.RFC3339), args[3])

return nil
})
u := &types.Update{
LastSeen: &now,
LastSeen: s.now,
}

err := i.set(s.ctx, testId, u)
Expand Down Expand Up @@ -136,8 +138,6 @@ func (s *RedisTestSuite) TestSetReferencesOnly() {
// }

func (s *RedisTestSuite) TestSetAll() {
now := time.Now().Truncate(time.Second)

r1 := types.Reference{
ParentHash: "p1",
Name: "f1",
Expand All @@ -146,7 +146,7 @@ func (s *RedisTestSuite) TestSetAll() {
r1,
}
u := &types.Update{
LastSeen: &now,
LastSeen: s.now,
References: r,
}

Expand All @@ -156,7 +156,7 @@ func (s *RedisTestSuite) TestSetAll() {
// We test key generation elsewhere, ignore args[1]

s.Equal("l", args[2]) // Use the `redis` tag.
s.Equal(now.Format(time.RFC3339), args[3])
s.Equal(s.now.Format(time.RFC3339), args[3])

s.Equal("r", args[4]) // Use the `redis` tag.

Expand Down Expand Up @@ -198,8 +198,7 @@ func (s *RedisTestSuite) TestDelete() {
}

func (s *RedisTestSuite) TestGetFound() {
now := time.Now().Truncate(time.Second)
nBytes, _ := now.MarshalText()
nBytes, _ := s.now.MarshalText()

r1 := types.Reference{
ParentHash: "p1",
Expand All @@ -211,16 +210,14 @@ func (s *RedisTestSuite) TestGetFound() {
rBytes, _ := r.MarshalBinary()

u := &types.Update{
LastSeen: &now,
LastSeen: s.now,
References: r,
}

i := s.stubIndex(func(_ context.Context, args []string) interface{} {
s.Len(args, 2)
s.Equal("HGETALL", args[0])

// return []string{"l", string(nBytes)}

return [][]byte{
{'l'}, nBytes,
{'r'}, rBytes,
Expand Down

0 comments on commit a17ac09

Please sign in to comment.