"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/cmd/secret/list/list_test.go" between
gh-cli-1.10.3.tar.gz and gh-cli-1.11.0.tar.gz

About: GitHub CLI is GitHub’s official command line tool.

list_test.go  (gh-cli-1.10.3):list_test.go  (gh-cli-1.11.0)
package list package list
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"strings"
"testing" "testing"
"time" "time"
"github.com/cli/cli/internal/config" "github.com/cli/cli/internal/config"
"github.com/cli/cli/internal/ghrepo" "github.com/cli/cli/internal/ghrepo"
"github.com/cli/cli/pkg/cmd/secret/shared" "github.com/cli/cli/pkg/cmd/secret/shared"
"github.com/cli/cli/pkg/cmdutil" "github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/httpmock" "github.com/cli/cli/pkg/httpmock"
"github.com/cli/cli/pkg/iostreams" "github.com/cli/cli/pkg/iostreams"
"github.com/cli/cli/test" "github.com/cli/cli/test"
skipping to change at line 41 skipping to change at line 43
OrgName: "", OrgName: "",
}, },
}, },
{ {
name: "org", name: "org",
cli: "-oUmbrellaCorporation", cli: "-oUmbrellaCorporation",
wants: ListOptions{ wants: ListOptions{
OrgName: "UmbrellaCorporation", OrgName: "UmbrellaCorporation",
}, },
}, },
{
name: "env",
cli: "-eDevelopment",
wants: ListOptions{
EnvName: "Development",
},
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
io, _, _, _ := iostreams.Test() io, _, _, _ := iostreams.Test()
f := &cmdutil.Factory{ f := &cmdutil.Factory{
IOStreams: io, IOStreams: io,
} }
argv, err := shlex.Split(tt.cli) argv, err := shlex.Split(tt.cli)
skipping to change at line 67 skipping to change at line 76
}) })
cmd.SetArgs(argv) cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{}) cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(&bytes.Buffer{}) cmd.SetOut(&bytes.Buffer{})
cmd.SetErr(&bytes.Buffer{}) cmd.SetErr(&bytes.Buffer{})
_, err = cmd.ExecuteC() _, err = cmd.ExecuteC()
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, tt.wants.OrgName, gotOpts.OrgName) assert.Equal(t, tt.wants.OrgName, gotOpts.OrgName)
assert.Equal(t, tt.wants.EnvName, gotOpts.EnvName)
}) })
} }
} }
func Test_listRun(t *testing.T) { func Test_listRun(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
tty bool tty bool
opts *ListOptions opts *ListOptions
wantOut []string wantOut []string
skipping to change at line 123 skipping to change at line 132
tty: false, tty: false,
opts: &ListOptions{ opts: &ListOptions{
OrgName: "UmbrellaCorporation", OrgName: "UmbrellaCorporation",
}, },
wantOut: []string{ wantOut: []string{
"SECRET_ONE\t1988-10-11\tALL", "SECRET_ONE\t1988-10-11\tALL",
"SECRET_TWO\t2020-12-04\tPRIVATE", "SECRET_TWO\t2020-12-04\tPRIVATE",
"SECRET_THREE\t1975-11-30\tSELECTED", "SECRET_THREE\t1975-11-30\tSELECTED",
}, },
}, },
{
name: "env tty",
tty: true,
opts: &ListOptions{
EnvName: "Development",
},
wantOut: []string{
"SECRET_ONE.*Updated 1988-10-11",
"SECRET_TWO.*Updated 2020-12-04",
"SECRET_THREE.*Updated 1975-11-30",
},
},
{
name: "env not tty",
tty: false,
opts: &ListOptions{
EnvName: "Development",
},
wantOut: []string{
"SECRET_ONE\t1988-10-11",
"SECRET_TWO\t2020-12-04",
"SECRET_THREE\t1975-11-30",
},
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
reg := &httpmock.Registry{} reg := &httpmock.Registry{}
path := "repos/owner/repo/actions/secrets"
if tt.opts.EnvName != "" {
path = fmt.Sprintf("repos/owner/repo/environments
/%s/secrets", tt.opts.EnvName)
}
t0, _ := time.Parse("2006-01-02", "1988-10-11") t0, _ := time.Parse("2006-01-02", "1988-10-11")
t1, _ := time.Parse("2006-01-02", "2020-12-04") t1, _ := time.Parse("2006-01-02", "2020-12-04")
t2, _ := time.Parse("2006-01-02", "1975-11-30") t2, _ := time.Parse("2006-01-02", "1975-11-30")
path := "repos/owner/repo/actions/secrets"
payload := secretsPayload{} payload := secretsPayload{}
payload.Secrets = []*Secret{ payload.Secrets = []*Secret{
{ {
Name: "SECRET_ONE", Name: "SECRET_ONE",
UpdatedAt: t0, UpdatedAt: t0,
}, },
{ {
Name: "SECRET_TWO", Name: "SECRET_TWO",
UpdatedAt: t1, UpdatedAt: t1,
}, },
skipping to change at line 203 skipping to change at line 240
err := listRun(tt.opts) err := listRun(tt.opts)
assert.NoError(t, err) assert.NoError(t, err)
reg.Verify(t) reg.Verify(t)
//nolint:staticcheck // prefer exact matchers over Expect Lines //nolint:staticcheck // prefer exact matchers over Expect Lines
test.ExpectLines(t, stdout.String(), tt.wantOut...) test.ExpectLines(t, stdout.String(), tt.wantOut...)
}) })
} }
} }
func Test_getSecrets_pagination(t *testing.T) {
var requests []*http.Request
var client testClient = func(req *http.Request) (*http.Response, error) {
header := make(map[string][]string)
if len(requests) == 0 {
header["Link"] = []string{`<http://example.com/page/0>; r
el="previous", <http://example.com/page/2>; rel="next"`}
}
requests = append(requests, req)
return &http.Response{
Request: req,
Body: ioutil.NopCloser(strings.NewReader(`{"secrets":[
{},{}]}`)),
Header: header,
}, nil
}
secrets, err := getSecrets(client, "github.com", "path/to")
assert.NoError(t, err)
assert.Equal(t, 2, len(requests))
assert.Equal(t, 4, len(secrets))
assert.Equal(t, "https://api.github.com/path/to?per_page=100", requests[0
].URL.String())
assert.Equal(t, "http://example.com/page/2", requests[1].URL.String())
}
type testClient func(*http.Request) (*http.Response, error)
func (c testClient) Do(req *http.Request) (*http.Response, error) {
return c(req)
}
 End of changes. 8 change blocks. 
2 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)