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 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
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 "ixture" \
> build/coverage-sanitised.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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,20 @@ galasactl runs get --name C1234 --format badFormatterName
```
For a complete list of supported parameters see [here](./docs/generated/galasactl_runs_get.md).

## runs delete

This command deletes a test run from an ecosystem's RAS. The name of the test run to delete can be provided to delete it along with any associated artifacts that have been stored.

### Examples

A run named "C1234" can be deleted using the following command:

```
galasactl runs delete --name C1234
```

A complete list of supported parameters for the `runs delete` command is available [here](./docs/generated/galasactl_runs_delete.md)

## runs download

This command downloads all artifacts for a test run that are stored in an ecosystem's RAS.
Expand Down
8 changes: 8 additions & 0 deletions docs/generated/errors-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ 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 named '{}' failed. Cause is {}
- GAL1158E: An attempt to delete a run named '{}' failed. Sending the delete request to the Galasa service failed. Cause is {}
- GAL1159E: An attempt to delete a run named '{}' failed. Unexpected http status code {} received from the server.
- GAL1160E: An attempt to delete a run named '{}' failed. Unexpected http status code {} received from the server. Error details from the server could not be read. Cause: {}
- GAL1161E: An attempt to delete a run named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
- GAL1162E: An attempt to delete a run named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are: '{}'
- GAL1163E: The run named '{}' could not be deleted because it was not found by the Galasa service. Try listing runs using 'galasactl runs get' to identify the one you wish to delete
- GAL1164E: An attempt to delete a run named '{}' failed. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
- 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) - Delete a named test run.
* [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

Delete a named test run.

### Synopsis

Delete a named test run.

```
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.
```

### 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
4 changes: 4 additions & 0 deletions pkg/cmd/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ func (factory *RealFactory) GetAuthenticator(apiServerUrl string, galasaHome spi
jwtCache := auth.NewJwtCache(factory.GetFileSystem(), galasaHome, factory.GetTimeService())
return auth.NewAuthenticator(apiServerUrl, factory.GetFileSystem(), galasaHome, factory.GetTimeService(), factory.GetEnvironment(), jwtCache)
}

func (*RealFactory) GetByteReader() spi.ByteReader {
return utils.NewByteReader()
}
Loading