Browse Source
fix: EC UI template error when viewing shard details (#7955)
fix: EC UI template error when viewing shard details (#7955)
* fix: EC UI template error when viewing shard details Fixed field name mismatch in volume.html where it was using .ShardDetails instead of .Shards. Added a robust type conversion wrapper in templates.go to handle int64 to uint64 conversion for bytesToHumanReadable. Added regression test to ensure future stability. * refactor: improve bytesToHumanReadable and test robustness - Handled more integer types (uint32, int32, uint) in bytesToHumanReadable. - Improved volume_test.go to verify both shards are formatted correctly. * refactor: add bounds checking to bytesToHumanReadable Added checks for negative values in signed integer types to avoid incorrect formatting when converting to uint64. Addressed feedback from coderabbitai.pull/7959/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 274 additions and 164 deletions
-
33weed/server/volume_server_ui/templates.go
-
329weed/server/volume_server_ui/volume.html
-
76weed/server/volume_server_ui/volume_test.go
@ -0,0 +1,76 @@ |
|||
package volume_server_ui |
|||
|
|||
import ( |
|||
"bytes" |
|||
"testing" |
|||
"time" |
|||
|
|||
"github.com/seaweedfs/seaweedfs/weed/stats" |
|||
) |
|||
|
|||
func TestStatusTpl(t *testing.T) { |
|||
args := struct { |
|||
Version string |
|||
Masters []string |
|||
Volumes interface{} |
|||
EcVolumes interface{} |
|||
RemoteVolumes interface{} |
|||
DiskStatuses interface{} |
|||
Stats interface{} |
|||
Counters *stats.ServerStats |
|||
}{ |
|||
Version: "3.59", |
|||
Masters: []string{"localhost:9333"}, |
|||
EcVolumes: []interface{}{ |
|||
struct { |
|||
VolumeId uint32 |
|||
Collection string |
|||
Size uint64 |
|||
Shards []interface{} |
|||
CreatedAt time.Time |
|||
}{ |
|||
VolumeId: 1, |
|||
Collection: "ectest", |
|||
Size: 8 * 1024 * 1024, |
|||
Shards: []interface{}{ |
|||
struct { |
|||
ShardId uint8 |
|||
Size int64 |
|||
}{ |
|||
ShardId: 4, |
|||
Size: 1024 * 1024, |
|||
}, |
|||
struct { |
|||
ShardId uint8 |
|||
Size uint32 |
|||
}{ |
|||
ShardId: 6, |
|||
Size: 1024 * 1024, |
|||
}, |
|||
}, |
|||
CreatedAt: time.Now(), |
|||
}, |
|||
}, |
|||
Counters: stats.NewServerStats(), |
|||
} |
|||
|
|||
var buf bytes.Buffer |
|||
if err := StatusTpl.Execute(&buf, args); err != nil { |
|||
t.Logf("output: %s", buf.String()) |
|||
t.Fatalf("template execution error: %v", err) |
|||
} |
|||
|
|||
if !bytes.Contains(buf.Bytes(), []byte("8.00 MiB")) { |
|||
t.Errorf("output does not contain formatted volume size '8.00 MiB'") |
|||
} |
|||
if bytes.Count(buf.Bytes(), []byte("1.00 MiB")) != 2 { |
|||
t.Errorf("expected two shards of size '1.00 MiB', but they were not found or not formatted correctly") |
|||
} |
|||
|
|||
if !bytes.Contains(buf.Bytes(), []byte("Erasure Coding Shards")) { |
|||
t.Errorf("output does not contain 'Erasure Coding Shards'") |
|||
} |
|||
if !bytes.Contains(buf.Bytes(), []byte("ectest")) { |
|||
t.Errorf("output does not contain 'ectest'") |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue