-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
213 additions
and
30 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
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