|
4 | 4 | package config |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "os" |
| 8 | + "path/filepath" |
| 9 | + "reflect" |
| 10 | + "strings" |
| 11 | + "testing" |
| 12 | + |
7 | 13 | . "github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig" |
8 | 14 | "github.com/microsoft/go-sqlcmd/internal/output" |
9 | 15 | "github.com/microsoft/go-sqlcmd/internal/pal" |
10 | 16 | "github.com/microsoft/go-sqlcmd/internal/secret" |
11 | 17 | "github.com/stretchr/testify/assert" |
12 | | - "os" |
13 | | - "reflect" |
14 | | - "strings" |
15 | | - "testing" |
| 18 | + "github.com/stretchr/testify/require" |
16 | 19 | ) |
17 | 20 |
|
18 | 21 | func TestConfig(t *testing.T) { |
@@ -380,6 +383,32 @@ func TestConfig_GetCurrentContextEndPointNotFoundPanic(t *testing.T) { |
380 | 383 | }) |
381 | 384 | } |
382 | 385 |
|
| 386 | +func TestSetFileName_RejectsNonYAMLExtension(t *testing.T) { |
| 387 | + var gotErr error |
| 388 | + originalCallback := errorCallback |
| 389 | + errorCallback = func(err error) { gotErr = err } |
| 390 | + t.Cleanup(func() { errorCallback = originalCallback }) |
| 391 | + |
| 392 | + SetFileName("config.json") |
| 393 | + require.Error(t, gotErr) |
| 394 | + assert.Contains(t, gotErr.Error(), ".json") |
| 395 | + |
| 396 | + gotErr = nil |
| 397 | + SetFileName("config.toml") |
| 398 | + require.Error(t, gotErr) |
| 399 | + assert.Contains(t, gotErr.Error(), ".toml") |
| 400 | + |
| 401 | + tempDir := t.TempDir() |
| 402 | + |
| 403 | + gotErr = nil |
| 404 | + SetFileName(filepath.Join(tempDir, t.Name()+".yaml")) |
| 405 | + assert.NoError(t, gotErr) |
| 406 | + |
| 407 | + gotErr = nil |
| 408 | + SetFileName(filepath.Join(tempDir, t.Name()+".yml")) |
| 409 | + assert.NoError(t, gotErr) |
| 410 | +} |
| 411 | + |
383 | 412 | func TestConfig_DeleteContextThatDoesNotExist(t *testing.T) { |
384 | 413 | assert.Panics(t, func() { |
385 | 414 | contextOrdinal("does-not-exist") |
|
0 commit comments