-
Notifications
You must be signed in to change notification settings - Fork 248
cmd, pkg/podman: Introduce Image Interface and Unit Tests #1724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ type Image interface { | |
| Labels() map[string]string | ||
| Name() string | ||
| Names() []string | ||
|
DaliborKr marked this conversation as resolved.
|
||
| RepoTags() []string | ||
| } | ||
|
|
||
| type Images struct { | ||
|
|
@@ -37,10 +38,21 @@ type Images struct { | |
| } | ||
|
|
||
| type imageImages struct { | ||
| created string | ||
| id string | ||
| labels map[string]string | ||
| names []string | ||
| created string | ||
| id string | ||
| labels map[string]string | ||
| names []string | ||
| repoTags []string | ||
| } | ||
|
|
||
| type imageInspect struct { | ||
| created string | ||
| entrypoint []string | ||
| envVars []string | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like More importantly, don't we need to add methods to the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are right. I prepared fields I am not sure about adding methods for them to the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked it out to be sure, and it is true. The |
||
| id string | ||
| labels map[string]string | ||
| namesHistory []string | ||
| repoTags []string | ||
| } | ||
|
|
||
| type imageSlice []imageImages | ||
|
|
@@ -163,12 +175,24 @@ func (image *imageImages) Names() []string { | |
| return ret | ||
| } | ||
|
|
||
| func (image *imageImages) RepoTags() []string { | ||
| if image.repoTags == nil { | ||
| return nil | ||
| } | ||
|
|
||
| repoTagsCount := len(image.repoTags) | ||
| ret := make([]string, repoTagsCount) | ||
| copy(ret, image.repoTags) | ||
| return ret | ||
| } | ||
|
|
||
| func (image *imageImages) UnmarshalJSON(data []byte) error { | ||
| var raw struct { | ||
| Created interface{} | ||
| ID string | ||
| Labels map[string]string | ||
| Names []string | ||
| Created interface{} | ||
| ID string | ||
| Labels map[string]string | ||
| Names []string | ||
| RepoTags []string | ||
| } | ||
|
|
||
| if err := json.Unmarshal(data, &raw); err != nil { | ||
|
|
@@ -188,6 +212,103 @@ func (image *imageImages) UnmarshalJSON(data []byte) error { | |
| image.id = raw.ID | ||
| image.labels = raw.Labels | ||
| image.names = raw.Names | ||
| image.repoTags = raw.RepoTags | ||
| return nil | ||
| } | ||
|
|
||
| func (image *imageInspect) Created() string { | ||
| return image.created | ||
| } | ||
|
|
||
| func (image *imageInspect) Entrypoint() []string { | ||
| return image.entrypoint | ||
| } | ||
|
|
||
| func (image *imageInspect) EnvVars() []string { | ||
| return image.envVars | ||
| } | ||
|
|
||
| func (image *imageInspect) ID() string { | ||
| return image.id | ||
| } | ||
|
|
||
| func (image *imageInspect) IsToolbx() bool { | ||
| return isToolbx(image.labels) | ||
| } | ||
|
|
||
| func (image *imageInspect) Labels() map[string]string { | ||
| if image.labels == nil { | ||
| return nil | ||
| } | ||
|
|
||
| labelsCount := len(image.labels) | ||
| ret := make(map[string]string, labelsCount) | ||
| for label, value := range image.labels { | ||
| ret[label] = value | ||
| } | ||
|
|
||
| return ret | ||
| } | ||
|
|
||
| func (image *imageInspect) Names() []string { | ||
| if image.namesHistory == nil { | ||
| return nil | ||
| } | ||
|
|
||
| namesHistoryCount := len(image.namesHistory) | ||
| ret := make([]string, namesHistoryCount) | ||
| copy(ret, image.namesHistory) | ||
| return ret | ||
| } | ||
|
|
||
| func (image *imageInspect) Name() string { | ||
| if len(image.namesHistory) == 0 { | ||
| panic("no name is available in Image name history") | ||
| } | ||
| return image.namesHistory[0] | ||
| } | ||
|
|
||
| func (image *imageInspect) RepoTags() []string { | ||
| if image.repoTags == nil { | ||
| return nil | ||
| } | ||
|
|
||
| repoTagsCount := len(image.repoTags) | ||
| ret := make([]string, repoTagsCount) | ||
| copy(ret, image.repoTags) | ||
| return ret | ||
| } | ||
|
|
||
| func (image *imageInspect) UnmarshalJSON(data []byte) error { | ||
| var raw struct { | ||
| Created interface{} | ||
| ID string | ||
| Config struct { | ||
| Labels map[string]string | ||
| Env []string | ||
| Entrypoint []string | ||
| } | ||
| NamesHistory []string | ||
| RepoTags []string | ||
| } | ||
|
|
||
| if err := json.Unmarshal(data, &raw); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| switch value := raw.Created.(type) { | ||
| case string: | ||
| image.created = value | ||
| case float64: | ||
| image.created = utils.HumanDuration(int64(value)) | ||
| } | ||
|
|
||
| image.id = raw.ID | ||
| image.labels = raw.Config.Labels | ||
| image.envVars = raw.Config.Env | ||
| image.namesHistory = raw.NamesHistory | ||
| image.repoTags = raw.RepoTags | ||
| image.entrypoint = raw.Config.Entrypoint | ||
| return nil | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.