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 21 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
57 changes: 57 additions & 0 deletions .github/workflows/test-e2e-create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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: Checkout template-operator
uses: actions/checkout@v4
with:
repository: kyma-project/template-operator
path: ./template-operator/
- name: Copy template-operator to e2e testdata folder
run: |
mkdir -p ./tests/e2e/create/testdata/template-operator/
cp -r ./../template-operator/ ./tests/e2e/create/testdata/template-operator/
lindnerby marked this conversation as resolved.
Show resolved Hide resolved
- name: Set template-operator github URL
run: |
cd ./template-operator
echo "TEST_REPOSITORY_URL=$(git remote get-url origin)" >> "$GITHUB_ENV"
- 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: Make manifests template-operator
run: |
cd ./template-operator
make build-manifests
- 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 @@ -58,6 +58,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
ireturn:
allow:
- anon
Expand All @@ -70,7 +76,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 @@ -134,7 +134,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 @@ -144,6 +144,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
}
Loading
Loading