-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create zip reader using ditto tool * Unify default zip reader and the new ditto reader * Move internal zip package to ziputil * zip.ReadCloser.ReadFile now actualy read the file * Revert zip error type * Introduce IsErrFormat * Add tests for ditto reader * Renam zip to artifacts and ziputil to zip * Fix lint issue * Fix refactor issue * Add IsDittoReaderAvailable * Add some comment to the ditto command * Ditto zip reader: lazy extract archives * Benchmark test default and ditto zip readers * Introduce fallbackReader * Rename defaultRead to stdlibRead * Rename fallbackReader to defaultReader and add tests * Fix lint issues * Move stdlib and ditto zip readers to an internal package * Define ZipReadCloser interface on the client package (artifacts) * Update lint issue * Code cleanup
- Loading branch information
Showing
16 changed files
with
469 additions
and
411 deletions.
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 |
---|---|---|
@@ -1,32 +1,105 @@ | ||
package zip | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/bitrise-io/go-utils/v2/log" | ||
"github.com/bitrise-io/go-xcode/plistutil" | ||
"github.com/bitrise-io/go-xcode/profileutil" | ||
"github.com/bitrise-io/go-xcode/v2/_integration_tests" | ||
"github.com/bitrise-io/go-xcode/v2/artifacts" | ||
internalzip "github.com/bitrise-io/go-xcode/v2/internal/zip" | ||
"github.com/bitrise-io/go-xcode/v2/zip" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIPAReader(t *testing.T) { | ||
func TestIPAReader_DefaultZipReader(t *testing.T) { | ||
sampleArtifactsDir := _integration_tests.GetSampleArtifactsRepository(t) | ||
watchTestIPAPath := filepath.Join(sampleArtifactsDir, "ipas", "watch-test.ipa") | ||
|
||
r, err := zip.NewReader(watchTestIPAPath, log.NewLogger()) | ||
r, err := zip.NewDefaultReader(watchTestIPAPath, log.NewLogger()) | ||
require.NoError(t, err) | ||
defer func() { | ||
require.NoError(t, r.Close()) | ||
err := r.Close() | ||
require.NoError(t, err) | ||
}() | ||
|
||
ipaReader := zip.NewIPAReader(*r) | ||
plist, err := ipaReader.AppInfoPlist() | ||
require.NoError(t, err) | ||
plist, profile := readIPAWithStdlibZipReader(t, watchTestIPAPath) | ||
bundleID, _ := plist.GetString("CFBundleIdentifier") | ||
require.Equal(t, "bitrise.watch-test", bundleID) | ||
require.Equal(t, "XC iOS: *", profile.Name) | ||
} | ||
|
||
func TestIPAReader_StdlibZipReader(t *testing.T) { | ||
sampleArtifactsDir := _integration_tests.GetSampleArtifactsRepository(t) | ||
watchTestIPAPath := filepath.Join(sampleArtifactsDir, "ipas", "watch-test.ipa") | ||
|
||
plist, profile := readIPAWithStdlibZipReader(t, watchTestIPAPath) | ||
bundleID, _ := plist.GetString("CFBundleIdentifier") | ||
require.Equal(t, "bitrise.watch-test", bundleID) | ||
require.Equal(t, "XC iOS: *", profile.Name) | ||
} | ||
|
||
func TestIPAReader_DittoZipReader(t *testing.T) { | ||
sampleArtifactsDir := _integration_tests.GetSampleArtifactsRepository(t) | ||
watchTestIPAPath := filepath.Join(sampleArtifactsDir, "ipas", "watch-test.ipa") | ||
|
||
plist, profile := readIPAWithDittoZipReader(t, watchTestIPAPath) | ||
bundleID, _ := plist.GetString("CFBundleIdentifier") | ||
require.Equal(t, "bitrise.watch-test", bundleID) | ||
require.Equal(t, "XC iOS: *", profile.Name) | ||
} | ||
|
||
func Benchmark_ZipReaders(b *testing.B) { | ||
sampleArtifactsDir := _integration_tests.GetSampleArtifactsRepository(b) | ||
watchTestIPAPath := filepath.Join(sampleArtifactsDir, "ipas", "watch-test.ipa") | ||
|
||
for name, zipFunc := range map[string]readIPAFunc{ | ||
"dittoReader": func() (plistutil.PlistData, *profileutil.ProvisioningProfileInfoModel) { | ||
return readIPAWithDittoZipReader(b, watchTestIPAPath) | ||
}, | ||
"stdlibReader": func() (plistutil.PlistData, *profileutil.ProvisioningProfileInfoModel) { | ||
return readIPAWithStdlibZipReader(b, watchTestIPAPath) | ||
}, | ||
} { | ||
b.Run(fmt.Sprintf("Benchmarking %s", name), func(b *testing.B) { | ||
_, _ = zipFunc() | ||
}) | ||
} | ||
} | ||
|
||
type readIPAFunc func() (plistutil.PlistData, *profileutil.ProvisioningProfileInfoModel) | ||
|
||
func readIPAWithStdlibZipReader(t require.TestingT, archivePth string) (plistutil.PlistData, *profileutil.ProvisioningProfileInfoModel) { | ||
r, err := internalzip.NewStdlibRead(archivePth, log.NewLogger()) | ||
require.NoError(t, err) | ||
defer func() { | ||
err := r.Close() | ||
require.NoError(t, err) | ||
}() | ||
|
||
return readIPA(t, r) | ||
} | ||
|
||
func readIPAWithDittoZipReader(t require.TestingT, archivePth string) (plistutil.PlistData, *profileutil.ProvisioningProfileInfoModel) { | ||
r := internalzip.NewDittoReader(archivePth, log.NewLogger()) | ||
defer func() { | ||
err := r.Close() | ||
require.NoError(t, err) | ||
}() | ||
|
||
return readIPA(t, r) | ||
} | ||
|
||
func readIPA(t require.TestingT, zipReader artifacts.ZipReadCloser) (plistutil.PlistData, *profileutil.ProvisioningProfileInfoModel) { | ||
ipaReader := artifacts.NewIPAReader(zipReader) | ||
plist, err := ipaReader.AppInfoPlist() | ||
require.NoError(t, err) | ||
|
||
profile, err := ipaReader.ProvisioningProfileInfo() | ||
require.NoError(t, err) | ||
require.Equal(t, "XC iOS: *", profile.Name) | ||
|
||
return plist, profile | ||
} |
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
10 changes: 6 additions & 4 deletions
10
zip/ios_xcarchive_reader.go → artifacts/ios_xcarchive_reader.go
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
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,7 @@ | ||
package artifacts | ||
|
||
// ZipReadCloser ... | ||
type ZipReadCloser interface { | ||
ReadFile(relPthPattern string) ([]byte, error) | ||
Close() error | ||
} |
Oops, something went wrong.