Skip to content

Commit 749af2e

Browse files
authored
Merge pull request #6 from addityasingh/as-fix-go-report-card
Fix go report card
2 parents e524455 + 5318f85 commit 749af2e

6 files changed

Lines changed: 82 additions & 61 deletions

File tree

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Pickbox Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

pkg/admin/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func TestCommand_Validation(t *testing.T) {
167167
// For now, we just check that the command can be marshaled
168168
_, err := json.Marshal(tt.cmd)
169169
assert.NoError(t, err)
170-
170+
171171
// In a real implementation, we would have a Validate() method
172172
// For now, we just check basic field presence
173173
if tt.valid {

pkg/monitoring/dashboard_test.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import (
1111
// Test Dashboard creation
1212
func TestNewDashboard(t *testing.T) {
1313
logger := logrus.New()
14-
14+
1515
// Create a simple monitor (we'll skip the raft dependency for this test)
1616
monitor := &Monitor{
1717
metrics: NewMetrics("test-node", logger),
1818
logger: logger,
1919
}
20-
20+
2121
dashboard := NewDashboard(monitor, logger)
22-
22+
2323
require.NotNil(t, dashboard)
2424
assert.NotNil(t, dashboard.monitor)
2525
assert.Equal(t, logger, dashboard.logger)
@@ -28,39 +28,39 @@ func TestNewDashboard(t *testing.T) {
2828
// Test Dashboard with nil logger
2929
func TestNewDashboard_NilLogger(t *testing.T) {
3030
logger := logrus.New()
31-
31+
3232
// Create a simple monitor
3333
monitor := &Monitor{
3434
metrics: NewMetrics("test-node", logger),
3535
logger: logger,
3636
}
37-
37+
3838
dashboard := NewDashboard(monitor, nil)
39-
39+
4040
require.NotNil(t, dashboard)
4141
assert.Nil(t, dashboard.logger) // NewDashboard doesn't create default logger
4242
}
4343

4444
// Test Dashboard metrics access
4545
func TestDashboard_MetricsAccess(t *testing.T) {
4646
logger := logrus.New()
47-
47+
4848
// Create monitor with metrics
4949
metrics := NewMetrics("test-node", logger)
5050
metrics.IncrementFilesReplicated()
5151
metrics.AddBytesReplicated(1024)
52-
52+
5353
monitor := &Monitor{
5454
metrics: metrics,
5555
logger: logger,
5656
}
57-
57+
5858
dashboard := NewDashboard(monitor, logger)
59-
59+
6060
// Verify dashboard can access metrics through monitor
6161
assert.NotNil(t, dashboard.monitor)
6262
assert.NotNil(t, dashboard.monitor.metrics)
63-
63+
6464
// Get metrics and verify they contain expected data
6565
nodeMetrics := dashboard.monitor.metrics.GetNodeMetrics()
6666
assert.Equal(t, "test-node", nodeMetrics.NodeID)
@@ -71,17 +71,17 @@ func TestDashboard_MetricsAccess(t *testing.T) {
7171
// Test Dashboard logging with valid logger
7272
func TestDashboard_Logging(t *testing.T) {
7373
logger := logrus.New()
74-
74+
7575
monitor := &Monitor{
7676
metrics: NewMetrics("test-node", logger),
7777
logger: logger,
7878
}
79-
79+
8080
dashboard := NewDashboard(monitor, logger)
81-
81+
8282
// Verify logger is set
8383
assert.Equal(t, logger, dashboard.logger)
84-
84+
8585
// Test that dashboard can log (no errors should occur)
8686
assert.NotPanics(t, func() {
8787
dashboard.logger.Info("Test log message")
@@ -91,14 +91,14 @@ func TestDashboard_Logging(t *testing.T) {
9191
// Test Dashboard structure validation
9292
func TestDashboard_Structure(t *testing.T) {
9393
logger := logrus.New()
94-
94+
9595
monitor := &Monitor{
9696
metrics: NewMetrics("test-node", logger),
9797
logger: logger,
9898
}
99-
99+
100100
dashboard := NewDashboard(monitor, logger)
101-
101+
102102
// Verify dashboard structure
103103
assert.NotNil(t, dashboard)
104104
assert.IsType(t, &Dashboard{}, dashboard)
@@ -109,22 +109,22 @@ func TestDashboard_Structure(t *testing.T) {
109109
// Test Monitor GetMetrics method
110110
func TestDashboard_MonitorGetMetrics(t *testing.T) {
111111
logger := logrus.New()
112-
112+
113113
metrics := NewMetrics("test-node", logger)
114114
metrics.IncrementFilesReplicated()
115-
115+
116116
monitor := &Monitor{
117117
metrics: metrics,
118118
logger: logger,
119119
}
120-
120+
121121
dashboard := NewDashboard(monitor, logger)
122-
122+
123123
// Test that we can get metrics through the monitor
124124
retrievedMetrics := dashboard.monitor.GetMetrics()
125125
assert.NotNil(t, retrievedMetrics)
126126
assert.Equal(t, metrics, retrievedMetrics)
127-
127+
128128
// Verify metrics data
129129
nodeMetrics := retrievedMetrics.GetNodeMetrics()
130130
assert.Equal(t, int64(1), nodeMetrics.FilesReplicated)
@@ -133,7 +133,7 @@ func TestDashboard_MonitorGetMetrics(t *testing.T) {
133133
// Benchmark dashboard creation
134134
func BenchmarkNewDashboard(b *testing.B) {
135135
logger := logrus.New()
136-
136+
137137
monitor := &Monitor{
138138
metrics: NewMetrics("bench-node", logger),
139139
logger: logger,
@@ -148,13 +148,13 @@ func BenchmarkNewDashboard(b *testing.B) {
148148
// Benchmark metrics access through dashboard
149149
func BenchmarkDashboard_MetricsAccess(b *testing.B) {
150150
logger := logrus.New()
151-
151+
152152
metrics := NewMetrics("bench-node", logger)
153153
monitor := &Monitor{
154154
metrics: metrics,
155155
logger: logger,
156156
}
157-
157+
158158
dashboard := NewDashboard(monitor, logger)
159159

160160
b.ResetTimer()

pkg/monitoring/metrics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package monitoring
22

33
import (
4-
"testing"
54
"sync"
5+
"testing"
66
"time"
77

88
"github.com/sirupsen/logrus"

pkg/watcher/hash_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ func TestHashContent(t *testing.T) {
3535
for _, tt := range tests {
3636
t.Run(tt.name, func(t *testing.T) {
3737
result := HashContent(tt.data)
38-
38+
3939
// Verify it's a valid hex string
4040
_, err := hex.DecodeString(result)
4141
assert.NoError(t, err, "Hash should be valid hex")
42-
42+
4343
// Verify it's the correct length for SHA-256 (64 hex characters)
4444
assert.Equal(t, 64, len(result), "SHA-256 hash should be 64 characters")
45-
45+
4646
// Verify consistency - same input should produce same hash
4747
result2 := HashContent(tt.data)
4848
assert.Equal(t, result, result2, "Hash should be consistent")
49-
49+
5050
// For empty content, verify exact hash
5151
if tt.name == "empty_content" {
5252
hasher := sha256.New()
@@ -71,12 +71,12 @@ func TestHashContent_Uniqueness(t *testing.T) {
7171
[]byte("ab"),
7272
[]byte("abc"),
7373
}
74-
74+
7575
hashes := make(map[string][]byte)
76-
76+
7777
for _, data := range testCases {
7878
hash := HashContent(data)
79-
79+
8080
// Check if we've seen this hash before
8181
if existingData, exists := hashes[hash]; exists {
8282
// Only fail if the data is actually different (collision)
@@ -85,21 +85,21 @@ func TestHashContent_Uniqueness(t *testing.T) {
8585
hashes[hash] = data
8686
}
8787
}
88-
88+
8989
// We should have unique hashes for different content
9090
assert.Equal(t, len(testCases), len(hashes), "All different content should have unique hashes")
9191
}
9292

9393
// Test hash stability across multiple calls
9494
func TestHashContent_Stability(t *testing.T) {
9595
testData := []byte("stable test content")
96-
96+
9797
// Generate hash multiple times
9898
hashes := make([]string, 100)
9999
for i := 0; i < 100; i++ {
100100
hashes[i] = HashContent(testData)
101101
}
102-
102+
103103
// All hashes should be identical
104104
firstHash := hashes[0]
105105
for i, hash := range hashes {
@@ -114,15 +114,15 @@ func TestHashContent_LargeContent(t *testing.T) {
114114
for i := range largeData {
115115
largeData[i] = byte(i % 256)
116116
}
117-
117+
118118
hash := HashContent(largeData)
119-
119+
120120
// Verify it's a valid hash
121121
assert.Equal(t, 64, len(hash), "Large content hash should be 64 characters")
122-
122+
123123
_, err := hex.DecodeString(hash)
124124
assert.NoError(t, err, "Large content hash should be valid hex")
125-
125+
126126
// Verify consistency
127127
hash2 := HashContent(largeData)
128128
assert.Equal(t, hash, hash2, "Large content hash should be consistent")
@@ -131,7 +131,7 @@ func TestHashContent_LargeContent(t *testing.T) {
131131
// Benchmark hashing performance
132132
func BenchmarkHashContent_Small(b *testing.B) {
133133
data := []byte("small test content")
134-
134+
135135
b.ResetTimer()
136136
for i := 0; i < b.N; i++ {
137137
HashContent(data)
@@ -144,7 +144,7 @@ func BenchmarkHashContent_Medium(b *testing.B) {
144144
for i := range data {
145145
data[i] = byte(i % 256)
146146
}
147-
147+
148148
b.ResetTimer()
149149
for i := 0; i < b.N; i++ {
150150
HashContent(data)
@@ -157,7 +157,7 @@ func BenchmarkHashContent_Large(b *testing.B) {
157157
for i := range data {
158158
data[i] = byte(i % 256)
159159
}
160-
160+
161161
b.ResetTimer()
162162
for i := 0; i < b.N; i++ {
163163
HashContent(data)

0 commit comments

Comments
 (0)