@@ -14,34 +14,51 @@ import (
1414 "github.com/stretchr/testify/assert"
1515)
1616
17+ // TODO prompt cfg test
18+
1719func Test_NewCmdRefresh (t * testing.T ) {
1820 tests := []struct {
19- name string
20- cli string
21- wants RefreshOptions
21+ name string
22+ cli string
23+ wants RefreshOptions
24+ wantsErr bool
25+ tty bool
2226 }{
2327 {
24- name : "no arguments" ,
28+ name : "tty no arguments" ,
29+ tty : true ,
2530 wants : RefreshOptions {
2631 Hostname : "" ,
2732 },
2833 },
2934 {
30- name : "hostname" ,
35+ name : "nontty no arguments" ,
36+ wantsErr : true ,
37+ },
38+ {
39+ name : "nontty hostname" ,
40+ cli : "-h aline.cedrac" ,
41+ wantsErr : true ,
42+ },
43+ {
44+ name : "tty hostname" ,
45+ tty : true ,
3146 cli : "-h aline.cedrac" ,
3247 wants : RefreshOptions {
3348 Hostname : "aline.cedrac" ,
3449 },
3550 },
3651 {
37- name : "one scope" ,
52+ name : "tty one scope" ,
53+ tty : true ,
3854 cli : "--scopes repo:invite" ,
3955 wants : RefreshOptions {
4056 Scopes : []string {"repo:invite" },
4157 },
4258 },
4359 {
44- name : "scopes" ,
60+ name : "tty scopes" ,
61+ tty : true ,
4562 cli : "--scopes repo:invite,read:public_key" ,
4663 wants : RefreshOptions {
4764 Scopes : []string {"repo:invite" , "read:public_key" },
@@ -55,6 +72,8 @@ func Test_NewCmdRefresh(t *testing.T) {
5572 f := & cmdutil.Factory {
5673 IOStreams : io ,
5774 }
75+ io .SetStdinTTY (tt .tty )
76+ io .SetStdoutTTY (tt .tty )
5877
5978 argv , err := shlex .Split (tt .cli )
6079 assert .NoError (t , err )
@@ -73,11 +92,14 @@ func Test_NewCmdRefresh(t *testing.T) {
7392 cmd .SetErr (& bytes.Buffer {})
7493
7594 _ , err = cmd .ExecuteC ()
95+ if tt .wantsErr {
96+ assert .Error (t , err )
97+ return
98+ }
7699 assert .NoError (t , err )
77100 assert .Equal (t , tt .wants .Hostname , gotOpts .Hostname )
78101 assert .Equal (t , tt .wants .Scopes , gotOpts .Scopes )
79102 })
80-
81103 }
82104}
83105
@@ -96,12 +118,6 @@ func Test_refreshRun(t *testing.T) {
96118 nontty bool
97119 wantAuthArgs authArgs
98120 }{
99- {
100- name : "non tty" ,
101- opts : & RefreshOptions {},
102- nontty : true ,
103- wantErr : regexp .MustCompile (`not attached to a terminal;` ),
104- },
105121 {
106122 name : "no hosts configured" ,
107123 opts : & RefreshOptions {},
0 commit comments