|
| 1 | +/* |
| 2 | +Copyright 2025 The Kubernetes 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 wcpguest |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "google.golang.org/grpc/codes" |
| 23 | + "google.golang.org/grpc/status" |
| 24 | +) |
| 25 | + |
| 26 | +// TestCreateVolumeTimeoutReturnsDeadlineExceeded verifies that when a PVC fails to bind |
| 27 | +// within the provision timeout, the CreateVolume operation returns codes.DeadlineExceeded |
| 28 | +// instead of codes.Internal to allow external-provisioner to retry and prevent orphan volumes. |
| 29 | +func TestCreateVolumeTimeoutReturnsDeadlineExceeded(t *testing.T) { |
| 30 | + t.Log("Testing timeout error code behavior") |
| 31 | + t.Log("") |
| 32 | + |
| 33 | + // Simulate what the code does when timeout occurs |
| 34 | + msg := "failed to create volume on namespace: test-ns in supervisor cluster. reason: provisioning timeout" |
| 35 | + err := status.Error(codes.DeadlineExceeded, msg) |
| 36 | + |
| 37 | + // Verify we can extract the correct code |
| 38 | + st, ok := status.FromError(err) |
| 39 | + if !ok { |
| 40 | + t.Fatalf("Expected to extract gRPC status from error") |
| 41 | + } |
| 42 | + |
| 43 | + if st.Code() != codes.DeadlineExceeded { |
| 44 | + t.Fatalf("Expected codes.DeadlineExceeded, got: %v", st.Code()) |
| 45 | + } |
| 46 | + |
| 47 | + t.Logf("Timeout errors return codes.DeadlineExceeded") |
| 48 | +} |
0 commit comments