-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up displayed paths when encountering archives (#217)
* Clean up displayed paths when encountering archives * Use separate functions; add tests * Remove print * Use the convenient archive root when cleaning archive paths Signed-off-by: egibs <[email protected]> * Clean up paths inside archive * Clean up test Signed-off-by: egibs <[email protected]> --------- Signed-off-by: egibs <[email protected]> Co-authored-by: egibs <[email protected]>
- Loading branch information
Showing
4 changed files
with
105 additions
and
13 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
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,69 @@ | ||
package action | ||
|
||
import "testing" | ||
|
||
func TestCleanPath(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
path string | ||
prefix string | ||
want string | ||
}{ | ||
{ | ||
name: "linux", | ||
path: "/tmp/static3980366648/usr/share/zoneinfo/zone1970", | ||
prefix: "/tmp/static3980366648/", | ||
want: "usr/share/zoneinfo/zone1970", | ||
}, | ||
{ | ||
name: "macOS", | ||
path: "/var/folders/3g/88131l9j11x995ppjbxsvhbh0000gn/T/apko_0.13.2_linux_arm64.tar.gz2526862474/apko_0.13.2_linux_arm64/apko", | ||
prefix: "/var/folders/3g/88131l9j11x995ppjbxsvhbh0000gn/T/apko_0.13.2_linux_arm64.tar.gz2526862474/", | ||
want: "apko_0.13.2_linux_arm64/apko", | ||
}, | ||
{ | ||
name: "windows", | ||
path: "C:\\Users\\abc\\AppData\\Local\\Temp\\static3980366648\\usr\\share\\zoneinfo\\zone1970", | ||
prefix: "C:\\Users\\abc\\AppData\\Local\\Temp\\static3980366648\\", | ||
want: "usr\\share\\zoneinfo\\zone1970", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := cleanPath(tt.path, tt.prefix); got != tt.want { | ||
t.Errorf("CleanPath() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestFormatPath(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
path string | ||
want string | ||
}{ | ||
{ | ||
name: "single separator", | ||
path: "/apko_0.13.2_linux_arm64/apko", | ||
want: "apko_0.13.2_linux_arm64/apko", | ||
}, | ||
{ | ||
name: "multiple separators", | ||
path: "/usr/share/zoneinfo/zone1970", | ||
want: "usr/share/zoneinfo/zone1970", | ||
}, | ||
{ | ||
name: "multiple windows separators", | ||
path: "\\usr\\share\\zoneinfo\\zone1970", | ||
want: "usr/share/zoneinfo/zone1970", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := formatPath(tt.path); got != tt.want { | ||
t.Errorf("FormatPath() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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,4 +1,5 @@ | ||
|
||
# testdata/apko_nested.tar.gz ∴ apko_0.13.2_linux_arm64/apko | ||
archives/zip | ||
combo/dropper/shell | ||
combo/stealer/ssh | ||
|