From b12bab6a5f7176a18e83f9d952d7b199537138bb Mon Sep 17 00:00:00 2001 From: Aumetra Weisman Date: Wed, 26 Jun 2024 12:39:51 +0200 Subject: [PATCH] Fix tests --- internal/api/lib_test.go | 16 +++++++--------- types/types.go | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/internal/api/lib_test.go b/internal/api/lib_test.go index d30509431..d259e8220 100644 --- a/internal/api/lib_test.go +++ b/internal/api/lib_test.go @@ -1,6 +1,7 @@ package api import ( + "bytes" "crypto/sha256" "encoding/hex" "encoding/json" @@ -409,14 +410,11 @@ func TestGetPinnedMetrics(t *testing.T) { err = Pin(cache, cyberpunkChecksum) require.NoError(t, err) - checksumStr := types.Checksum(checksum).String() - cyberpunkChecksumStr := types.Checksum(cyberpunkChecksum).String() - - findMetrics := func(list []types.PerModuleEntry, checksum string) *types.PerModuleMetrics { + findMetrics := func(list []types.PerModuleEntry, checksum types.Checksum) *types.PerModuleMetrics { found := (*types.PerModuleMetrics)(nil) for _, structure := range list { - if structure.Checksum == checksum { + if bytes.Equal(structure.Checksum, checksum) { found = &structure.Metrics break } @@ -430,8 +428,8 @@ func TestGetPinnedMetrics(t *testing.T) { require.NoError(t, err) assert.Equal(t, 2, len(metrics.PerModule)) - hackatomMetrics := findMetrics(metrics.PerModule, checksumStr) - cyberpunkMetrics := findMetrics(metrics.PerModule, cyberpunkChecksumStr) + hackatomMetrics := findMetrics(metrics.PerModule, checksum) + cyberpunkMetrics := findMetrics(metrics.PerModule, cyberpunkChecksum) assert.Equal(t, uint32(0), hackatomMetrics.Hits) assert.NotEqual(t, uint32(0), hackatomMetrics.Size) @@ -455,8 +453,8 @@ func TestGetPinnedMetrics(t *testing.T) { require.NoError(t, err) assert.Equal(t, 2, len(metrics.PerModule)) - hackatomMetrics = findMetrics(metrics.PerModule, checksumStr) - cyberpunkMetrics = findMetrics(metrics.PerModule, cyberpunkChecksumStr) + hackatomMetrics = findMetrics(metrics.PerModule, checksum) + cyberpunkMetrics = findMetrics(metrics.PerModule, cyberpunkChecksum) assert.Equal(t, uint32(1), hackatomMetrics.Hits) assert.NotEqual(t, uint32(0), hackatomMetrics.Size) diff --git a/types/types.go b/types/types.go index bf9a54d0d..e33acc1f5 100644 --- a/types/types.go +++ b/types/types.go @@ -197,8 +197,8 @@ type PerModuleMetrics struct { } type PerModuleEntry struct { - Checksum Checksum - Metrics PerModuleMetrics + Checksum Checksum + Metrics PerModuleMetrics } type PinnedMetrics struct {