(t *testing.T)
| 701 | } |
| 702 | |
| 703 | func Test_setRun_user(t *testing.T) { |
| 704 | tests := []struct { |
| 705 | name string |
| 706 | opts *SetOptions |
| 707 | wantVisibility shared.Visibility |
| 708 | wantRepositories []int64 |
| 709 | }{ |
| 710 | { |
| 711 | name: "all vis", |
| 712 | opts: &SetOptions{ |
| 713 | UserSecrets: true, |
| 714 | Visibility: shared.All, |
| 715 | }, |
| 716 | }, |
| 717 | { |
| 718 | name: "selected visibility", |
| 719 | opts: &SetOptions{ |
| 720 | UserSecrets: true, |
| 721 | Visibility: shared.Selected, |
| 722 | RepositoryNames: []string{"cli/cli", "github/hub"}, |
| 723 | }, |
| 724 | wantRepositories: []int64{212613049, 401025}, |
| 725 | }, |
| 726 | } |
| 727 | |
| 728 | for _, tt := range tests { |
| 729 | t.Run(tt.name, func(t *testing.T) { |
| 730 | reg := &httpmock.Registry{} |
| 731 | |
| 732 | reg.Register(httpmock.REST("GET", "user/codespaces/secrets/public-key"), |
| 733 | httpmock.JSONResponse(PubKey{ID: "123", Key: "CDjXqf7AJBXWhMczcy+Fs7JlACEptgceysutztHaFQI="})) |
| 734 | |
| 735 | reg.Register(httpmock.REST("PUT", "user/codespaces/secrets/cool_secret"), |
| 736 | httpmock.StatusStringResponse(201, `{}`)) |
| 737 | |
| 738 | if len(tt.opts.RepositoryNames) > 0 { |
| 739 | reg.Register(httpmock.GraphQL(`query MapRepositoryNames\b`), |
| 740 | httpmock.StringResponse(`{"data":{"repo_0001":{"databaseId":212613049},"repo_0002":{"databaseId":401025}}}`)) |
| 741 | } |
| 742 | |
| 743 | ios, _, _, _ := iostreams.Test() |
| 744 | |
| 745 | tt.opts.HttpClient = func() (*http.Client, error) { |
| 746 | return &http.Client{Transport: reg}, nil |
| 747 | } |
| 748 | tt.opts.Config = func() (gh.Config, error) { |
| 749 | return config.NewBlankConfig(), nil |
| 750 | } |
| 751 | tt.opts.IO = ios |
| 752 | tt.opts.SecretName = "cool_secret" |
| 753 | tt.opts.Body = "a secret" |
| 754 | tt.opts.RandomOverride = fakeRandom |
| 755 | |
| 756 | err := setRun(tt.opts) |
| 757 | assert.NoError(t, err) |
| 758 | |
| 759 | reg.Verify(t) |
| 760 |
nothing calls this directly
no test coverage detected