MCPcopy Index your code
hub / github.com/cli/cli / Test_setRun_env

Function Test_setRun_env

pkg/cmd/secret/set/set_test.go:499–536  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

497}
498
499func Test_setRun_env(t *testing.T) {
500 reg := &httpmock.Registry{}
501
502 reg.Register(httpmock.REST("GET", "repos/owner/repo/environments/development/secrets/public-key"),
503 httpmock.JSONResponse(PubKey{ID: "123", Key: "CDjXqf7AJBXWhMczcy+Fs7JlACEptgceysutztHaFQI="}))
504
505 reg.Register(httpmock.REST("PUT", "repos/owner/repo/environments/development/secrets/cool_secret"), httpmock.StatusStringResponse(201, `{}`))
506
507 ios, _, _, _ := iostreams.Test()
508
509 opts := &SetOptions{
510 HttpClient: func() (*http.Client, error) {
511 return &http.Client{Transport: reg}, nil
512 },
513 Config: func() (gh.Config, error) { return config.NewBlankConfig(), nil },
514 BaseRepo: func() (ghrepo.Interface, error) {
515 return ghrepo.FromFullName("owner/repo")
516 },
517 EnvName: "development",
518 IO: ios,
519 SecretName: "cool_secret",
520 Body: "a secret",
521 RandomOverride: fakeRandom,
522 }
523
524 err := setRun(opts)
525 assert.NoError(t, err)
526
527 reg.Verify(t)
528
529 data, err := io.ReadAll(reg.Requests[1].Body)
530 assert.NoError(t, err)
531 var payload SecretPayload
532 err = json.Unmarshal(data, &payload)
533 assert.NoError(t, err)
534 assert.Equal(t, payload.KeyID, "123")
535 assert.Equal(t, payload.EncryptedValue, "UKYUCbHd0DJemxa3AOcZ6XcsBwALG9d4bpB8ZT0gSV39vl3BHiGSgj8zJapDxgB2BwqNqRhpjC4=")
536}
537
538func Test_setRun_org(t *testing.T) {
539 tests := []struct {

Callers

nothing calls this directly

Calls 10

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
JSONResponseFunction · 0.92
StatusStringResponseFunction · 0.92
TestFunction · 0.92
NewBlankConfigFunction · 0.92
FromFullNameFunction · 0.92
EqualMethod · 0.80
setRunFunction · 0.70

Tested by

no test coverage detected