@@ -2,6 +2,7 @@ package actions_test
22
33import (
44 "context"
5+ "errors"
56 "net/http"
67 "testing"
78 "time"
@@ -58,4 +59,37 @@ func TestGenerateJitRunnerConfig(t *testing.T) {
5859 assert .NotNil (t , err )
5960 assert .Equalf (t , actualRetry , expectedRetry , "A retry was expected after the first request but got: %v" , actualRetry )
6061 })
62+
63+ t .Run ("Error includes HTTP method and URL when request fails" , func (t * testing.T ) {
64+ runnerSettings := & actions.RunnerScaleSetJitRunnerSetting {}
65+
66+ server := newActionsServer (t , http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
67+ w .WriteHeader (http .StatusInternalServerError )
68+ }))
69+
70+ client , err := actions .NewClient (
71+ server .configURLForOrg ("my-org" ),
72+ auth ,
73+ actions .WithRetryMax (0 ), // No retries to get immediate error
74+ actions .WithRetryWaitMax (1 * time .Millisecond ),
75+ )
76+ require .NoError (t , err )
77+
78+ _ , err = client .GenerateJitRunnerConfig (ctx , runnerSettings , 1 )
79+ require .NotNil (t , err )
80+ // Verify error message includes HTTP method and URL for better debugging
81+ errMsg := err .Error ()
82+ assert .Contains (t , errMsg , "POST" , "Error message should include HTTP method" )
83+ assert .Contains (t , errMsg , "generatejitconfig" , "Error message should include URL path" )
84+
85+ // The error might be an ActionsError (if response was received) or a wrapped error (if Do() failed)
86+ // In either case, the error message should include request details
87+ var actionsErr * actions.ActionsError
88+ if errors .As (err , & actionsErr ) {
89+ // If we got an ActionsError, verify the status code is included
90+ assert .Equal (t , http .StatusInternalServerError , actionsErr .StatusCode )
91+ }
92+ // If it's a wrapped error from Do(), the error message already includes the method and URL
93+ // which is what we're testing for
94+ })
6195}
0 commit comments