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

makefile improvements, runs delete, unit tests missing. #277

Merged
merged 17 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
107 changes: 67 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
#
# SPDX-License-Identifier: EPL-2.0
#

# Rather than keep tabs on all of the source folders, lets create the list of things we are dependent upon
# dynamically using a cool shell script.

# A list of source files. This is completely expanded-out.
# Evaluates to something like this: ./pkg/tokensformatter/tokensFormatter.go ./pkg/tokensformatter/summaryFormatter_test.go
# We want to run some targets if any of the source files have changed.
SOURCE_FILES := $(shell find . -iname "*.go"| tr "\n" " ") embedded_info

all: tests galasactl gendocs-galasactl

galasactl: \
Expand All @@ -15,51 +24,69 @@ galasactl: \

# 'gendocs-galasactl' is a command-line tool which generates documentation about the galasactl tool.
# When executed, the .md produced contain up-to-date information on tool syntax.
gendocs-galasactl: bin/gendocs-galasactl-darwin-arm64 bin/gendocs-galasactl-linux-arm64 bin/gendocs-galasactl-darwin-x86_64 bin/gendocs-galasactl-linux-x86_64

tests: galasactl-source build/coverage.txt build/coverage.html

build/coverage.out : galasactl-source
gendocs-galasactl: \
bin/gendocs-galasactl-darwin-arm64 \
bin/gendocs-galasactl-linux-arm64 \
bin/gendocs-galasactl-darwin-x86_64 \
bin/gendocs-galasactl-linux-x86_64

tests: $(SOURCE_FILES) build/coverage.txt build/coverage.html

# Build a list of the source packages
# Note:
# - We don't want to include the generated galasaapi
# - We don't want to include the top-level command code at ./cmd
# - We join them into a comma-separated list
# - We smarten-up the begining element (remove ".,")
# - We smarten-up the end element (remove trailing ",")
# - We remove any spaces in the whole thing,.
# So we end up with something like this: ./pkg/api,./pkg/auth,./pkg/cmd,./pkg/embedded,./pkg/errors,./pkg/files ...etc.
COVERAGE_SOURCE_PACKAGES := ${shell find . -iname "*.go" \
| xargs dirname {} \
| grep -v "/pkg/galasaapi" \
| grep -v "[.]/cmd/" \
| sort \
| uniq \
| tr '\n' ',' \
| sed "s/[.],//g" \
| sed "s/,$$//g" \
| sed "s/ //g" \
}

# If any source code has changed, re-run the unit tests.
build/coverage.out : $(SOURCE_FILES)
mkdir -p build
go test -v -cover -coverprofile=build/coverage.out -coverpkg pkg/api,./pkg/auth,./pkg/cmd,./pkg/runsformatter,./pkg/errors,./pkg/launcher,./pkg/utils,./pkg/runs,./pkg/properties,./pkg/propertiesformatter,./pkg/resources ./pkg/...
echo "Coverage source packages are $(COVERAGE_SOURCE_PACKAGES)"
go test -v -cover -coverprofile=build/coverage.out -coverpkg $(COVERAGE_SOURCE_PACKAGES) ./pkg/...

build/coverage-sanitised.out : build/coverage.out
cat build/coverage.out \
| grep -v "Mock" \
| grep -v "ixtures" \
> build/coverage-no-mocks.out

build/coverage.html : build/coverage.out
# Unit test output --> an html report.
build/coverage.html : build/coverage-sanitised.out
go tool cover -html=build/coverage.out -o build/coverage.html

build/coverage.txt : build/coverage.out
# Unit test output --> a text file report.
build/coverage.txt : build/coverage-sanitised.out
go tool cover -func=build/coverage.out > build/coverage.txt
cat build/coverage.txt

galasactl-source : \
./cmd/galasactl/*.go \
./pkg/api/*.go \
./pkg/auth/*.go \
./pkg/runsformatter/*.go \
./pkg/cmd/*.go \
./pkg/utils/*.go \
./pkg/runs/*.go \
./pkg/launcher/*.go \
./pkg/files/*.go \
./pkg/images/*.go \
./pkg/props/*.go \
./pkg/properties/*.go \
./pkg/propertiesformatter/*.go \
./pkg/resources/*.go \
./pkg/spi/*.go \
./pkg/tokensformatter/*.go \
embedded_info
coverage : build/coverage.txt

# The build process
embedded_info : \
pkg/embedded/templates/version/build.properties

GENERATED_BUILD_PROPERTIES_FILE := pkg/embedded/templates/version/build.properties
embedded_info : $(GENERATED_BUILD_PROPERTIES_FILE)

pkg/embedded/templates/version :
mkdir -p $@

# Build a properties file containing versions of things.
# Then the galasactl can embed the data and read it at run-time.
pkg/embedded/templates/version/build.properties : VERSION pkg/embedded/templates/version Makefile build.gradle
$(GENERATED_BUILD_PROPERTIES_FILE) : VERSION pkg/embedded/templates/version Makefile build.gradle
echo "# Property file generated at build-time" > $@
# Turn the contents of VERSION file into a properties file value.
cat VERSION | sed "s/^/galasactl.version = /1" >> $@ ; echo "" >> $@
Expand All @@ -72,34 +99,34 @@ pkg/embedded/templates/version/build.properties : VERSION pkg/embedded/templates
echo "# version of the rest api that is compiled and the client is expecting from the ecosystem." >> $@
cat build/dependencies/openapi.yaml | grep "version :" | cut -f2 -d'"' | sed "s/^/galasactl.rest.api.version = /" >> $@

bin/galasactl-linux-x86_64 : galasactl-source
bin/galasactl-linux-x86_64 : $(SOURCE_FILES)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/galasactl-linux-x86_64 ./cmd/galasactl

bin/galasactl-windows-x86_64.exe : galasactl-source
bin/galasactl-windows-x86_64.exe : $(SOURCE_FILES)
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/galasactl-windows-x86_64.exe ./cmd/galasactl

bin/galasactl-darwin-x86_64 : galasactl-source
bin/galasactl-darwin-x86_64 : $(SOURCE_FILES)
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o bin/galasactl-darwin-x86_64 ./cmd/galasactl

bin/galasactl-darwin-arm64 : galasactl-source
bin/galasactl-darwin-arm64 : $(SOURCE_FILES)
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/galasactl-darwin-arm64 ./cmd/galasactl

bin/galasactl-linux-arm64 : galasactl-source
bin/galasactl-linux-arm64 : $(SOURCE_FILES)
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o bin/galasactl-linux-arm64 ./cmd/galasactl

bin/galasactl-linux-s390x : galasactl-source
bin/galasactl-linux-s390x : $(SOURCE_FILES)
CGO_ENABLED=0 GOOS=linux GOARCH=s390x go build -o bin/galasactl-linux-s390x ./cmd/galasactl

bin/gendocs-galasactl-darwin-arm64 : galasactl-source
bin/gendocs-galasactl-darwin-arm64 : $(SOURCE_FILES)
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/gendocs-galasactl-darwin-arm64 ./cmd/gendocs-galasactl

bin/gendocs-galasactl-linux-arm64 : galasactl-source
bin/gendocs-galasactl-linux-arm64 : $(SOURCE_FILES)
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o bin/gendocs-galasactl-linux-arm64 ./cmd/gendocs-galasactl

bin/gendocs-galasactl-linux-x86_64 : galasactl-source
bin/gendocs-galasactl-linux-x86_64 : $(SOURCE_FILES)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/gendocs-galasactl-linux-x86_64 ./cmd/gendocs-galasactl

bin/gendocs-galasactl-darwin-x86_64 : galasactl-source
bin/gendocs-galasactl-darwin-x86_64 : $(SOURCE_FILES)
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o bin/gendocs-galasactl-darwin-x86_64 ./cmd/gendocs-galasactl

clean:
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/errors-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ The `galasactl` tool can generate the following errors:
- GAL1154E: The provided token ID, '{}', does not match formatting requirements. The token ID can contain any character in the 'a'-'z', 'A'-'Z', '0'-'9', '-' (dash), or '_' (underscore) ranges only.
- GAL1155E: The id provided by the --id field cannot be an empty string.
- GAL1156E: '{}' is not supported as a valid value. Valid values are 'me'.
- GAL1157E: An attempt to delete a run failed. Cause is {}
- GAL1158E: An attempt to delete a run failed. The server responded with an error. Cause is {}
- GAL1225E: Failed to open file '{}' cause: {}. Check that this file exists, and that you have read permissions.
- GAL1226E: Internal failure. Contents of gzip could be read, but not decoded. New gzip reader failed: file: {} error: {}
- GAL1227E: Internal failure. Contents of gzip could not be decoded. {} error: {}
Expand Down
1 change: 1 addition & 0 deletions docs/generated/galasactl_runs.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Assembles, submits and monitors test runs in Galasa Ecosystem

* [galasactl](galasactl.md) - CLI for Galasa
* [galasactl runs cancel](galasactl_runs_cancel.md) - cancel an active run in the ecosystem
* [galasactl runs delete](galasactl_runs_delete.md) - Get the details of a test runname which ran or is running.
* [galasactl runs download](galasactl_runs_download.md) - Download the artifacts of a test run which ran.
* [galasactl runs get](galasactl_runs_get.md) - Get the details of a test runname which ran or is running.
* [galasactl runs prepare](galasactl_runs_prepare.md) - prepares a list of tests
Expand Down
31 changes: 31 additions & 0 deletions docs/generated/galasactl_runs_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## galasactl runs delete

Get the details of a test runname which ran or is running.

### Synopsis

Get the details of a test runname which ran or is running, displaying the results to the caller.
eamansour marked this conversation as resolved.
Show resolved Hide resolved

```
galasactl runs delete [flags]
eamansour marked this conversation as resolved.
Show resolved Hide resolved
```

### Options

```
-h, --help Displays the options for the 'runs delete' command.
--name string the name of the test run we want to delete. Cannot be used in conjunction with --requestor, --result or --active flags
eamansour marked this conversation as resolved.
Show resolved Hide resolved
```

### Options inherited from parent commands

```
-b, --bootstrap string Bootstrap URL. Should start with 'http://' or 'file://'. If it starts with neither, it is assumed to be a fully-qualified path. If missing, it defaults to use the 'bootstrap.properties' file in your GALASA_HOME. Example: http://example.com/bootstrap, file:///user/myuserid/.galasa/bootstrap.properties , file://C:/Users/myuserid/.galasa/bootstrap.properties
--galasahome string Path to a folder where Galasa will read and write files and configuration settings. The default is '${HOME}/.galasa'. This overrides the GALASA_HOME environment variable which may be set instead.
-l, --log string File to which log information will be sent. Any folder referred to must exist. An existing file will be overwritten. Specify "-" to log to stderr. Defaults to not logging.
```

### SEE ALSO

* [galasactl runs](galasactl_runs.md) - Manage test runs in the ecosystem

6 changes: 6 additions & 0 deletions pkg/cmd/commandCollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
COMMAND_NAME_RUNS_SUBMIT_LOCAL = "runs submit local"
COMMAND_NAME_RUNS_RESET = "runs reset"
COMMAND_NAME_RUNS_CANCEL = "runs cancel"
COMMAND_NAME_RUNS_DELETE = "runs delete"
COMMAND_NAME_RESOURCES = "resources"
COMMAND_NAME_RESOURCES_APPLY = "resources apply"
COMMAND_NAME_RESOURCES_CREATE = "resources create"
Expand Down Expand Up @@ -297,6 +298,7 @@ func (commands *commandCollectionImpl) addRunsCommands(factory spi.Factory, root
var runsSubmitLocalCommand spi.GalasaCommand
var runsResetCommand spi.GalasaCommand
var runsCancelCommand spi.GalasaCommand
var runsDeleteCommand spi.GalasaCommand

runsCommand, err = NewRunsCmd(rootCommand)
if err == nil {
Expand All @@ -313,6 +315,9 @@ func (commands *commandCollectionImpl) addRunsCommands(factory spi.Factory, root
runsResetCommand, err = NewRunsResetCommand(factory, runsCommand, rootCommand)
if err == nil {
runsCancelCommand, err = NewRunsCancelCommand(factory, runsCommand, rootCommand)
if err == nil {
runsDeleteCommand, err = NewRunsDeleteCommand(factory, runsCommand, rootCommand)
}
}
}
}
Expand All @@ -330,6 +335,7 @@ func (commands *commandCollectionImpl) addRunsCommands(factory spi.Factory, root
commands.commandMap[runsSubmitLocalCommand.Name()] = runsSubmitLocalCommand
commands.commandMap[runsResetCommand.Name()] = runsResetCommand
commands.commandMap[runsCancelCommand.Name()] = runsCancelCommand
commands.commandMap[runsDeleteCommand.Name()] = runsDeleteCommand
}

return err
Expand Down
155 changes: 155 additions & 0 deletions pkg/cmd/runsDelete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package cmd

import (
"log"

"github.com/galasa-dev/cli/pkg/api"
"github.com/galasa-dev/cli/pkg/galasaapi"
"github.com/galasa-dev/cli/pkg/runs"
"github.com/galasa-dev/cli/pkg/spi"
"github.com/galasa-dev/cli/pkg/utils"
"github.com/spf13/cobra"
)

// Objective: Allow the user to do this:
// run get --runname 12345
eamansour marked this conversation as resolved.
Show resolved Hide resolved
// And then show the results in a human-readable form.

// Variables set by cobra's command-line parsing.
type RunsDeleteCmdValues struct {
runName string
}

type RunsDeleteCommand struct {
values *RunsDeleteCmdValues
cobraCommand *cobra.Command
}

func NewRunsDeleteCommand(factory spi.Factory, runsCommand spi.GalasaCommand, rootCommand spi.GalasaCommand) (spi.GalasaCommand, error) {
cmd := new(RunsDeleteCommand)
err := cmd.init(factory, runsCommand, rootCommand)
return cmd, err
}

// ------------------------------------------------------------------------------------------------
// Public methods
// ------------------------------------------------------------------------------------------------
func (cmd *RunsDeleteCommand) Name() string {
return COMMAND_NAME_RUNS_DELETE
}

func (cmd *RunsDeleteCommand) CobraCommand() *cobra.Command {
return cmd.cobraCommand
}

func (cmd *RunsDeleteCommand) Values() interface{} {
return cmd.values
}

// ------------------------------------------------------------------------------------------------
// Private methods
// ------------------------------------------------------------------------------------------------

func (cmd *RunsDeleteCommand) init(factory spi.Factory, runsCommand spi.GalasaCommand, rootCommand spi.GalasaCommand) error {
var err error
cmd.values = &RunsDeleteCmdValues{}
cmd.cobraCommand, err = cmd.createCobraCommand(factory, runsCommand, rootCommand.Values().(*RootCmdValues))
return err
}

func (cmd *RunsDeleteCommand) createCobraCommand(
factory spi.Factory,
runsCommand spi.GalasaCommand,
rootCmdValues *RootCmdValues,
) (*cobra.Command, error) {

var err error
runsCmdValues := runsCommand.Values().(*RunsCmdValues)

runsDeleteCobraCmd := &cobra.Command{
Use: "delete",
Short: "Get the details of a test runname which ran or is running.",
techcobweb marked this conversation as resolved.
Show resolved Hide resolved
Long: "Get the details of a test runname which ran or is running, displaying the results to the caller.",
Args: cobra.NoArgs,
Aliases: []string{"runs delete"},
RunE: func(cobraCmd *cobra.Command, args []string) error {
return cmd.executeRunsDelete(factory, runsCmdValues, rootCmdValues)
},
}

runsDeleteCobraCmd.PersistentFlags().StringVar(&cmd.values.runName, "name", "", "the name of the test run we want to delete."+
" Cannot be used in conjunction with --requestor, --result or --active flags")
techcobweb marked this conversation as resolved.
Show resolved Hide resolved

runsDeleteCobraCmd.MarkFlagRequired("name")

runsCommand.CobraCommand().AddCommand(runsDeleteCobraCmd)

return runsDeleteCobraCmd, err
}

func (cmd *RunsDeleteCommand) executeRunsDelete(
factory spi.Factory,
runsCmdValues *RunsCmdValues,
rootCmdValues *RootCmdValues,
) error {

var err error

// Operations on the file system will all be relative to the current folder.
fileSystem := factory.GetFileSystem()

err = utils.CaptureLog(fileSystem, rootCmdValues.logFileName)
if err == nil {
rootCmdValues.isCapturingLogs = true

log.Println("Galasa CLI - Delete runs info about a execute")

// Get the ability to query environment variables.
env := factory.GetEnvironment()

var galasaHome spi.GalasaHome
galasaHome, err = utils.NewGalasaHome(fileSystem, env, rootCmdValues.CmdParamGalasaHomePath)
if err == nil {

// Read the bootstrap properties.
var urlService *api.RealUrlResolutionService = new(api.RealUrlResolutionService)
var bootstrapData *api.BootstrapData
bootstrapData, err = api.LoadBootstrap(galasaHome, fileSystem, env, runsCmdValues.bootstrap, urlService)
if err == nil {

var console = factory.GetStdOutConsole()
timeService := factory.GetTimeService()

apiServerUrl := bootstrapData.ApiServerURL
log.Printf("The API server is at '%s'\n", apiServerUrl)

authenticator := factory.GetAuthenticator(
apiServerUrl,
galasaHome,
)

var apiClient *galasaapi.APIClient
apiClient, err = authenticator.GetAuthenticatedAPIClient()

if err == nil {
// Call to process the command in a unit-testable way.
err = runs.RunsDelete(
cmd.values.runName,
console,
apiServerUrl,
apiClient,
timeService,
)
}
}
}
}

log.Printf("executeRunsDelete returning %v", err)
return err
}
Loading
Loading