aboutsummaryrefslogtreecommitdiffstats
path: root/jar
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-09-27 15:06:19 -0700
committerColin Cross <ccross@android.com>2018-09-28 13:56:06 -0700
commit05518bc13b3cd31e6cb7158a41aa124b224c3bc4 (patch)
tree65dbf6c09827df7f23d973ef6419fea543580d52 /jar
parentb051ab5cb54f8802807680a8fb24092b445a3ddb (diff)
downloadbuild_soong-05518bc13b3cd31e6cb7158a41aa124b224c3bc4.tar.gz
build_soong-05518bc13b3cd31e6cb7158a41aa124b224c3bc4.tar.bz2
build_soong-05518bc13b3cd31e6cb7158a41aa124b224c3bc4.zip
soong_zip: Add tests
Add test that cover basic command line usage of soong_zip. -D is not covered yet as the implementation will be replaced with one that is also more easily testable in the next patch. Bug: 116751500 Test: zip_test.go Change-Id: I5a1bcee74ebc9cb3cf332c36f89bc12c0e807ad2
Diffstat (limited to 'jar')
-rw-r--r--jar/jar.go28
1 files changed, 8 insertions, 20 deletions
diff --git a/jar/jar.go b/jar/jar.go
index 653e5eed..fa0e6935 100644
--- a/jar/jar.go
+++ b/jar/jar.go
@@ -17,7 +17,6 @@ package jar
import (
"bytes"
"fmt"
- "io/ioutil"
"os"
"strings"
"time"
@@ -81,10 +80,9 @@ func MetaDirFileHeader() *zip.FileHeader {
return dirHeader
}
-// Convert manifest source path to zip header and contents. If path is empty uses a default
-// manifest.
-func ManifestFileContents(src string) (*zip.FileHeader, []byte, error) {
- b, err := manifestContents(src)
+// Create a manifest zip header and contents using the provided contents if any.
+func ManifestFileContents(contents []byte) (*zip.FileHeader, []byte, error) {
+ b, err := manifestContents(contents)
if err != nil {
return nil, nil, err
}
@@ -100,26 +98,16 @@ func ManifestFileContents(src string) (*zip.FileHeader, []byte, error) {
return fh, b, nil
}
-// Convert manifest source path to contents. If path is empty uses a default manifest.
-func manifestContents(src string) ([]byte, error) {
- var givenBytes []byte
- var err error
-
- if src != "" {
- givenBytes, err = ioutil.ReadFile(src)
- if err != nil {
- return nil, err
- }
- }
-
+// Create manifest contents, using the provided contents if any.
+func manifestContents(contents []byte) ([]byte, error) {
manifestMarker := []byte("Manifest-Version:")
header := append(manifestMarker, []byte(" 1.0\nCreated-By: soong_zip\n")...)
var finalBytes []byte
- if !bytes.Contains(givenBytes, manifestMarker) {
- finalBytes = append(append(header, givenBytes...), byte('\n'))
+ if !bytes.Contains(contents, manifestMarker) {
+ finalBytes = append(append(header, contents...), byte('\n'))
} else {
- finalBytes = givenBytes
+ finalBytes = contents
}
return finalBytes, nil