error_handling_e2e_test.go
1 // Copyright 2026 Alibaba Group Holding Ltd. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package e2e 16 17 import ( 18 "context" 19 "testing" 20 "time" 21 22 "github.com/alibaba/OpenSandbox/sdks/sandbox/go" 23 "github.com/stretchr/testify/require" 24 ) 25 26 func TestError_XRequestIDPassthrough(t *testing.T) { 27 config := getConnectionConfig(t) 28 ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) 29 defer cancel() 30 31 mgr := opensandbox.NewSandboxManager(config) 32 defer mgr.Close() 33 34 _, err := mgr.GetSandboxInfo(ctx, "non-existent-sandbox-id-12345") 35 require.Error(t, err, "expected error for non-existent sandbox") 36 37 var apiErr *opensandbox.APIError 38 require.ErrorAs(t, err, &apiErr) 39 40 require.Equal(t, 404, apiErr.StatusCode) 41 42 if apiErr.RequestID != "" { 43 t.Logf("x-request-id present: %s (status=%d, code=%s)", 44 apiErr.RequestID, apiErr.StatusCode, apiErr.Response.Code) 45 } else { 46 t.Log("x-request-id not returned by server (may not be configured)") 47 } 48 49 t.Logf("Error response: code=%s message=%s", apiErr.Response.Code, apiErr.Response.Message) 50 }