Skip to content

Commit 78e6b28

Browse files
committed
add unit test
Signed-off-by: Stephanie <[email protected]>
1 parent b7908ba commit 78e6b28

File tree

2 files changed

+311
-44
lines changed

2 files changed

+311
-44
lines changed

pkg/devfile/parser/parse.go

+9-17
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
"github.com/pkg/errors"
2020
)
2121

22-
23-
2422
// ParseDevfile func validates the devfile integrity.
2523
// Creates devfile context and runtime objects
2624
func parseDevfile(d DevfileObj, flattenedDevfile bool) (DevfileObj, error) {
@@ -180,36 +178,30 @@ func parseParentAndPlugin(d DevfileObj) (err error) {
180178
return nil
181179
}
182180

183-
184-
185-
func parseFromURI(uri string, curDevfile DevfileObj) (DevfileObj, error){
181+
func parseFromURI(uri string, curDevfile DevfileObj) (DevfileObj, error) {
186182
// validate URI
187183

188184
// absolute URL address
189185
if strings.HasPrefix(uri, "http://") || strings.HasPrefix(uri, "https://") {
190186
return ParseFromURL(uri)
191187
}
192188

193-
// absolute path on disk
194-
if strings.HasPrefix(uri, "file://") {
195-
return Parse(strings.TrimPrefix(uri, "file://"))
196-
}
197-
198189
// relative path on disk
199-
if curDevfile.Ctx.GetAbsPath() != ""{
200-
// parse uri receives a relative path and resolves abspath
201-
return Parse(uri)
190+
if curDevfile.Ctx.GetAbsPath() != "" {
191+
192+
return Parse(path.Join(path.Dir(curDevfile.Ctx.GetAbsPath()), uri))
202193
}
203194

204-
if curDevfile.Ctx.GetURL() != ""{
195+
if curDevfile.Ctx.GetURL() != "" {
205196
u, err := url.Parse(curDevfile.Ctx.GetURL())
206-
if err!= nil {
197+
if err != nil {
207198
return DevfileObj{}, err
208199
}
209-
u.Path = path.Join(u.Path, uri)
200+
201+
u.Path = path.Join(path.Dir(u.Path), uri)
210202
jointURL := u.String()
211203
return ParseFromURL(jointURL)
212204
}
213205

214206
return DevfileObj{}, fmt.Errorf("fail to parse from uri: %s", uri)
215-
}
207+
}

0 commit comments

Comments
 (0)