8000 test: integration testing of functionality by ashearin · Pull Request #169 · bomctl/bomctl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

test: integration testing of functionality #169

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

Merged
merged 7 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Normalize line endings
* text=auto
*.txtar text eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
!/docs/**/*.md
!/docs/images/*.png
!/docs/images/*.svg
!/internal/e2e/**/*.txtar
!/Taskfile.yml

# Whitelist patterns found anywhere in project
Expand Down
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ linters-settings:
exclude: [TEST, ~cmd/.*\.go]
arguments: [10]

- name: confusing-naming
exclude: [TEST]

- name: cyclomatic
disabled: true

Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
9E81
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"go.lintFlags": ["--fast"],
"go.lintOnSave": "workspace",
"go.lintTool": "golangci-lint",
"go.testFlags": ["-race", "-covermode=atomic"],
"go.testFlags": ["-race"],

"json.schemaDownload.enable": true,

Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,12 @@ lint-fix: lint-go-fix lint-markdown-fix lint-shell lint-yaml # Lint Golang code,
#@ Test
.PHONY: test-unit
test-unit: # Run unit tests
go test -failfast -v -coverprofile=coverage.out -covermode=atomic ./...
go test -failfast -v -coverprofile=coverage.out -covermode=atomic -short ./...

.PHONY: test-e2e
test-e2e: # Run unit tests
go test -failfast -v ./internal/e2e/...

.PHONY: test
test: test-unit # Run all tests
test: # Run all tests
go test -failfast -v -coverprofile=coverage.out -covermode=atomic ./...
9 changes: 6 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@ tasks:

test:
desc: Run all tests
cmds:
- task: test:unit
cmd: go test -failfast -v -coverprofile=coverage.out -covermode=atomic ./...

test:unit:
desc: Run unit tests
cmd: go test -failfast -v -coverprofile=coverage.out -covermode=atomic ./...
cmd: go test -failfast -v -coverprofile=coverage.out -covermode=atomic -short ./...

test:e2e:
desc: Run unit tests
cmd: go test -failfast -v ./internal/e2e/...
8 changes: 6 additions & 2 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
errFormatNotSupported = errors.New("format not supported")
)

func exportCmd() *cobra.Command {
func exportCmd() *cobra.Command { //nolint:funlen
opts := &options.ExportOptions{}
outputFile := outputFileValue("")

Expand Down Expand Up @@ -88,7 +88,11 @@ func exportCmd() *cobra.Command {
// Get the documents to obtain their IDs, in case the provided IDs were aliases.
documents, err := backend.GetDocumentsByIDOrAlias(args...)
if err != nil {
opts.Logger.Fatal(err, "documentIDs", args)
opts.Logger.Fatal(err, "documentID(s)", args)
}

if len(documents) == 0 {
opts.Logger.Errorf("documentID(s) not found: %s", args)
}

for _, document := range documents {
Expand Down
4 changes: 3 additions & 1 deletion cmd/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ import (
"github.com/bomctl/bomctl/internal/pkg/options"
)

const mergeMinArgs int = 2

func mergeCmd() *cobra.Command {
opts := &options.MergeOptions{}

mergeCmd := &cobra.Command{
Use: "merge [flags] DOCUMENT_ID...",
Args: cobra.MinimumNArgs(1),
Args: cobra.MinimumNArgs(mergeMinArgs),
Short: "Merge SBOM documents in local storage",
Long: fmt.Sprintf("%s%s%s",
"Merge SBOM documents in local storage. The leftmost specified document ID takes priority with the ",
Expand Down
17 changes: 15 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ func rootCmd() *cobra.Command {
return rootCmd
}

func Execute() {
cobra.CheckErr(rootCmd().Execute())
func Execute() (rc int) {
rc = 0

defer func() {
if r := recover(); r != nil {
// handle the panic
rc = 1
}
}()

if err := rootCmd().Execute(); err != nil {
rc = 1
}

return rc
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/opencontainers/image-spec v1.1.0
github.com/protobom/protobom v0.4.3
github.com/protobom/storage v0.1.5
github.com/rogpeppe/go-internal v1.12.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
Expand Down
28 changes: 28 additions & 0 deletions internal/e2e/alias/alias.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[windows] env TMPDIR=$TMP
[windows] env LocalAppData=$WORK\tmp"
[windows] env AppData=$WORK

# alias -h
exec bomctl alias -h --cache-dir $WORK
! stderr .
stdout .

# alias --help
exec bomctl alias --help --cache-dir $WORK
! stderr .
stdout .

# alias help
exec bomctl alias help --cache-dir $WORK
! stderr .
stdout .

# help alias
exec bomctl help alias --cache-dir $WORK
! stderr .
stdout .

# alias no input
exec bomctl alias --cache-dir $WORK
! stderr .
stdout .
46 changes: 46 additions & 0 deletions internal/e2e/alias/alias_list.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[windows] env TMPDIR=$TMP
[windows] env LocalAppData=$WORK\tmp"
[windows] env AppData=$WORK
add_files $WORK sbom.cdx.json

# alias list -h
exec bomctl alias list -h --cache-dir $WORK
! stderr .
stdout .

# alias list --help
exec bomctl alias list --help --cache-dir $WORK
! stderr .
stdout .

# help alias list
exec bomctl help alias list --cache-dir $WORK
! stderr .
stdout .

# alias list no input
exec bomctl alias list --cache-dir $WORK
! stderr .
cmp stdout empty_list.txt

# alias ls no input
exec bomctl import --cache-dir $WORK --alias charmander sbom.cdx.json
! stdout .
! stderr .

exec bomctl alias ls --cache-dir $WORK
! stderr .
cmp stdout alias_list.txt

-- empty_list.txt --

Alias Definitions
────────────────────────────────────────────────────────────────────────────────


-- alias_list.txt --

Alias Definitions
────────────────────────────────────────────────────────────────────────────────
charmander → urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79

80 changes: 80 additions & 0 deletions internal/e2e/alias/alias_remove.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[windows] env TMPDIR=$TMP
[windows] env LocalAppData=$WORK\tmp"
[windows] env AppData=$WORK
add_files $WORK sbom.cdx.json

# alias remove -h
exec bomctl alias remove -h --cache-dir $WORK
! stderr .
stdout .

# alias remove --help
exec bomctl alias remove --help --cache-dir $WORK
! stderr .
stdout .

# help alias remove
exec bomctl help alias remove --cache-dir $WORK
! stderr .
stdout .

# alias remove no input (FAILURE EXPECTED)
! exec bomctl alias remove --cache-dir $WORK
stderr -count=1 '^Error: accepts between 1 and 2 arg\(s\), received 0$'
! stdout .

# alias remove sbom_id
exec bomctl import --cache-dir $WORK --alias apple sbom.cdx.json
! stdout .
! stderr .

exec bomctl list --cache-dir $WORK
! stderr .
cmp stdout apple_remove_list.txt

exec bomctl alias remove --cache-dir $WORK urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79
! stderr .
! stdout .

exec bomctl list --cache-dir $WORK
! stderr .
cmp stdout empty_remove_list.txt

# alias rm sbom_id
exec bomctl alias set --cache-dir $WORK urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79 orange
! stderr .
! stdout .

exec bomctl list --cache-dir $WORK
! stderr .
cmp stdout orange_remove_list.txt

exec bomctl alias rm --cache-dir $WORK urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79
! stderr .
! stdout .

exec bomctl list --cache-dir $WORK
! stderr .
cmp stdout empty_remove_list.txt

-- empty_remove_list.txt --

ID : urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79
Alias :
Version : 1
# Nodes : 3

-- orange_remove_list.txt --

ID : urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79
Alias : orange
Version : 1
# Nodes : 3

-- apple_remove_list.txt --

ID : urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79
Alias : apple
Version : 1
# Nodes : 3

70 changes: 70 additions & 0 deletions internal/e2e/alias/alias_set.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[windows] env TMPDIR=$TMP
[windows] env LocalAppData=$WORK\tmp"
[windows] env AppData=$WORK
add_files $WORK sbom.cdx.json

# alias set -h
exec bomctl alias set -h --cache-dir $WORK
! stderr .
stdout .

# alias set --help
exec bomctl alias set --help --cache-dir $WORK
! stderr .
stdout .

# help alias set
exec bomctl help alias set --cache-dir $WORK
! stderr .
stdout .

# alias set no input (FAILURE EXPECTED)
! exec bomctl alias set --cache-dir $WORK
stderr -count=1 '^Error: accepts 2 arg\(s\), received 0$'
! stdout .

# alias set one input (FAILURE EXPECTED)
! exec bomctl alias set --cache-dir $WORK urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79
stderr -count=1 '^Error: accepts 2 arg\(s\), received 1$'
! stdout .

# alias set sbom_id
exec bomctl import --cache-dir $WORK sbom.cdx.json
! stdout .
! stderr .

exec bomctl alias set --cache-dir $WORK urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79 root_beer
! stderr .
! stdout .

exec bomctl list --cache-dir $WORK
cmp stdout alias_set_list.txt

# alias set same sbom with different alias (FAILURE EXPECTED)
! exec bomctl alias set --cache-dir $WORK urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79 cherry_coke
stderr 'FATAL db: The document already has an alias. To replace it, re-run the command with the --force flag'
! stdout .

# alias set sbom_id -f
exec bomctl alias set --cache-dir $WORK -f urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79 dr_pepper
! stderr .
! stdout .

exec bomctl list --cache-dir $WORK
cmp stdout force_set_list.txt
! stderr .

-- force_set_list.txt --

ID : urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79
Alias : dr_pepper
Version : 1
# Nodes : 3

-- alias_set_list.txt --

ID : urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79
Alias : root_beer
Version : 1
# Nodes : 3

Loading
0