|
| 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