-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
context: Fix directory leakage for snapshots contexts
Fix an error preventing the auto-unpacked snapshot files to be deleted. Add a unit-test to expose the issue. Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
- Loading branch information
1 parent
1a1bc99
commit 9840479
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// Use and distribution licensed under the Apache license version 2. | ||
// | ||
// See the COPYING file in the root project directory for full text. | ||
// | ||
|
||
package context_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/jaypipes/ghw/pkg/context" | ||
"github.com/jaypipes/ghw/pkg/option" | ||
) | ||
|
||
const ( | ||
testDataSnapshot = "../snapshot/testdata.tar.gz" | ||
) | ||
|
||
// nolint: gocyclo | ||
func TestSnapshotContext(t *testing.T) { | ||
ctx := context.New(option.WithSnapshot(option.SnapshotOptions{ | ||
Path: testDataSnapshot, | ||
})) | ||
|
||
var uncompressedDir string | ||
err := ctx.Do(func() error { | ||
uncompressedDir = ctx.Chroot | ||
return nil | ||
}) | ||
|
||
if len(uncompressedDir) == 0 { | ||
t.Fatalf("Expected the uncompressed dir path to not be empty") | ||
} | ||
if err != nil { | ||
t.Fatalf("Expected nil err, but got %v", err) | ||
} | ||
if _, err = os.Stat(uncompressedDir); !os.IsNotExist(err) { | ||
t.Fatalf("Expected the uncompressed dir to be deleted: %s", uncompressedDir) | ||
} | ||
} |