test: isolates temp test fixtures (#1569)
## Motivation and Context Replace shared temp paths with `t.TempDir()`` so each test gets its own cleanup-scoped directory. - This avoids leftover files and cross-test interference. No production code changed. ## How Has This Been Tested? GitHub CI passed. - https://github.com/yowainwright/registry/pull/1 ## Breaking Changes No breaking changes; just tests. ## Types of changes - [x] chore ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [x] My code follows the repository's style guidelines - [x] New and existing tests pass locally - [x] I have added appropriate error handling - [x] I have added or updated documentation as needed ## Additional context Small test-only cleanup. No production code paths are changed. Co-authored-by: Radoslav Dimitrov <radoslav@stacklok.com>
This commit is contained in:
parent
068a97a2f8
commit
dd4b2939e3
2 changed files with 16 additions and 33 deletions
|
|
@ -95,9 +95,7 @@ func SetupTestToken(t *testing.T, registryURL, token string) string {
|
|||
func CreateTestServerJSON(t *testing.T, serverJSON apiv0.ServerJSON) (string, string) {
|
||||
t.Helper()
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "mcp-publisher-test")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { os.RemoveAll(tempDir) })
|
||||
tempDir := t.TempDir()
|
||||
|
||||
jsonData, err := json.MarshalIndent(serverJSON, "", " ")
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -140,16 +140,13 @@ func TestValidateCommand_NoServerFile(t *testing.T) {
|
|||
server := SetupMockRegistryServer(t, nil, nil)
|
||||
SetupTestToken(t, server.URL, "test-token")
|
||||
|
||||
// Don't create server.json
|
||||
tempDir, err := os.MkdirTemp("", "mcp-publisher-test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
tempDir := t.TempDir()
|
||||
|
||||
originalDir, err := os.Getwd()
|
||||
require.NoError(t, err)
|
||||
defer func() { _ = os.Chdir(originalDir) }()
|
||||
|
||||
_ = os.Chdir(tempDir)
|
||||
require.NoError(t, os.Chdir(tempDir))
|
||||
|
||||
err = commands.ValidateCommand([]string{})
|
||||
|
||||
|
|
@ -161,15 +158,13 @@ func TestValidateCommand_InvalidJSON(t *testing.T) {
|
|||
server := SetupMockRegistryServer(t, nil, nil)
|
||||
SetupTestToken(t, server.URL, "test-token")
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "mcp-publisher-test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
tempDir := t.TempDir()
|
||||
|
||||
originalDir, err := os.Getwd()
|
||||
require.NoError(t, err)
|
||||
defer func() { _ = os.Chdir(originalDir) }()
|
||||
|
||||
_ = os.Chdir(tempDir)
|
||||
require.NoError(t, os.Chdir(tempDir))
|
||||
|
||||
// Create invalid JSON file
|
||||
err = os.WriteFile("server.json", []byte("{ invalid json }"), 0600)
|
||||
|
|
|
|||
Loading…
Reference in a new issue