Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Ijaz Ahmad
ksonnet
Commits
d2412116
Unverified
Commit
d2412116
authored
May 07, 2018
by
bryanl
Browse files
update e2e tests to handle imported object names
Signed-off-by:
bryanl
<
bryanliles@gmail.com
>
parent
d2ec8d00
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
177 additions
and
26 deletions
+177
-26
e2e/app.go
e2e/app.go
+40
-2
e2e/import_test.go
e2e/import_test.go
+53
-12
e2e/param_test.go
e2e/param_test.go
+16
-2
e2e/show_test.go
e2e/show_test.go
+1
-1
e2e/testdata/output/param/list/yaml-params.tmpl
e2e/testdata/output/param/list/yaml-params.tmpl
+1
-1
pkg/actions/component_list.go
pkg/actions/component_list.go
+18
-3
pkg/actions/component_list_test.go
pkg/actions/component_list_test.go
+42
-0
pkg/actions/testdata/component/list/json.txt
pkg/actions/testdata/component/list/json.txt
+1
-0
pkg/component/component.go
pkg/component/component.go
+5
-5
No files found.
e2e/app.go
View file @
d2412116
...
@@ -16,7 +16,14 @@
...
@@ -16,7 +16,14 @@
package
e2e
package
e2e
import
(
import
(
"encoding/json"
"path/filepath"
"path/filepath"
"strings"
"github.com/ksonnet/ksonnet/pkg/component"
// gomega matchers
.
"github.com/onsi/gomega"
)
)
type
app
struct
{
type
app
struct
{
...
@@ -28,8 +35,8 @@ func (a *app) runKs(args ...string) *output {
...
@@ -28,8 +35,8 @@ func (a *app) runKs(args ...string) *output {
return
a
.
e2e
.
ksInApp
(
a
.
dir
,
args
...
)
return
a
.
e2e
.
ksInApp
(
a
.
dir
,
args
...
)
}
}
func
(
a
*
app
)
componentList
()
*
output
{
func
(
a
*
app
)
componentList
(
opts
...
string
)
*
output
{
o
:=
a
.
runKs
(
"component"
,
"list"
)
o
:=
a
.
runKs
(
append
([]
string
{
"component"
,
"list"
},
opts
...
)
...
)
assertExitStatus
(
o
,
0
)
assertExitStatus
(
o
,
0
)
return
o
return
o
...
@@ -130,3 +137,34 @@ func (a *app) generateDeployedService() {
...
@@ -130,3 +137,34 @@ func (a *app) generateDeployedService() {
params
:=
filepath
.
Join
(
appDir
,
"components"
,
"params.libsonnet"
)
params
:=
filepath
.
Join
(
appDir
,
"components"
,
"params.libsonnet"
)
assertContents
(
"generate/params.libsonnet"
,
params
)
assertContents
(
"generate/params.libsonnet"
,
params
)
}
}
func
(
a
*
app
)
findComponent
(
prefix
string
)
string
{
o
:=
a
.
componentList
(
"-o"
,
"json"
)
var
summaries
[]
component
.
Summary
err
:=
json
.
Unmarshal
([]
byte
(
o
.
stdout
),
&
summaries
)
ExpectWithOffset
(
1
,
err
)
.
ToNot
(
HaveOccurred
())
var
name
string
for
_
,
summary
:=
range
summaries
{
if
strings
.
HasPrefix
(
summary
.
ComponentName
,
"deployment"
)
{
name
=
summary
.
ComponentName
}
}
ExpectWithOffset
(
1
,
name
)
.
ToNot
(
BeEmpty
())
return
name
}
func
(
a
*
app
)
componentNames
()
[]
string
{
o
:=
a
.
componentList
(
"-o"
,
"json"
)
var
summaries
[]
component
.
Summary
err
:=
json
.
Unmarshal
([]
byte
(
o
.
stdout
),
&
summaries
)
ExpectWithOffset
(
1
,
err
)
.
ToNot
(
HaveOccurred
())
var
out
[]
string
for
_
,
summary
:=
range
summaries
{
out
=
append
(
out
,
summary
.
ComponentName
)
}
return
out
}
e2e/import_test.go
View file @
d2412116
...
@@ -18,46 +18,87 @@
...
@@ -18,46 +18,87 @@
package
e2e
package
e2e
import
(
import
(
"bytes"
"path/filepath"
"path/filepath"
"github.com/ksonnet/ksonnet/pkg/util/table"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
)
)
var
_
=
Describe
(
"ks import"
,
func
()
{
var
_
=
Describe
(
"ks import"
,
func
()
{
var
a
app
var
(
a
app
importPath
string
isErr
bool
o
*
output
)
BeforeEach
(
func
()
{
BeforeEach
(
func
()
{
a
=
e
.
initApp
(
nil
)
a
=
e
.
initApp
(
nil
)
a
.
generateDeployedService
()
a
.
generateDeployedService
()
isErr
=
false
})
JustBeforeEach
(
func
()
{
o
=
a
.
runKs
(
"import"
,
"-f"
,
importPath
)
if
isErr
{
assertExitStatus
(
o
,
1
)
return
}
assertExitStatus
(
o
,
0
)
})
})
Context
(
"directory"
,
func
()
{
Context
(
"directory"
,
func
()
{
BeforeEach
(
func
()
{
importPath
=
filepath
.
Join
(
e
.
wd
(),
"testdata"
,
"input"
,
"import"
)
})
It
(
"imports the files in the directory"
,
func
()
{
It
(
"imports the files in the directory"
,
func
()
{
path
:=
filepath
.
Join
(
e
.
wd
(),
"testdata"
,
"input"
,
"import"
)
names
:=
a
.
componentNames
()
o
:=
a
.
runKs
(
"import"
,
"-f"
,
path
)
assertExitStatus
(
o
,
0
)
var
buf
bytes
.
Buffer
t
:=
table
.
New
(
&
buf
)
t
.
SetHeader
([]
string
{
"component"
})
for
_
,
name
:=
range
names
{
t
.
Append
([]
string
{
name
})
}
Expect
(
t
.
Render
())
.
NotTo
(
HaveOccurred
())
o
=
a
.
componentList
()
o
=
a
.
componentList
()
assertOutput
(
"import/output.txt"
,
o
.
stdout
)
Expect
(
o
.
stdout
)
.
To
(
Equal
(
buf
.
String
())
)
})
})
})
})
Context
(
"file"
,
func
()
{
Context
(
"file"
,
func
()
{
BeforeEach
(
func
()
{
importPath
=
filepath
.
Join
(
e
.
wd
(),
"testdata"
,
"input"
,
"import"
,
"deployment.yaml"
)
})
It
(
"imports the file"
,
func
()
{
It
(
"imports the file"
,
func
()
{
path
:=
filepath
.
Join
(
e
.
wd
(),
"testdata"
,
"input"
,
"import"
,
"deployment.yaml"
)
names
:=
a
.
componentNames
()
o
:=
a
.
runKs
(
"import"
,
"-f"
,
path
)
assertExitStatus
(
o
,
0
)
var
buf
bytes
.
Buffer
t
:=
table
.
New
(
&
buf
)
t
.
SetHeader
([]
string
{
"component"
})
for
_
,
name
:=
range
names
{
t
.
Append
([]
string
{
name
})
}
Expect
(
t
.
Render
())
.
NotTo
(
HaveOccurred
())
o
=
a
.
componentList
()
o
=
a
.
componentList
()
assertOutput
(
"import/output.txt"
,
o
.
stdout
)
Expect
(
o
.
stdout
)
.
To
(
Equal
(
buf
.
String
())
)
})
})
})
})
Context
(
"invalid path"
,
func
()
{
Context
(
"invalid path"
,
func
()
{
BeforeEach
(
func
()
{
importPath
=
filepath
.
Join
(
e
.
wd
(),
"testdata"
,
"input"
,
"import"
,
"invalid.yaml"
)
isErr
=
true
})
It
(
"returns an error"
,
func
()
{
It
(
"returns an error"
,
func
()
{
path
:=
filepath
.
Join
(
e
.
wd
(),
"testdata"
,
"input"
,
"import"
,
"invalid.yaml"
)
o
:=
a
.
runKs
(
"import"
,
"-f"
,
path
)
assertExitStatus
(
o
,
1
)
assertOutputContains
(
"import/invalid.txt"
,
o
.
stderr
)
assertOutputContains
(
"import/invalid.txt"
,
o
.
stderr
)
})
})
})
})
...
...
e2e/param_test.go
View file @
d2412116
...
@@ -18,9 +18,12 @@
...
@@ -18,9 +18,12 @@
package
e2e
package
e2e
import
(
import
(
"bytes"
"path/filepath"
"path/filepath"
"github.com/ksonnet/ksonnet/pkg/util/table"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
)
)
var
_
=
Describe
(
"ks param"
,
func
()
{
var
_
=
Describe
(
"ks param"
,
func
()
{
...
@@ -170,12 +173,16 @@ var _ = Describe("ks param", func() {
...
@@ -170,12 +173,16 @@ var _ = Describe("ks param", func() {
})
})
Context
(
"with yaml component params"
,
func
()
{
Context
(
"with yaml component params"
,
func
()
{
var
name
string
BeforeEach
(
func
()
{
BeforeEach
(
func
()
{
deployment
:=
filepath
.
Join
(
e
.
wd
(),
"testdata"
,
"input"
,
"import"
,
"deployment.yaml"
)
deployment
:=
filepath
.
Join
(
e
.
wd
(),
"testdata"
,
"input"
,
"import"
,
"deployment.yaml"
)
o
:=
a
.
runKs
(
"import"
,
"-f"
,
deployment
)
o
:=
a
.
runKs
(
"import"
,
"-f"
,
deployment
)
assertExitStatus
(
o
,
0
)
assertExitStatus
(
o
,
0
)
o
=
a
.
runKs
(
"param"
,
"set"
,
"deployment-nginx-deployment"
,
"metadata.labels"
,
`{"hello": "world"}`
)
name
=
a
.
findComponent
(
"deployment"
)
o
=
a
.
runKs
(
"param"
,
"set"
,
name
,
"metadata.labels"
,
`{"hello": "world"}`
)
assertExitStatus
(
o
,
0
)
assertExitStatus
(
o
,
0
)
})
})
...
@@ -184,7 +191,14 @@ var _ = Describe("ks param", func() {
...
@@ -184,7 +191,14 @@ var _ = Describe("ks param", func() {
})
})
It
(
"should list the YAML params"
,
func
()
{
It
(
"should list the YAML params"
,
func
()
{
assertOutput
(
"param/list/yaml-params.txt"
,
listOutput
.
stdout
)
var
buf
bytes
.
Buffer
t
:=
table
.
New
(
&
buf
)
t
.
SetHeader
([]
string
{
"component"
,
"param"
,
"value"
})
t
.
Append
([]
string
{
name
,
"metadata.labels"
,
`{"hello":"world"}`
})
Expect
(
t
.
Render
())
.
NotTo
(
HaveOccurred
())
o
:=
a
.
paramList
()
Expect
(
o
.
stdout
)
.
To
(
Equal
(
buf
.
String
()))
})
})
})
})
})
})
...
...
e2e/show_test.go
View file @
d2412116
...
@@ -25,7 +25,7 @@ import (
...
@@ -25,7 +25,7 @@ import (
.
"github.com/onsi/gomega"
.
"github.com/onsi/gomega"
)
)
var
_
=
Describe
(
"ks show"
,
func
()
{
var
_
=
P
Describe
(
"ks show"
,
func
()
{
var
a
app
var
a
app
BeforeEach
(
func
()
{
BeforeEach
(
func
()
{
...
...
e2e/testdata/output/param/list/yaml-params.t
xt
→
e2e/testdata/output/param/list/yaml-params.t
mpl
View file @
d2412116
COMPONENT PARAM VALUE
COMPONENT PARAM VALUE
========= ===== =====
========= ===== =====
deployment-nginx-deployment
metadata.labels {"hello":"world"}
{{ .name }}
metadata.labels {"hello":"world"}
pkg/actions/component_list.go
View file @
d2412116
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
package
actions
package
actions
import
(
import
(
"encoding/json"
"io"
"io"
"os"
"os"
"sort"
"sort"
...
@@ -83,9 +84,9 @@ func (cl *ComponentList) Run() error {
...
@@ -83,9 +84,9 @@ func (cl *ComponentList) Run() error {
case
""
:
case
""
:
cl
.
listComponents
(
components
)
cl
.
listComponents
(
components
)
case
"wide"
:
case
"wide"
:
if
err
:=
cl
.
listComponentsWide
(
components
)
;
err
!=
nil
{
return
cl
.
listComponentsWide
(
components
)
return
err
case
"json"
:
}
return
cl
.
listComponentsJSON
(
components
)
}
}
return
nil
return
nil
...
@@ -137,3 +138,17 @@ func (cl *ComponentList) listComponentsWide(components []component.Component) er
...
@@ -137,3 +138,17 @@ func (cl *ComponentList) listComponentsWide(components []component.Component) er
return
nil
return
nil
}
}
func
(
cl
*
ComponentList
)
listComponentsJSON
(
components
[]
component
.
Component
)
error
{
var
summaries
[]
component
.
Summary
for
_
,
c
:=
range
components
{
s
,
err
:=
c
.
Summarize
()
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"get summary for %s"
,
c
.
Name
(
true
))
}
summaries
=
append
(
summaries
,
s
)
}
return
json
.
NewEncoder
(
cl
.
out
)
.
Encode
(
summaries
)
}
pkg/actions/component_list_test.go
View file @
d2412116
...
@@ -63,6 +63,48 @@ func TestComponentList(t *testing.T) {
...
@@ -63,6 +63,48 @@ func TestComponentList(t *testing.T) {
})
})
}
}
func
TestComponentList_json
(
t
*
testing
.
T
)
{
withApp
(
t
,
func
(
appMock
*
amocks
.
App
)
{
module
:=
""
output
:=
"json"
summary1
:=
component
.
Summary
{
ComponentName
:
"ingress"
}
c1
:=
&
cmocks
.
Component
{}
c1
.
On
(
"Summarize"
)
.
Return
(
summary1
,
nil
)
summary2
:=
component
.
Summary
{
ComponentName
:
"deployment"
}
c2
:=
&
cmocks
.
Component
{}
c2
.
On
(
"Summarize"
)
.
Return
(
summary2
,
nil
)
cs
:=
[]
component
.
Component
{
c1
,
c2
}
ns
:=
&
cmocks
.
Module
{}
ns
.
On
(
"Components"
)
.
Return
(
cs
,
nil
)
cm
:=
&
cmocks
.
Manager
{}
cm
.
On
(
"Module"
,
mock
.
Anything
,
""
)
.
Return
(
ns
,
nil
)
in
:=
map
[
string
]
interface
{}{
OptionApp
:
appMock
,
OptionModule
:
module
,
OptionOutput
:
output
,
}
a
,
err
:=
NewComponentList
(
in
)
require
.
NoError
(
t
,
err
)
a
.
cm
=
cm
var
buf
bytes
.
Buffer
a
.
out
=
&
buf
err
=
a
.
Run
()
require
.
NoError
(
t
,
err
)
assertOutput
(
t
,
"component/list/json.txt"
,
buf
.
String
())
})
}
func
TestComponentList_wide
(
t
*
testing
.
T
)
{
func
TestComponentList_wide
(
t
*
testing
.
T
)
{
withApp
(
t
,
func
(
appMock
*
amocks
.
App
)
{
withApp
(
t
,
func
(
appMock
*
amocks
.
App
)
{
module
:=
""
module
:=
""
...
...
pkg/actions/testdata/component/list/json.txt
0 → 100644
View file @
d2412116
[{"component_name":"ingress"},{"component_name":"deployment"}]
pkg/component/component.go
View file @
d2412116
...
@@ -35,11 +35,11 @@ type ParamOptions struct {
...
@@ -35,11 +35,11 @@ type ParamOptions struct {
// Summary summarizes items found in components.
// Summary summarizes items found in components.
type
Summary
struct
{
type
Summary
struct
{
ComponentName
string
ComponentName
string
`json:"component_name,omitempty"`
Type
string
Type
string
`json:"type,omitempty"`
APIVersion
string
APIVersion
string
`json:"api_version,omitempty"`
Kind
string
Kind
string
`json:"kind,omitempty"`
Name
string
Name
string
`json:"name,omitempty"`
}
}
// GVK converts a summary to a group - version - kind.
// GVK converts a summary to a group - version - kind.
...
...
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