| 1 |
package cmd |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"github.com/stretchr/testify/require" |
| 6 |
"net/http" |
| 7 |
"net/http/httptest" |
| 8 |
"os" |
| 9 |
"path/filepath" |
| 10 |
"strings" |
| 11 |
"testing" |
| 12 |
) |
| 13 |
|
| 14 |
func TestCLI_Subscribe_Default_UserPass_Subscription_Token(t *testing.T) { |
| 15 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 16 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 17 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 18 |
require.Equal(t, "Bearer tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2", r.Header.Get("Authorization")) |
| 19 |
|
| 20 |
w.WriteHeader(http.StatusOK) |
| 21 |
w.Write([]byte(message)) |
| 22 |
})) |
| 23 |
defer server.Close() |
| 24 |
|
| 25 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 26 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 27 |
default-host: %s |
| 28 |
default-user: philipp |
| 29 |
default-password: mypass |
| 30 |
subscribe: |
| 31 |
- topic: mytopic |
| 32 |
token: tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2 |
| 33 |
`, server.URL)), 0600)) |
| 34 |
|
| 35 |
app, _, stdout, _ := newTestApp() |
| 36 |
|
| 37 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename})) |
| 38 |
|
| 39 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 40 |
} |
| 41 |
|
| 42 |
func TestCLI_Subscribe_Default_Token_Subscription_UserPass(t *testing.T) { |
| 43 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 44 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 45 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 46 |
require.Equal(t, "Basic cGhpbGlwcDpteXBhc3M=", r.Header.Get("Authorization")) |
| 47 |
|
| 48 |
w.WriteHeader(http.StatusOK) |
| 49 |
w.Write([]byte(message)) |
| 50 |
})) |
| 51 |
defer server.Close() |
| 52 |
|
| 53 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 54 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 55 |
default-host: %s |
| 56 |
default-token: tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2 |
| 57 |
subscribe: |
| 58 |
- topic: mytopic |
| 59 |
user: philipp |
| 60 |
password: mypass |
| 61 |
`, server.URL)), 0600)) |
| 62 |
|
| 63 |
app, _, stdout, _ := newTestApp() |
| 64 |
|
| 65 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename})) |
| 66 |
|
| 67 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 68 |
} |
| 69 |
|
| 70 |
func TestCLI_Subscribe_Default_Token_Subscription_Token(t *testing.T) { |
| 71 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 72 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 73 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 74 |
require.Equal(t, "Bearer tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2", r.Header.Get("Authorization")) |
| 75 |
|
| 76 |
w.WriteHeader(http.StatusOK) |
| 77 |
w.Write([]byte(message)) |
| 78 |
})) |
| 79 |
defer server.Close() |
| 80 |
|
| 81 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 82 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 83 |
default-host: %s |
| 84 |
default-token: tk_FAKETOKEN01234567890FAKETOKEN |
| 85 |
subscribe: |
| 86 |
- topic: mytopic |
| 87 |
token: tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2 |
| 88 |
`, server.URL)), 0600)) |
| 89 |
|
| 90 |
app, _, stdout, _ := newTestApp() |
| 91 |
|
| 92 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename})) |
| 93 |
|
| 94 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 95 |
} |
| 96 |
|
| 97 |
func TestCLI_Subscribe_Default_UserPass_Subscription_UserPass(t *testing.T) { |
| 98 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 99 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 100 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 101 |
require.Equal(t, "Basic cGhpbGlwcDpteXBhc3M=", r.Header.Get("Authorization")) |
| 102 |
|
| 103 |
w.WriteHeader(http.StatusOK) |
| 104 |
w.Write([]byte(message)) |
| 105 |
})) |
| 106 |
defer server.Close() |
| 107 |
|
| 108 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 109 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 110 |
default-host: %s |
| 111 |
default-user: fake |
| 112 |
default-password: password |
| 113 |
subscribe: |
| 114 |
- topic: mytopic |
| 115 |
user: philipp |
| 116 |
password: mypass |
| 117 |
`, server.URL)), 0600)) |
| 118 |
|
| 119 |
app, _, stdout, _ := newTestApp() |
| 120 |
|
| 121 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename})) |
| 122 |
|
| 123 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 124 |
} |
| 125 |
|
| 126 |
func TestCLI_Subscribe_Default_Token_Subscription_Empty(t *testing.T) { |
| 127 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 128 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 129 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 130 |
require.Equal(t, "Bearer tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2", r.Header.Get("Authorization")) |
| 131 |
|
| 132 |
w.WriteHeader(http.StatusOK) |
| 133 |
w.Write([]byte(message)) |
| 134 |
})) |
| 135 |
defer server.Close() |
| 136 |
|
| 137 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 138 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 139 |
default-host: %s |
| 140 |
default-token: tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2 |
| 141 |
subscribe: |
| 142 |
- topic: mytopic |
| 143 |
`, server.URL)), 0600)) |
| 144 |
|
| 145 |
app, _, stdout, _ := newTestApp() |
| 146 |
|
| 147 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename})) |
| 148 |
|
| 149 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 150 |
} |
| 151 |
|
| 152 |
func TestCLI_Subscribe_Default_UserPass_Subscription_Empty(t *testing.T) { |
| 153 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 154 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 155 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 156 |
require.Equal(t, "Basic cGhpbGlwcDpteXBhc3M=", r.Header.Get("Authorization")) |
| 157 |
|
| 158 |
w.WriteHeader(http.StatusOK) |
| 159 |
w.Write([]byte(message)) |
| 160 |
})) |
| 161 |
defer server.Close() |
| 162 |
|
| 163 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 164 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 165 |
default-host: %s |
| 166 |
default-user: philipp |
| 167 |
default-password: mypass |
| 168 |
subscribe: |
| 169 |
- topic: mytopic |
| 170 |
`, server.URL)), 0600)) |
| 171 |
|
| 172 |
app, _, stdout, _ := newTestApp() |
| 173 |
|
| 174 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename})) |
| 175 |
|
| 176 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 177 |
} |
| 178 |
|
| 179 |
func TestCLI_Subscribe_Default_Empty_Subscription_Token(t *testing.T) { |
| 180 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 181 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 182 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 183 |
require.Equal(t, "Bearer tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2", r.Header.Get("Authorization")) |
| 184 |
|
| 185 |
w.WriteHeader(http.StatusOK) |
| 186 |
w.Write([]byte(message)) |
| 187 |
})) |
| 188 |
defer server.Close() |
| 189 |
|
| 190 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 191 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 192 |
default-host: %s |
| 193 |
subscribe: |
| 194 |
- topic: mytopic |
| 195 |
token: tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2 |
| 196 |
`, server.URL)), 0600)) |
| 197 |
|
| 198 |
app, _, stdout, _ := newTestApp() |
| 199 |
|
| 200 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename})) |
| 201 |
|
| 202 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 203 |
} |
| 204 |
|
| 205 |
func TestCLI_Subscribe_Default_Empty_Subscription_UserPass(t *testing.T) { |
| 206 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 207 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 208 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 209 |
require.Equal(t, "Basic cGhpbGlwcDpteXBhc3M=", r.Header.Get("Authorization")) |
| 210 |
|
| 211 |
w.WriteHeader(http.StatusOK) |
| 212 |
w.Write([]byte(message)) |
| 213 |
})) |
| 214 |
defer server.Close() |
| 215 |
|
| 216 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 217 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 218 |
default-host: %s |
| 219 |
subscribe: |
| 220 |
- topic: mytopic |
| 221 |
user: philipp |
| 222 |
password: mypass |
| 223 |
`, server.URL)), 0600)) |
| 224 |
|
| 225 |
app, _, stdout, _ := newTestApp() |
| 226 |
|
| 227 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename})) |
| 228 |
|
| 229 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 230 |
} |
| 231 |
|
| 232 |
func TestCLI_Subscribe_Default_Token_CLI_Token(t *testing.T) { |
| 233 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 234 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 235 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 236 |
require.Equal(t, "Bearer tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2", r.Header.Get("Authorization")) |
| 237 |
|
| 238 |
w.WriteHeader(http.StatusOK) |
| 239 |
w.Write([]byte(message)) |
| 240 |
})) |
| 241 |
defer server.Close() |
| 242 |
|
| 243 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 244 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 245 |
default-host: %s |
| 246 |
default-token: tk_FAKETOKEN0123456789FAKETOKEN |
| 247 |
`, server.URL)), 0600)) |
| 248 |
|
| 249 |
app, _, stdout, _ := newTestApp() |
| 250 |
|
| 251 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename, "--token", "tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2", "mytopic"})) |
| 252 |
|
| 253 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 254 |
} |
| 255 |
|
| 256 |
func TestCLI_Subscribe_Default_Token_CLI_UserPass(t *testing.T) { |
| 257 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 258 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 259 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 260 |
require.Equal(t, "Basic cGhpbGlwcDpteXBhc3M=", r.Header.Get("Authorization")) |
| 261 |
|
| 262 |
w.WriteHeader(http.StatusOK) |
| 263 |
w.Write([]byte(message)) |
| 264 |
})) |
| 265 |
defer server.Close() |
| 266 |
|
| 267 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 268 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 269 |
default-host: %s |
| 270 |
default-token: tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2 |
| 271 |
`, server.URL)), 0600)) |
| 272 |
|
| 273 |
app, _, stdout, _ := newTestApp() |
| 274 |
|
| 275 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename, "--user", "philipp:mypass", "mytopic"})) |
| 276 |
|
| 277 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 278 |
} |
| 279 |
|
| 280 |
func TestCLI_Subscribe_Default_Token_Subscription_Token_CLI_UserPass(t *testing.T) { |
| 281 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 282 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 283 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 284 |
require.Equal(t, "Bearer tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2", r.Header.Get("Authorization")) |
| 285 |
|
| 286 |
w.WriteHeader(http.StatusOK) |
| 287 |
w.Write([]byte(message)) |
| 288 |
})) |
| 289 |
defer server.Close() |
| 290 |
|
| 291 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 292 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 293 |
default-host: %s |
| 294 |
default-token: tk_FAKETOKEN01234567890FAKETOKEN |
| 295 |
subscribe: |
| 296 |
- topic: mytopic |
| 297 |
token: tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2 |
| 298 |
`, server.URL)), 0600)) |
| 299 |
|
| 300 |
app, _, stdout, _ := newTestApp() |
| 301 |
|
| 302 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename, "--user", "philipp:mypass"})) |
| 303 |
|
| 304 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 305 |
} |
| 306 |
|
| 307 |
func TestCLI_Subscribe_Token_And_UserPass(t *testing.T) { |
| 308 |
app, _, _, _ := newTestApp() |
| 309 |
err := app.Run([]string{"ntfy", "subscribe", "--poll", "--token", "tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2", "--user", "philipp:mypass", "mytopic", "triggered"}) |
| 310 |
require.Error(t, err) |
| 311 |
require.Equal(t, "cannot set both --user and --token", err.Error()) |
| 312 |
} |
| 313 |
|
| 314 |
func TestCLI_Subscribe_Default_Token(t *testing.T) { |
| 315 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 316 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 317 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 318 |
require.Equal(t, "Bearer tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2", r.Header.Get("Authorization")) |
| 319 |
|
| 320 |
w.WriteHeader(http.StatusOK) |
| 321 |
w.Write([]byte(message)) |
| 322 |
})) |
| 323 |
defer server.Close() |
| 324 |
|
| 325 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 326 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 327 |
default-host: %s |
| 328 |
default-token: tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2 |
| 329 |
`, server.URL)), 0600)) |
| 330 |
|
| 331 |
app, _, stdout, _ := newTestApp() |
| 332 |
|
| 333 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename, "mytopic"})) |
| 334 |
|
| 335 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 336 |
} |
| 337 |
|
| 338 |
func TestCLI_Subscribe_Default_UserPass(t *testing.T) { |
| 339 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 340 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 341 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 342 |
require.Equal(t, "Basic cGhpbGlwcDpteXBhc3M=", r.Header.Get("Authorization")) |
| 343 |
|
| 344 |
w.WriteHeader(http.StatusOK) |
| 345 |
w.Write([]byte(message)) |
| 346 |
})) |
| 347 |
defer server.Close() |
| 348 |
|
| 349 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 350 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 351 |
default-host: %s |
| 352 |
default-user: philipp |
| 353 |
default-password: mypass |
| 354 |
`, server.URL)), 0600)) |
| 355 |
|
| 356 |
app, _, stdout, _ := newTestApp() |
| 357 |
|
| 358 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename, "mytopic"})) |
| 359 |
|
| 360 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 361 |
} |
| 362 |
|
| 363 |
func TestCLI_Subscribe_Override_Default_UserPass_With_Empty_UserPass(t *testing.T) { |
| 364 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 365 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 366 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 367 |
require.Equal(t, "", r.Header.Get("Authorization")) |
| 368 |
|
| 369 |
w.WriteHeader(http.StatusOK) |
| 370 |
w.Write([]byte(message)) |
| 371 |
})) |
| 372 |
defer server.Close() |
| 373 |
|
| 374 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 375 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 376 |
default-host: %s |
| 377 |
default-user: philipp |
| 378 |
default-password: mypass |
| 379 |
subscribe: |
| 380 |
- topic: mytopic |
| 381 |
user: "" |
| 382 |
password: "" |
| 383 |
`, server.URL)), 0600)) |
| 384 |
|
| 385 |
app, _, stdout, _ := newTestApp() |
| 386 |
|
| 387 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename})) |
| 388 |
|
| 389 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 390 |
} |
| 391 |
|
| 392 |
func TestCLI_Subscribe_Override_Default_Token_With_Empty_Token(t *testing.T) { |
| 393 |
message := `{"id":"RXIQBFaieLVr","time":124,"expires":1124,"event":"message","topic":"mytopic","message":"triggered"}` |
| 394 |
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 395 |
require.Equal(t, "/mytopic/json", r.URL.Path) |
| 396 |
require.Equal(t, "", r.Header.Get("Authorization")) |
| 397 |
|
| 398 |
w.WriteHeader(http.StatusOK) |
| 399 |
w.Write([]byte(message)) |
| 400 |
})) |
| 401 |
defer server.Close() |
| 402 |
|
| 403 |
filename := filepath.Join(t.TempDir(), "client.yml") |
| 404 |
require.Nil(t, os.WriteFile(filename, []byte(fmt.Sprintf(` |
| 405 |
default-host: %s |
| 406 |
default-token: tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2 |
| 407 |
subscribe: |
| 408 |
- topic: mytopic |
| 409 |
token: "" |
| 410 |
`, server.URL)), 0600)) |
| 411 |
|
| 412 |
app, _, stdout, _ := newTestApp() |
| 413 |
|
| 414 |
require.Nil(t, app.Run([]string{"ntfy", "subscribe", "--poll", "--from-config", "--config=" + filename})) |
| 415 |
|
| 416 |
require.Equal(t, message, strings.TrimSpace(stdout.String())) |
| 417 |
} |