@@ -51,22 +51,37 @@ func TestOutStyle(t *testing.T) {
51
51
style string
52
52
envValue string
53
53
message string
54
+ params []interface {}
54
55
want string
55
56
}{
56
- {"happy" , "true" , "This is happy." , "😄 This is happy.\n " },
57
- {"Docker" , "true" , "This is Docker." , "🐳 This is Docker.\n " },
58
- {"option" , "true" , "This is option." , " ▪ This is option.\n " },
59
-
60
- {"happy" , "false" , "This is happy." , "o This is happy.\n " },
61
- {"Docker" , "false" , "This is Docker." , "- This is Docker.\n " },
62
- {"option" , "false" , "This is option." , " - This is option.\n " },
57
+ {"happy" , "true" , "This is happy." , nil , "😄 This is happy.\n " },
58
+ {"Docker" , "true" , "This is Docker." , nil , "🐳 This is Docker.\n " },
59
+ {"option" , "true" , "This is option." , nil , " ▪ This is option.\n " },
60
+ {
61
+ "option" ,
62
+ "true" ,
63
+ "Message with params: %s %s" ,
64
+ []interface {}{"encode '%' signs" , "%s%%%d" },
65
+ " ▪ Message with params: encode '%' signs %s%%%d\n " ,
66
+ },
67
+
68
+ {"happy" , "false" , "This is happy." , nil , "o This is happy.\n " },
69
+ {"Docker" , "false" , "This is Docker." , nil , "- This is Docker.\n " },
70
+ {"option" , "false" , "This is option." , nil , " - This is option.\n " },
71
+ {
72
+ "option" ,
73
+ "false" ,
74
+ "Message with params: %s %s" ,
75
+ []interface {}{"encode '%' signs" , "%s%%%d" },
76
+ " - Message with params: encode '%' signs %s%%%d\n " ,
77
+ },
63
78
}
64
79
for _ , tc := range tests {
65
80
t .Run (tc .style + "-" + tc .envValue , func (t * testing.T ) {
66
81
os .Setenv (OverrideEnv , tc .envValue )
67
82
f := newFakeFile ()
68
83
SetOutFile (f )
69
- if err := OutStyle (tc .style , tc .message ); err != nil {
84
+ if err := OutStyle (tc .style , tc .message , tc . params ... ); err != nil {
70
85
t .Errorf ("unexpected error: %q" , err )
71
86
}
72
87
got := f .String ()
@@ -94,6 +109,7 @@ func TestOut(t *testing.T) {
94
109
{format : "xyz123" , want : "xyz123" },
95
110
{format : "Installing Kubernetes version %s ..." , lang : language .Arabic , arg : "v1.13" , want : "... v1.13 تثبيت Kubernetes الإصدار" },
96
111
{format : "Installing Kubernetes version %s ..." , lang : language .AmericanEnglish , arg : "v1.13" , want : "Installing Kubernetes version v1.13 ..." },
112
+ {format : "Parameter encoding: %s" , arg : "%s%%%d" , want : "Parameter encoding: %s%%%d" },
97
113
}
98
114
for _ , tc := range tests {
99
115
t .Run (tc .format , func (t * testing.T ) {
@@ -116,13 +132,13 @@ func TestErr(t *testing.T) {
116
132
os .Setenv (OverrideEnv , "0" )
117
133
f := newFakeFile ()
118
134
SetErrFile (f )
119
- if err := Err ("xyz123\n " ); err != nil {
135
+ if err := Err ("xyz123 %s \n " , "%s%%%d " ); err != nil {
120
136
t .Errorf ("unexpected error: %q" , err )
121
137
}
122
138
123
139
OutLn ("unrelated message" )
124
140
got := f .String ()
125
- want := "xyz123\n "
141
+ want := "xyz123 %s%%%d \n "
126
142
127
143
if got != want {
128
144
t .Errorf ("Err() = %q, want %q" , got , want )
@@ -133,11 +149,11 @@ func TestErrStyle(t *testing.T) {
133
149
os .Setenv (OverrideEnv , "1" )
134
150
f := newFakeFile ()
135
151
SetErrFile (f )
136
- if err := ErrStyle ("fatal" , "It broke " ); err != nil {
152
+ if err := ErrStyle ("fatal" , "error: %s" , "%s%%%d " ); err != nil {
137
153
t .Errorf ("unexpected error: %q" , err )
138
154
}
139
155
got := f .String ()
140
- want := "💣 It broke \n "
156
+ want := "💣 error: %s%%%d \n "
141
157
if got != want {
142
158
t .Errorf ("ErrStyle() = %q, want %q" , got , want )
143
159
}
0 commit comments