@@ -20,25 +20,13 @@ import (
2020 "testing"
2121 "time"
2222
23+ "github.com/google/go-cmp/cmp"
2324 "github.com/stretchr/testify/assert"
2425
2526 "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datalayer"
2627)
2728
28- func TestNewMetrics (t * testing.T ) {
29- m := datalayer .NewMetrics ()
30- assert .NotNil (t , m )
31- assert .NotNil (t , m .ActiveModels )
32- assert .NotNil (t , m .WaitingModels )
33-
34- assert .Zero (t , m .MaxActiveModels )
35- assert .Zero (t , m .KVCacheUsagePercent )
36- assert .True (t , m .UpdateTime .IsZero ())
37- }
38-
3929func TestMetricsClone (t * testing.T ) {
40- now := time .Now ()
41-
4230 m := & datalayer.Metrics {
4331 ActiveModels : map [string ]int {"modelA" : 1 },
4432 WaitingModels : map [string ]int {"modelB" : 2 },
@@ -47,25 +35,19 @@ func TestMetricsClone(t *testing.T) {
4735 WaitingQueueSize : 7 ,
4836 KVCacheUsagePercent : 42.5 ,
4937 KvCacheMaxTokenCapacity : 2048 ,
50- UpdateTime : now ,
38+ UpdateTime : time . Now () ,
5139 }
5240
5341 clone := m .Clone ()
5442
5543 assert .NotNil (t , clone )
56- assert .Equal (t , m .ActiveModels , clone .ActiveModels )
57- assert .Equal (t , m .WaitingModels , clone .WaitingModels )
58- assert .Equal (t , m .MaxActiveModels , clone .MaxActiveModels )
59- assert .Equal (t , m .RunningQueueSize , clone .RunningQueueSize )
60- assert .Equal (t , m .WaitingQueueSize , clone .WaitingQueueSize )
61- assert .Equal (t , m .KVCacheUsagePercent , clone .KVCacheUsagePercent )
62- assert .Equal (t , m .KvCacheMaxTokenCapacity , clone .KvCacheMaxTokenCapacity )
63- assert .True (t , m .UpdateTime .Equal (clone .UpdateTime ), "UpdateTime should be equal" )
44+ if diff := cmp .Diff (m , clone ); diff != "" {
45+ t .Errorf ("Unexpected output (-want +got): %v" , diff )
46+ }
6447
6548 // ensure maps are cloned and not sharing pointers
6649 clone .ActiveModels ["modelA" ] = 42
6750 assert .Equal (t , 1 , m .ActiveModels ["modelA" ], "mutating clone should not affect original" )
68-
6951 clone .WaitingModels ["modelB" ] = 99
7052 assert .Equal (t , 2 , m .WaitingModels ["modelB" ], "mutating clone should not affect original" )
7153}
0 commit comments