Skip to content
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

feat: Add E2E Test Suite for module create #47

Merged
merged 42 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e62bafb
add workflow and tests
lindnerby Sep 4, 2024
c8f1776
Merge branch 'main' into e2e-module-create
lindnerby Sep 4, 2024
716bf81
fmt
lindnerby Sep 4, 2024
c70151d
test
lindnerby Sep 4, 2024
6babc37
test
lindnerby Sep 4, 2024
ab16656
test
lindnerby Sep 4, 2024
d8a5fde
revert renaming fail
lindnerby Sep 5, 2024
8d69d27
renaming
lindnerby Sep 5, 2024
6a6fd87
add unit tests for scaffold options Validate function
lindnerby Sep 5, 2024
c6967c7
fix yaml unmarshal of module template
lindnerby Sep 5, 2024
54eac8c
add new ginkgo format create e2e tests
lindnerby Sep 5, 2024
f7d2935
lint
lindnerby Sep 5, 2024
1520aa4
fix linter but keep todo to fail
lindnerby Sep 5, 2024
4019928
fix unit tests
lindnerby Sep 5, 2024
493f9c6
use build tags for e2e tests
lindnerby Sep 5, 2024
1cda31b
test new e2e structure against kyma bin
lindnerby Sep 5, 2024
f96574b
stash
lindnerby Sep 10, 2024
3da148e
migrate all e2e tests
lindnerby Sep 12, 2024
10f43cf
clean-up
lindnerby Sep 12, 2024
cafe3f8
clean-up
lindnerby Sep 12, 2024
aaf8775
adapt some review issues
lindnerby Sep 13, 2024
f26ab1e
Add registryUrl != "" check
nesmabadr Sep 24, 2024
34f5f08
adapt testcases to new modulectl api
lindnerby Sep 24, 2024
abd17c2
clean-up
lindnerby Sep 24, 2024
08d6491
Revert "Add registryUrl != "" check"
nesmabadr Sep 24, 2024
eda8d79
Fix E2E tests
nesmabadr Sep 24, 2024
4362d8f
Add test case for missing security (still not passing)
nesmabadr Sep 24, 2024
a61acdf
add more testdata
lindnerby Sep 24, 2024
6e86073
use new testdata
lindnerby Sep 24, 2024
583f7a1
clean-up
lindnerby Sep 24, 2024
b7e90df
add testcases for different valid module-configs
lindnerby Sep 24, 2024
4b9aa46
bump mandatory version
lindnerby Sep 24, 2024
53679d8
move consts
lindnerby Sep 24, 2024
940bf01
fix tests
lindnerby Sep 24, 2024
1e4c609
fix tests
lindnerby Sep 24, 2024
c557e16
fix tests
lindnerby Sep 24, 2024
db89c8b
Merge branch 'main' into e2e-module-create
lindnerby Sep 26, 2024
d3bf279
fix merge diff
lindnerby Sep 26, 2024
497cc76
new line
lindnerby Sep 26, 2024
6551f9c
fix e2e expected err
lindnerby Sep 26, 2024
f46f869
adapt coverage
lindnerby Sep 26, 2024
6d007b6
retrigger jobs
lindnerby Sep 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
name: Build modulectl
name: Build
on:
pull_request:
branches:
- main
- 'release-**'
workflow_dispatch:
jobs:
build:
name: Build modulectl
build-modulectl:
runs-on: ubuntu-latest
steps:
- name: Checkout modulectl
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
- name: Go setup
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
- name: Run CLI Build
- name: "Run 'make build'"
run: make build
40 changes: 40 additions & 0 deletions .github/workflows/test-e2e-create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: E2E test - create command
on:
push:
branches:
- main
- 'release-**'
pull_request:
branches:
- main
- 'release-**'
jobs:
test-create-cmd:
runs-on: ubuntu-latest
env:
K3D_VERSION: v5.4.7
MODULE_TEMPLATE_VERSION: 1.0.0
OCI_REPOSITORY_URL: http://k3d-oci.localhost:5001
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Go setup
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
- name: Build
run: |
make build-linux
chmod +x ./bin/modulectl-linux
ls -la ./bin
mv ./bin/modulectl-linux /usr/local/bin/modulectl
timeout-minutes: 5
- name: Install k3d and create registry
run: |
wget -qO - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | TAG=$K3D_VERSION bash
k3d registry create oci.localhost --port 5001
- name: Run tests
run: |
make -C tests/e2e test-create-cmd
timeout-minutes: 3
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
name: E2E Test - Create Scaffold
name: E2E test - scaffold command
on:
pull_request:
branches:
- main
- 'release-**'
jobs:
e2e-test:
name: E2E Test - Create Scaffold
test-scaffold-cmd:
runs-on: ubuntu-latest
steps:
- name: Checkout modulectl
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
- name: Go setup
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
- name: Build modulectl
- name: Build
run: |
make build-linux
chmod +x ./bin/modulectl-linux
ls -la ./bin
mv ./bin/modulectl-linux /usr/local/bin/modulectl
timeout-minutes: 10
- name: Run E2E Test - Create Scaffold
timeout-minutes: 5
- name: Run tests
run: |
make -C tests/e2e test-create-scaffold
make -C tests/e2e test-scaffold-cmd
timeout-minutes: 3
File renamed without changes.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ bin

# rendered manifest
**/manifest.yaml

# copied template-operator repo
tests/e2e/create/testdata/template-operator
9 changes: 7 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ linters:
- exhaustruct # too subjective and harms code readability
- execinquery # deprecated (since v1.58.0)
- exportloopref # deprecated (since v1.60.2), replaced by copyloopvar
- forbidigo # temparily disabled
- forbidigo # temporarily disabled
- godot # not needed
- gomnd # deprecated (since v1.58.0), renamed to mnd
- lll
Expand Down Expand Up @@ -60,6 +60,12 @@ linters-settings:
alias: scaffoldcmd
- pkg: github.com/kyma-project/modulectl/cmd/modulectl/create
alias: createcmd
- pkg: github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1
alias: ocmmetav1
- pkg: github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/versions/v2
alias: compdescv2
- pkg: github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/ocireg
alias: ocmocireg
- pkg: github.com/kyma-project/modulectl/internal/service/moduleconfig/generator
alias: moduleconfiggenerator
- pkg: github.com/kyma-project/modulectl/internal/service/moduleconfig/reader
Expand Down Expand Up @@ -87,7 +93,6 @@ linters-settings:
ignore-type-assert-ok: true
ignore-map-index-ok: true
ignore-chan-recv-ok: true
godox: # `TODO`, `BUG`, `FIXME` are the default, no need to mention again
issues:
exclude-rules:
- path: "_test\\.go"
Expand Down
12 changes: 6 additions & 6 deletions cmd/modulectl/create/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ var long string
//go:embed example.txt
var example string

type ModuleService interface {
CreateModule(opts create.Options) error
type Service interface {
Run(opts create.Options) error
}

func NewCmd(moduleService ModuleService) (*cobra.Command, error) {
if moduleService == nil {
return nil, fmt.Errorf("%w: createService must not be nil", commonerrors.ErrInvalidArg)
func NewCmd(service Service) (*cobra.Command, error) {
if service == nil {
return nil, fmt.Errorf("%w: service must not be nil", commonerrors.ErrInvalidArg)
}

opts := create.Options{}
Expand All @@ -41,7 +41,7 @@ func NewCmd(moduleService ModuleService) (*cobra.Command, error) {
Long: long,
Example: example,
RunE: func(cmd *cobra.Command, _ []string) error {
return moduleService.CreateModule(opts)
return service.Run(opts)
},
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/modulectl/create/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Test_NewCmd_ReturnsError_WhenModuleServiceIsNil(t *testing.T) {
_, err := createcmd.NewCmd(nil)

require.Error(t, err)
assert.Contains(t, err.Error(), "createService")
assert.Contains(t, err.Error(), "service must not be nil")
}

func Test_NewCmd_Succeeds(t *testing.T) {
Expand Down Expand Up @@ -130,7 +130,7 @@ type moduleServiceStub struct {
opts create.Options
}

func (m *moduleServiceStub) CreateModule(opts create.Options) error {
func (m *moduleServiceStub) Run(opts create.Options) error {
m.called = true
m.opts = opts
return nil
Expand All @@ -140,6 +140,6 @@ type moduleServiceErrorStub struct{}

var errSomeTestError = errors.New("some test error")

func (s *moduleServiceErrorStub) CreateModule(_ create.Options) error {
func (s *moduleServiceErrorStub) Run(_ create.Options) error {
return errSomeTestError
}
12 changes: 6 additions & 6 deletions cmd/modulectl/scaffold/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ var long string
//go:embed example.txt
var example string

type ScaffoldService interface {
CreateScaffold(opts scaffold.Options) error
type Service interface {
Run(opts scaffold.Options) error
}

func NewCmd(scaffoldService ScaffoldService) (*cobra.Command, error) {
if scaffoldService == nil {
return nil, fmt.Errorf("%w: scaffoldService must not be nil", commonerrors.ErrInvalidArg)
func NewCmd(service Service) (*cobra.Command, error) {
if service == nil {
return nil, fmt.Errorf("%w: service must not be nil", commonerrors.ErrInvalidArg)
}

opts := scaffold.Options{}
Expand All @@ -42,7 +42,7 @@ func NewCmd(scaffoldService ScaffoldService) (*cobra.Command, error) {
Example: example,
Args: cobra.NoArgs,
RunE: func(_ *cobra.Command, _ []string) error {
return scaffoldService.CreateScaffold(opts)
return service.Run(opts)
},
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/modulectl/scaffold/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Test_NewCmd_ReturnsError_WhenScaffoldServiceIsNil(t *testing.T) {
_, err := scaffoldcmd.NewCmd(nil)

require.Error(t, err)
assert.Contains(t, err.Error(), "scaffoldService")
assert.Contains(t, err.Error(), "service must not be nil")
}

func Test_NewCmd_Succceeds(t *testing.T) {
Expand Down Expand Up @@ -143,7 +143,7 @@ type scaffoldServiceStub struct {
opts scaffold.Options
}

func (s *scaffoldServiceStub) CreateScaffold(opts scaffold.Options) error {
func (s *scaffoldServiceStub) Run(opts scaffold.Options) error {
s.called = true
s.opts = opts
return nil
Expand All @@ -153,6 +153,6 @@ type scaffoldServiceErrorStub struct{}

var errSomeTestError = errors.New("some test error")

func (s *scaffoldServiceErrorStub) CreateScaffold(_ scaffold.Options) error {
func (s *scaffoldServiceErrorStub) Run(_ scaffold.Options) error {
return errSomeTestError
}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/mandelsoft/vfs v0.4.3
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.2
github.com/open-component-model/ocm v0.13.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
Expand Down Expand Up @@ -120,6 +121,7 @@ require (
github.com/elliotchance/orderedmap v1.6.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand Down Expand Up @@ -311,6 +313,7 @@ require (
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/api v0.190.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf // indirect
Expand All @@ -330,6 +333,7 @@ require (
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
oras.land/oras-go v1.2.5 // indirect
sigs.k8s.io/controller-runtime v0.19.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.17.3 // indirect
sigs.k8s.io/kustomize/kyaml v0.17.2 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ2tG6yudJd8LBksgI=
github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f h1:Wl78ApPPB2Wvf/TIe2xdyJxTlb6obmF18d8QdkxNDu4=
Expand Down Expand Up @@ -427,6 +428,8 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=
github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg=
github.com/go-openapi/analysis v0.23.0 h1:aGday7OWupfMs+LbmLZG4k0MYXIANxcuBTYUC03zFCU=
github.com/go-openapi/analysis v0.23.0/go.mod h1:9mz9ZWaSlV8TvjQHLl2mUW2PbZtemkE8yA5v22ohupo=
github.com/go-openapi/errors v0.22.0 h1:c4xY/OLxUBSTiepAg3j/MHuAv5mJhnf53LLMWFB+u/w=
Expand Down Expand Up @@ -783,6 +786,8 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8=
github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc=
github.com/open-component-model/ocm v0.13.0 h1:rm31Z7SpFzpxCIUagaFEUI4cSIS098Hf2H0dToV2nOA=
github.com/open-component-model/ocm v0.13.0/go.mod h1:+ovmIxTexDM2fcnfVg9uqJh22A7KOxwa/stNJn315yU=
github.com/open-policy-agent/opa v0.67.0 h1:FOdsO9yNhfmrh+72oVK7ImWmzruG+VSpfbr5IBqEWVs=
github.com/open-policy-agent/opa v0.67.0/go.mod h1:aqKlHc8E2VAAylYE9x09zJYr/fYzGX+JKne89UGqFzk=
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
Expand Down Expand Up @@ -1230,6 +1235,8 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw=
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
google.golang.org/api v0.190.0 h1:ASM+IhLY1zljNdLu19W1jTmU6A+gMk6M46Wlur61s+Q=
google.golang.org/api v0.190.0/go.mod h1:QIr6I9iedBLnfqoD6L6Vze1UvS5Hzj5r2aUBOaZnLHo=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
Expand Down
2 changes: 1 addition & 1 deletion internal/service/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func NewService(moduleConfigService ModuleConfigService,
}, nil
}

func (s *Service) CreateModule(opts Options) error {
func (s *Service) Run(opts Options) error {
if err := opts.Validate(); err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions internal/service/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Test_CreateModule_ReturnsError_WhenModuleConfigFileIsEmpty(t *testing.T) {

opts := newCreateOptionsBuilder().withModuleConfigFile("").build()

err = svc.CreateModule(opts)
err = svc.Run(opts)

require.ErrorIs(t, err, commonerrors.ErrInvalidOption)
require.Contains(t, err.Error(), "opts.ModuleConfigFile")
Expand All @@ -46,7 +46,7 @@ func Test_CreateModule_ReturnsError_WhenOutIsNil(t *testing.T) {

opts := newCreateOptionsBuilder().withOut(nil).build()

err = svc.CreateModule(opts)
err = svc.Run(opts)

require.ErrorIs(t, err, commonerrors.ErrInvalidOption)
require.Contains(t, err.Error(), "opts.Out")
Expand All @@ -59,7 +59,7 @@ func Test_CreateModule_ReturnsError_WhenCredentialsIsInInvalidFormat(t *testing.

opts := newCreateOptionsBuilder().withCredentials("user").build()

err = svc.CreateModule(opts)
err = svc.Run(opts)

require.ErrorIs(t, err, commonerrors.ErrInvalidOption)
require.Contains(t, err.Error(), "opts.Credentials")
Expand All @@ -72,7 +72,7 @@ func Test_CreateModule_ReturnsError_WhenTemplateOutputIsEmpty(t *testing.T) {

opts := newCreateOptionsBuilder().withTemplateOutput("").build()

err = svc.CreateModule(opts)
err = svc.Run(opts)

require.ErrorIs(t, err, commonerrors.ErrInvalidOption)
require.Contains(t, err.Error(), "opts.TemplateOutput")
Expand All @@ -86,7 +86,7 @@ func Test_CreateModule_ReturnsError_WhenParseAndValidateModuleConfigReturnsError

opts := newCreateOptionsBuilder().build()

err = svc.CreateModule(opts)
err = svc.Run(opts)

require.Error(t, err)
require.Contains(t, err.Error(), "failed to read module config file")
Expand Down
2 changes: 1 addition & 1 deletion internal/service/scaffold/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Options struct {
ModuleChannel string
}

func (opts Options) validate() error {
func (opts Options) Validate() error {
lindnerby marked this conversation as resolved.
Show resolved Hide resolved
if opts.Out == nil {
return fmt.Errorf("%w: opts.Out must not be nil", commonerrors.ErrInvalidOption)
}
Expand Down
Loading
Loading