Skip to content

Commit

Permalink
fix: app storage filename references for xcuitest simulators (#859)
Browse files Browse the repository at this point in the history
* fix: app storage filename references for xcuitest simulators

* refactor: align function names

* docs: engrish
  • Loading branch information
alexplischke authored Nov 29, 2023
1 parent e84ec40 commit 09a2a7f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions internal/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

var (
reFileID = regexp.MustCompile(`(storage:(//)?)?(?P<fileID>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})$`)
reFilePattern = regexp.MustCompile(`^(storage:filename=)(?P<filename>[\S][\S ]+(\.ipa|\.apk))$`)
reFilePattern = regexp.MustCompile(`^(storage:filename=)(?P<filename>[\S][\S ]+(\.ipa|\.apk|\.zip))$`)
reHTTPSchemePattern = regexp.MustCompile(`(?i)^https?`)
)

Expand All @@ -36,20 +36,20 @@ func IsStorageReference(link string) bool {
return reFileID.MatchString(link) || reFilePattern.MatchString(link)
}

// StandardizeReferenceLink standardize the provided storageID reference to make it work for VMD and RDC.
func StandardizeReferenceLink(storageRef string) string {
if reFileID.MatchString(storageRef) {
if !strings.HasPrefix(storageRef, "storage:") {
return fmt.Sprintf("storage:%s", storageRef)
// NormalizeStorageReference normalizes ref to work across VMD and RDC.
func NormalizeStorageReference(ref string) string {
if reFileID.MatchString(ref) {
if !strings.HasPrefix(ref, "storage:") {
return fmt.Sprintf("storage:%s", ref)
}
if strings.HasPrefix(storageRef, "storage://") {
return strings.Replace(storageRef, "storage://", "storage:", 1)
if strings.HasPrefix(ref, "storage://") {
return strings.Replace(ref, "storage://", "storage:", 1)
}
}
return storageRef
return ref
}

// Validate validates that the apps is valid (storageID / File / URL).
// Validate validates that app is valid (storageID / File / URL).
func Validate(kind, app string, validExt []string) error {
if IsStorageReference(app) {
return nil
Expand Down
6 changes: 3 additions & 3 deletions internal/apps/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func TestIsStorageReference(t *testing.T) {
args: args{
link: "storage:filename=dummyfilename.zip",
},
want: false,
want: true,
},
{
name: "Bad Reference",
Expand Down Expand Up @@ -257,8 +257,8 @@ func TestStandardizeReferenceLink(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := StandardizeReferenceLink(tt.storageRef); got != tt.want {
t.Errorf("StandardizeReferenceLink() = %v, want %v", got, tt.want)
if got := NormalizeStorageReference(tt.storageRef); got != tt.want {
t.Errorf("NormalizeStorageReference() = %v, want %v", got, tt.want)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/saucecloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func (r *CloudRunner) uploadProject(filename, description string, pType uploadTy
}

if apps.IsStorageReference(filename) {
return apps.StandardizeReferenceLink(filename), nil
return apps.NormalizeStorageReference(filename), nil
}

if apps.IsRemote(filename) {
Expand Down

0 comments on commit 09a2a7f

Please sign in to comment.