-
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
Add command to provide starter project information #3173
Merged
openshift-merge-robot
merged 10 commits into
redhat-developer:master
from
skoh7645:fix3005
Jun 26, 2020
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fd9f40d
add command to provide starter project information
skoh7645 ac6747a
update test result
skoh7645 3848183
update tests
skoh7645 442d9bb
only print projects from devfile
skoh7645 59fbf8b
abstract out code into functions as requested
skoh7645 6cab3a6
resolve merge conflicts
skoh7645 0a9fcb1
requested changes
skoh7645 8ac0ba7
simplify return statement
skoh7645 6c3d449
update test for java-openliberty
skoh7645 c9aeb0d
resolve merge conflicts
skoh7645 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
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 |
---|---|---|
|
@@ -45,7 +45,7 @@ func hasPrefix(buf []byte, prefix []byte) bool { | |
return bytes.HasPrefix(trim, prefix) | ||
} | ||
|
||
// SetDevfileContent reads devfile and if devfile is in YAML format converts is to JSON | ||
// SetDevfileContent reads devfile and if devfile is in YAML format converts it to JSON | ||
func (d *DevfileCtx) SetDevfileContent() error { | ||
|
||
// Read devfile | ||
|
@@ -55,7 +55,14 @@ func (d *DevfileCtx) SetDevfileContent() error { | |
return errors.Wrapf(err, "failed to read devfile from path '%s'", d.absPath) | ||
} | ||
|
||
// set devfile content | ||
return d.SetDevfileContentFromBytes(data) | ||
} | ||
|
||
// SetDevfileContentFromBytes sets devfile content from byte input | ||
func (d *DevfileCtx) SetDevfileContentFromBytes(data []byte) error { | ||
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. This function should be called from SetDevfileContent once bytes are extracted from file to avoid code duplication 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. Done |
||
// If YAML file convert it to JSON | ||
var err error | ||
d.rawContent, err = YAMLToJSON(data) | ||
if err != nil { | ||
return err | ||
|
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,100 @@ | ||
package parser | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/openshift/odo/pkg/testingutil/filesystem" | ||
) | ||
|
||
func TestPopulateFromBytes(t *testing.T) { | ||
|
||
const ( | ||
InvalidDevfilePath = "/invalid/path" | ||
) | ||
|
||
// createTempDevfile helper creates temp devfile | ||
createTempDevfile := func(t *testing.T, content []byte, fakeFs filesystem.Filesystem) (f filesystem.File) { | ||
|
||
t.Helper() | ||
|
||
// Create tempfile | ||
f, err := fakeFs.TempFile(os.TempDir(), TempJSONDevfilePrefix) | ||
if err != nil { | ||
t.Errorf("failed to create temp devfile, %v", err) | ||
return f | ||
} | ||
|
||
// Write content to devfile | ||
if _, err := f.Write(content); err != nil { | ||
t.Errorf("failed to write to temp devfile") | ||
return f | ||
} | ||
|
||
// Successful | ||
return f | ||
} | ||
|
||
t.Run("valid data passed", func(t *testing.T) { | ||
|
||
var ( | ||
fakeFs = filesystem.NewFakeFs() | ||
tempDevfile = createTempDevfile(t, validJsonRawContent100(), fakeFs) | ||
d = DevfileCtx{ | ||
absPath: tempDevfile.Name(), | ||
Fs: fakeFs, | ||
} | ||
) | ||
defer os.Remove(tempDevfile.Name()) | ||
|
||
err := d.PopulateFromBytes(validJsonRawContent100()) | ||
|
||
if err != nil { | ||
t.Errorf("unexpected error '%v'", err) | ||
} | ||
|
||
if err := tempDevfile.Close(); err != nil { | ||
t.Errorf("failed to close temp devfile") | ||
} | ||
}) | ||
|
||
t.Run("invalid data passed", func(t *testing.T) { | ||
|
||
var ( | ||
fakeFs = filesystem.NewFakeFs() | ||
tempDevfile = createTempDevfile(t, []byte(validJsonRawContent100()), fakeFs) | ||
d = DevfileCtx{ | ||
absPath: tempDevfile.Name(), | ||
Fs: fakeFs, | ||
} | ||
) | ||
defer os.Remove(tempDevfile.Name()) | ||
|
||
err := d.PopulateFromBytes([]byte(InvalidDevfileContent)) | ||
|
||
if err == nil { | ||
t.Errorf("expected error, didn't get one ") | ||
} | ||
|
||
if err := tempDevfile.Close(); err != nil { | ||
t.Errorf("failed to close temp devfile") | ||
} | ||
}) | ||
|
||
t.Run("invalid filepath", func(t *testing.T) { | ||
|
||
var ( | ||
fakeFs = filesystem.NewFakeFs() | ||
d = DevfileCtx{ | ||
absPath: InvalidDevfilePath, | ||
Fs: fakeFs, | ||
} | ||
) | ||
|
||
err := d.SetDevfileContent() | ||
|
||
if err == nil { | ||
t.Errorf("expected an error, didn't get one") | ||
} | ||
}) | ||
} |
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
Oops, something went wrong.
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.
Seems like it would make sense to make all file/path based functions extract their bytes and then call the "in-memory" functions instead of more or less duplicating code at several levels to do the same kind of thing.
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.
I tried doing this but found that some commands ran a lot slower as we would have to download the file to memory every time :)
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.
OK, let's not do that right now then, I'll take a look once this is merged.