Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ijaz Ahmad
ksonnet
Commits
42e79860
Commit
42e79860
authored
Aug 27, 2018
by
GuessWhoSamFoo
Browse files
Fix sourcePath for imported json on root module
Signed-off-by:
GuessWhoSamFoo
<
sfoohei@gmail.com
>
parent
f45eed14
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
4 deletions
+81
-4
pkg/actions/import.go
pkg/actions/import.go
+0
-3
pkg/actions/import_test.go
pkg/actions/import_test.go
+62
-1
pkg/actions/testdata/import/my-service.json
pkg/actions/testdata/import/my-service.json
+19
-0
No files found.
pkg/actions/import.go
View file @
42e79860
...
...
@@ -271,9 +271,6 @@ func (i *Import) createComponentFromData(name, data string, templateType prototy
func
(
i
*
Import
)
createComponent
(
fileName
,
base
,
ext
string
,
templateType
prototype
.
TemplateType
)
error
{
var
name
bytes
.
Buffer
if
i
.
module
!=
""
{
name
.
WriteString
(
i
.
module
+
"/"
)
}
name
.
WriteString
(
strings
.
TrimSuffix
(
base
,
ext
))
...
...
pkg/actions/import_test.go
View file @
42e79860
...
...
@@ -76,7 +76,7 @@ func TestImport_http(t *testing.T) {
})
}
func
TestImport_file
(
t
*
testing
.
T
)
{
func
TestImport_
yaml_
file
(
t
*
testing
.
T
)
{
withApp
(
t
,
func
(
appMock
*
amocks
.
App
)
{
dataPath
:=
filepath
.
Join
(
"testdata"
,
"import"
,
"file.yaml"
)
serviceData
,
err
:=
ioutil
.
ReadFile
(
dataPath
)
...
...
@@ -111,6 +111,67 @@ func TestImport_file(t *testing.T) {
})
}
func
TestImport_json_file
(
t
*
testing
.
T
)
{
withApp
(
t
,
func
(
appMock
*
amocks
.
App
)
{
dataPath
:=
filepath
.
Join
(
"testdata"
,
"import"
,
"my-service.json"
)
serviceData
,
err
:=
ioutil
.
ReadFile
(
dataPath
)
require
.
NoError
(
t
,
err
)
path
:=
"/my-service.json"
stageFile
(
t
,
appMock
.
Fs
(),
"import/my-service.json"
,
path
)
cases
:=
[]
struct
{
name
string
module
string
path
string
expectedModule
string
}{
{
name
:
"root module"
,
module
:
"/"
,
expectedModule
:
"/"
,
},
{
name
:
"module"
,
module
:
"a"
,
expectedModule
:
"a"
,
},
{
name
:
"dot module"
,
module
:
"a.b"
,
expectedModule
:
"a.b"
,
},
}
for
_
,
tc
:=
range
cases
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
in
:=
map
[
string
]
interface
{}{
OptionApp
:
appMock
,
OptionModule
:
tc
.
module
,
OptionPath
:
path
,
}
a
,
err
:=
NewImport
(
in
)
require
.
NoError
(
t
,
err
)
a
.
createComponentFn
=
func
(
_
app
.
App
,
moduleName
,
name
,
text
string
,
p
params
.
Params
,
templateType
prototype
.
TemplateType
)
(
string
,
error
)
{
assert
.
Contains
(
t
,
name
,
"my-service"
)
assert
.
Equal
(
t
,
tc
.
expectedModule
,
moduleName
)
assert
.
Equal
(
t
,
string
(
serviceData
),
text
)
assert
.
Equal
(
t
,
params
.
Params
{},
p
)
assert
.
Equal
(
t
,
prototype
.
JSON
,
templateType
)
return
"/"
,
nil
}
err
=
a
.
Run
()
require
.
NoError
(
t
,
err
)
})
}
})
}
func
TestImport_directory
(
t
*
testing
.
T
)
{
withApp
(
t
,
func
(
appMock
*
amocks
.
App
)
{
dataPath
:=
filepath
.
Join
(
"testdata"
,
"import"
,
"file.yaml"
)
...
...
pkg/actions/testdata/import/my-service.json
0 → 100644
View file @
42e79860
{
"kind"
:
"Service"
,
"apiVersion"
:
"v1"
,
"metadata"
:
{
"name"
:
"my-service"
},
"spec"
:
{
"selector"
:
{
"app"
:
"MyApp"
},
"ports"
:
[
{
"protocol"
:
"TCP"
,
"port"
:
80
,
"targetPort"
:
9376
}
]
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment