-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20572 from baude/ocirefactor
Refactor key machine objects
- Loading branch information
Showing
33 changed files
with
783 additions
and
657 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
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,91 @@ | ||
package compression | ||
|
||
import "testing" | ||
|
||
func Test_compressionFromFile(t *testing.T) { | ||
type args struct { | ||
path string | ||
} | ||
var tests = []struct { | ||
name string | ||
args args | ||
want ImageCompression | ||
}{ | ||
{ | ||
name: "xz", | ||
args: args{ | ||
path: "/tmp/foo.xz", | ||
}, | ||
want: Xz, | ||
}, | ||
{ | ||
name: "gzip", | ||
args: args{ | ||
path: "/tmp/foo.gz", | ||
}, | ||
want: Gz, | ||
}, | ||
{ | ||
name: "bz2", | ||
args: args{ | ||
path: "/tmp/foo.bz2", | ||
}, | ||
want: Bz2, | ||
}, | ||
{ | ||
name: "default is xz", | ||
args: args{ | ||
path: "/tmp/foo", | ||
}, | ||
want: Xz, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := KindFromFile(tt.args.path); got != tt.want { | ||
t.Errorf("KindFromFile() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestImageCompression_String(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
c ImageCompression | ||
want string | ||
}{ | ||
{ | ||
name: "xz", | ||
c: Xz, | ||
want: "xz", | ||
}, | ||
{ | ||
name: "gz", | ||
c: Gz, | ||
want: "gz", | ||
}, | ||
{ | ||
name: "bz2", | ||
c: Bz2, | ||
want: "bz2", | ||
}, | ||
{ | ||
name: "zip", | ||
c: Zip, | ||
want: "zip", | ||
}, | ||
{ | ||
name: "xz is default", | ||
c: 99, | ||
want: "xz", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.c.String(); got != tt.want { | ||
t.Errorf("String() = %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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package compression | ||
|
||
import "strings" | ||
|
||
type ImageCompression int64 | ||
|
||
const ( | ||
Xz ImageCompression = iota | ||
Zip | ||
Gz | ||
Bz2 | ||
) | ||
|
||
func KindFromFile(path string) ImageCompression { | ||
switch { | ||
case strings.HasSuffix(path, Bz2.String()): | ||
return Bz2 | ||
case strings.HasSuffix(path, Gz.String()): | ||
return Gz | ||
case strings.HasSuffix(path, Zip.String()): | ||
return Zip | ||
} | ||
return Xz | ||
} | ||
|
||
func (c ImageCompression) String() string { | ||
switch c { | ||
case Gz: | ||
return "gz" | ||
case Zip: | ||
return "zip" | ||
case Bz2: | ||
return "bz2" | ||
} | ||
return "xz" | ||
} |
Oops, something went wrong.
57dbd61
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
podman-next COPR build failed. @containers/packit-build please check.