-
Notifications
You must be signed in to change notification settings - Fork 285
Add test for tar2ext layer expansion #990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,90 @@ | ||
| package tar2ext4 | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "archive/tar" | ||
| "os" | ||
| "strings" | ||
| "time" | ||
| ) | ||
|
|
||
| // Test_UnorderedTarExpansion tests that we are correctly able to expand a layer tar file | ||
| // which has one or many files in an unordered fashion. By unordered we mean that the | ||
| // entry of a file shows up during an expansion before the entry of one of the parent | ||
| // directories of that file. In such cases we create that parent directory with same | ||
| // permissions as its parent and then later on fix the permissions when we actually see | ||
| // the entry of that parent directory. | ||
| func Test_UnorderedTarExpansion(t *testing.T) { | ||
| tmpTarFilePath := filepath.Join(os.TempDir(), "test-layer.tar") | ||
| layerTar, err := os.Create(tmpTarFilePath) | ||
| if err != nil { | ||
| t.Fatalf("failed to create output file: %s", err) | ||
| } | ||
| defer os.Remove(tmpTarFilePath) | ||
|
|
||
| tw := tar.NewWriter(layerTar) | ||
| var files = []struct { | ||
| path, body string | ||
| }{ | ||
| {"data/", ""}, | ||
| {"root.txt", "inside root.txt"}, | ||
| {"foo/bar.txt", "inside bar.txt"}, | ||
| {"foo/", ""}, | ||
| {"A/B/b.txt", "inside b.txt"}, | ||
| {"A/a.txt", "inside a.txt"}, | ||
| {"A/", ""}, | ||
| {"A/B/", ""}, | ||
| } | ||
| for _, file := range files { | ||
| var hdr *tar.Header | ||
| if strings.HasSuffix(file.path, "/") { | ||
| hdr = &tar.Header{ | ||
| Name: file.path, | ||
| Mode: 0777, | ||
| Size: 0, | ||
| ModTime: time.Now(), | ||
| AccessTime: time.Now(), | ||
| ChangeTime: time.Now(), | ||
| } | ||
| } else { | ||
| hdr = &tar.Header{ | ||
| Name: file.path, | ||
| Mode: 0777, | ||
| Size: int64(len(file.body)), | ||
| ModTime: time.Now(), | ||
| AccessTime: time.Now(), | ||
| ChangeTime: time.Now(), | ||
| } | ||
| } | ||
| if err := tw.WriteHeader(hdr); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if !strings.HasSuffix(file.path, "/") { | ||
| if _, err := tw.Write([]byte(file.body)); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| } | ||
| } | ||
| if err := tw.Close(); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| // Now try to import this tar and verify that there is no failure. | ||
| if _, err := layerTar.Seek(0, 0); err != nil { | ||
| t.Fatalf("failed to seek file: %s", err) | ||
| } | ||
|
|
||
| opts := []Option{AppendVhdFooter, ConvertWhiteout} | ||
| tmpVhdPath := filepath.Join(os.TempDir(), "test-vhd.vhdx") | ||
| layerVhd, err := os.Create(tmpVhdPath) | ||
| if err != nil { | ||
| t.Fatalf("failed to create output VHD: %s", err) | ||
| } | ||
| defer os.Remove(tmpVhdPath) | ||
|
|
||
| if err := Convert(layerTar, layerVhd, opts...); err != nil { | ||
| t.Fatalf("failed to convert tar to layer vhd: %s", err) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.