@@ -7,6 +7,7 @@ package github
77
88import (
99 "context"
10+ "encoding/json"
1011 "fmt"
1112 "net/http"
1213 "testing"
@@ -56,6 +57,94 @@ func TestActionsService_ListRunnerApplicationDownloads(t *testing.T) {
5657 })
5758}
5859
60+ func TestActionsService_GenerateOrgJITConfig (t * testing.T ) {
61+ client , mux , _ , teardown := setup ()
62+ defer teardown ()
63+
64+ input := & GenerateJITConfigRequest {Name : "test" , RunnerGroupID : 1 , Labels : []string {"one" , "two" }}
65+
66+ mux .HandleFunc ("/orgs/o/actions/runners/generate-jitconfig" , func (w http.ResponseWriter , r * http.Request ) {
67+ v := new (GenerateJITConfigRequest )
68+ json .NewDecoder (r .Body ).Decode (v )
69+
70+ testMethod (t , r , "POST" )
71+ if ! cmp .Equal (v , input ) {
72+ t .Errorf ("Request body = %+v, want %+v" , v , input )
73+ }
74+
75+ fmt .Fprint (w , `{"encoded_jit_config":"foo"}` )
76+ })
77+
78+ ctx := context .Background ()
79+ jitConfig , _ , err := client .Actions .GenerateOrgJITConfig (ctx , "o" , input )
80+ if err != nil {
81+ t .Errorf ("Actions.GenerateOrgJITConfig returned error: %v" , err )
82+ }
83+
84+ want := & JITRunnerConfig {EncodedJITConfig : String ("foo" )}
85+ if ! cmp .Equal (jitConfig , want ) {
86+ t .Errorf ("Actions.GenerateOrgJITConfig returned %+v, want %+v" , jitConfig , want )
87+ }
88+
89+ const methodName = "GenerateOrgJITConfig"
90+ testBadOptions (t , methodName , func () (err error ) {
91+ _ , _ , err = client .Actions .GenerateOrgJITConfig (ctx , "\n " , input )
92+ return err
93+ })
94+
95+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
96+ got , resp , err := client .Actions .GenerateOrgJITConfig (ctx , "o" , input )
97+ if got != nil {
98+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
99+ }
100+ return resp , err
101+ })
102+ }
103+
104+ func TestActionsService_GenerateRepoJITConfig (t * testing.T ) {
105+ client , mux , _ , teardown := setup ()
106+ defer teardown ()
107+
108+ input := & GenerateJITConfigRequest {Name : "test" , RunnerGroupID : 1 , Labels : []string {"one" , "two" }}
109+
110+ mux .HandleFunc ("/repos/o/r/actions/runners/generate-jitconfig" , func (w http.ResponseWriter , r * http.Request ) {
111+ v := new (GenerateJITConfigRequest )
112+ json .NewDecoder (r .Body ).Decode (v )
113+
114+ testMethod (t , r , "POST" )
115+ if ! cmp .Equal (v , input ) {
116+ t .Errorf ("Request body = %+v, want %+v" , v , input )
117+ }
118+
119+ fmt .Fprint (w , `{"encoded_jit_config":"foo"}` )
120+ })
121+
122+ ctx := context .Background ()
123+ jitConfig , _ , err := client .Actions .GenerateRepoJITConfig (ctx , "o" , "r" , input )
124+ if err != nil {
125+ t .Errorf ("Actions.GenerateRepoJITConfig returned error: %v" , err )
126+ }
127+
128+ want := & JITRunnerConfig {EncodedJITConfig : String ("foo" )}
129+ if ! cmp .Equal (jitConfig , want ) {
130+ t .Errorf ("Actions.GenerateRepoJITConfig returned %+v, want %+v" , jitConfig , want )
131+ }
132+
133+ const methodName = "GenerateRepoJITConfig"
134+ testBadOptions (t , methodName , func () (err error ) {
135+ _ , _ , err = client .Actions .GenerateRepoJITConfig (ctx , "\n " , "\n " , input )
136+ return err
137+ })
138+
139+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
140+ got , resp , err := client .Actions .GenerateRepoJITConfig (ctx , "o" , "r" , input )
141+ if got != nil {
142+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
143+ }
144+ return resp , err
145+ })
146+ }
147+
59148func TestActionsService_CreateRegistrationToken (t * testing.T ) {
60149 client , mux , _ , teardown := setup ()
61150 defer teardown ()
0 commit comments