(t *testing.T)
| 143 | } |
| 144 | |
| 145 | func TestRemoveCopilot(t *testing.T) { |
| 146 | t.Run("removes existing install directory", func(t *testing.T) { |
| 147 | // Create a temporary directory to simulate the install directory |
| 148 | tmpDir := t.TempDir() |
| 149 | installDir := filepath.Join(tmpDir, "copilot") |
| 150 | require.NoError(t, os.MkdirAll(installDir, 0755), "failed to create test directory") |
| 151 | // Create a dummy file in the directory |
| 152 | dummyFile := filepath.Join(installDir, "copilot") |
| 153 | require.NoError(t, os.WriteFile(dummyFile, []byte("test"), 0755), "failed to create test file") |
| 154 | |
| 155 | err := removeCopilot(installDir) |
| 156 | require.NoError(t, err, "unexpected error") |
| 157 | |
| 158 | _, err = os.Stat(installDir) |
| 159 | require.True(t, os.IsNotExist(err), "expected install directory to be removed") |
| 160 | }) |
| 161 | |
| 162 | t.Run("handles non-existent directory", func(t *testing.T) { |
| 163 | tmpDir := t.TempDir() |
| 164 | installDir := filepath.Join(tmpDir, "copilot") |
| 165 | |
| 166 | require.ErrorContains(t, removeCopilot(installDir), "failed to remove Copilot CLI") |
| 167 | }) |
| 168 | } |
| 169 | |
| 170 | // createTarGzBuffer creates a tar.gz archive in memory with the given files. |
| 171 | func createTarGzBuffer(t *testing.T, files map[string][]byte) []byte { |
nothing calls this directly
no test coverage detected