-
Notifications
You must be signed in to change notification settings - Fork 244
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
Support dev.odo.push.path:*
attributes on Podman
#6576
Merged
openshift-merge-robot
merged 6 commits into
redhat-developer:main
from
rm3l:6492-support-dev.odo.push.path-attribute-on-podman
Feb 8, 2023
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b31025e
Pick the right command attributes when searching for attributes prefi…
rm3l 6a4f5f6
Test 'dev.odo.push.path' attribute using debug commands
rm3l 7ec3701
Extract GetSyncFilesFromAttributes as an exported function in adapters
rm3l ef6f951
Support 'dev.odo.push.path' attribute on Podman
rm3l a16059d
Update documentation
rm3l d1a7381
fixup! Extract GetSyncFilesFromAttributes as an exported function in …
rm3l File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 5 additions & 3 deletions
8
...ioned_docs/version-2.5.0/tutorials/using-devfile-odo.dev.push.path-attribute.md
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,23 @@ | ||
package adapters | ||
|
||
import ( | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" | ||
) | ||
|
||
const _devPushPathAttributePrefix = "dev.odo.push.path:" | ||
|
||
// GetSyncFilesFromAttributes gets the target files and folders along with their respective remote destination from the devfile. | ||
// It uses the "dev.odo.push.path:" attribute prefix, if any, in the specified command. | ||
func GetSyncFilesFromAttributes(command v1alpha2.Command) map[string]string { | ||
syncMap := make(map[string]string) | ||
for key, value := range command.Attributes.Strings(nil) { | ||
if strings.HasPrefix(key, _devPushPathAttributePrefix) { | ||
localValue := strings.ReplaceAll(key, _devPushPathAttributePrefix, "") | ||
syncMap[filepath.Clean(localValue)] = filepath.ToSlash(filepath.Clean(value)) | ||
} | ||
} | ||
return syncMap | ||
} |
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 adapters | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" | ||
"github.com/devfile/api/v2/pkg/attributes" | ||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestGetSyncFilesFromAttributes(t *testing.T) { | ||
type args struct { | ||
command v1alpha2.Command | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string]string | ||
}{ | ||
{ | ||
name: "no attributes", | ||
args: args{ | ||
command: v1alpha2.Command{}, | ||
}, | ||
want: make(map[string]string), | ||
}, | ||
{ | ||
name: "no matching attributes", | ||
args: args{ | ||
command: v1alpha2.Command{ | ||
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{ | ||
"some-custom-attribute-key": "some-value", | ||
"another-custom-attribute-key": "some-value", | ||
}), | ||
}, | ||
}, | ||
want: make(map[string]string), | ||
}, | ||
{ | ||
name: "dev.odo.push.path attribute key", | ||
args: args{ | ||
command: v1alpha2.Command{ | ||
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{ | ||
"dev.odo.push.path": "some-value", | ||
}), | ||
}, | ||
}, | ||
want: make(map[string]string), | ||
}, | ||
{ | ||
name: "attribute with only matching prefix as key", | ||
args: args{ | ||
command: v1alpha2.Command{ | ||
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{ | ||
_devPushPathAttributePrefix: "server/", | ||
}), | ||
}, | ||
}, | ||
want: map[string]string{ | ||
".": "server", | ||
}, | ||
}, | ||
{ | ||
name: "multiple matching attributes", | ||
args: args{ | ||
command: v1alpha2.Command{ | ||
Attributes: attributes.Attributes{}.FromStringMap(map[string]string{ | ||
"some-custom-attribute-key": "some-value", | ||
_devPushPathAttributePrefix + "server.js": "server/server.js", | ||
"some-other-custom-attribute-key": "some-value", | ||
_devPushPathAttributePrefix + "some-path/README": "another/nested/path/README.md", | ||
_devPushPathAttributePrefix + "random-file.txt": "/tmp/rand-file.txt", | ||
}), | ||
}, | ||
}, | ||
want: map[string]string{ | ||
"server.js": "server/server.js", | ||
"some-path/README": "another/nested/path/README.md", | ||
"random-file.txt": "/tmp/rand-file.txt", | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := GetSyncFilesFromAttributes(tt.args.command) | ||
if diff := cmp.Diff(tt.want, got); diff != "" { | ||
t.Errorf("GetSyncFilesFromAttributes() mismatch (-want +got):\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we move
cmdName
along withcmdKind
as well for a better readability?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.
Done in
d1a7381
(#6576)