Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Jun 26, 2024
1 parent 61b6bcd commit b12bab6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"bytes"
"crypto/sha256"
"encoding/hex"
"encoding/json"
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ type PerModuleMetrics struct {
}

type PerModuleEntry struct {
Checksum Checksum
Metrics PerModuleMetrics
Checksum Checksum
Metrics PerModuleMetrics
}

type PinnedMetrics struct {
Expand Down

0 comments on commit b12bab6

Please sign in to comment.