Skip to content

Commit 9eea5a7

Browse files
committed
strengthen alluxio runtime helpers
Signed-off-by: r0hansaxena <rohansxn8772@gmail.com>
1 parent 9fe6aad commit 9eea5a7

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

api/v1alpha1/alluxioruntime_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,15 @@ func init() {
285285

286286
// Replicas gets the replicas of runtime worker
287287
func (runtime *AlluxioRuntime) Replicas() int32 {
288+
if runtime == nil {
289+
return 0
290+
}
288291
return runtime.Spec.Replicas
289292
}
290293

291294
func (runtime *AlluxioRuntime) GetStatus() *RuntimeStatus {
295+
if runtime == nil {
296+
return &RuntimeStatus{}
297+
}
292298
return &runtime.Status
293299
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
Copyright 2026 The Fluid Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import "testing"
20+
21+
func TestAlluxioRuntime_Replicas(t *testing.T) {
22+
testCases := map[string]struct {
23+
runtime *AlluxioRuntime
24+
want int32
25+
}{
26+
"nil runtime defaults to zero": {
27+
runtime: nil,
28+
want: 0,
29+
},
30+
"returns configured replicas": {
31+
runtime: &AlluxioRuntime{
32+
Spec: AlluxioRuntimeSpec{
33+
Replicas: 3,
34+
},
35+
},
36+
want: 3,
37+
},
38+
"returns zero replicas when not configured": {
39+
runtime: &AlluxioRuntime{},
40+
want: 0,
41+
},
42+
}
43+
44+
for name, tc := range testCases {
45+
t.Run(name, func(t *testing.T) {
46+
got := tc.runtime.Replicas()
47+
if got != tc.want {
48+
t.Fatalf("Replicas() = %d, want %d", got, tc.want)
49+
}
50+
})
51+
}
52+
}
53+
54+
func TestAlluxioRuntime_GetStatus(t *testing.T) {
55+
t.Run("nil runtime returns empty status pointer", func(t *testing.T) {
56+
var runtime *AlluxioRuntime
57+
got := runtime.GetStatus()
58+
if got == nil {
59+
t.Fatalf("GetStatus() returned nil")
60+
}
61+
if got.MasterPhase != RuntimePhaseNone {
62+
t.Fatalf("GetStatus().MasterPhase = %q, want %q", got.MasterPhase, RuntimePhaseNone)
63+
}
64+
})
65+
66+
t.Run("returns pointer to runtime status", func(t *testing.T) {
67+
runtime := &AlluxioRuntime{
68+
Status: RuntimeStatus{
69+
MasterPhase: RuntimePhaseReady,
70+
WorkerPhase: RuntimePhasePartialReady,
71+
},
72+
}
73+
74+
got := runtime.GetStatus()
75+
if got == nil {
76+
t.Fatalf("GetStatus() returned nil")
77+
}
78+
if got.MasterPhase != RuntimePhaseReady {
79+
t.Fatalf("GetStatus().MasterPhase = %q, want %q", got.MasterPhase, RuntimePhaseReady)
80+
}
81+
82+
got.FusePhase = RuntimePhaseNotReady
83+
if runtime.Status.FusePhase != RuntimePhaseNotReady {
84+
t.Fatalf("GetStatus() should return underlying status pointer")
85+
}
86+
})
87+
}

0 commit comments

Comments
 (0)