Skip to content

Commit

Permalink
Merge pull request #374 from reubenmiller/fix-build-errors
Browse files Browse the repository at this point in the history
build: improve error handling and case insensitivity
  • Loading branch information
reubenmiller authored May 19, 2024
2 parents 5ab2e05 + f0a0d33 commit 2aac348
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions api/spec/json/remoteAccessConfigurations.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"examples": {
"go": [
{
"command": "c8y remoteaccess configurations update --device device01 --id 1 --name hello",
"command": "c8y remoteaccess configurations update --device device01 --id 1 --newName hello",
"description": "Update an existing remote access configuration",
"assertStdOut": {
"json": {
Expand All @@ -117,7 +117,7 @@
],
"powershell": [
{
"command": "Update-RemoteAccessConfiguration -Device device01 -Id 1 -Name hello",
"command": "Update-RemoteAccessConfiguration -Device device01 -Id 1 -NewName hello",
"description": "Update an existing remote access configuration",
"skipTest": true
}
Expand Down
4 changes: 2 additions & 2 deletions api/spec/yaml/remoteAccessConfigurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ commands:
powershell: Update-RemoteAccessConfiguration
examples:
go:
- command: c8y remoteaccess configurations update --device device01 --id 1 --name hello
- command: c8y remoteaccess configurations update --device device01 --id 1 --newName hello
description: Update an existing remote access configuration
assertStdOut:
json:
path: r//service/remoteaccess/devices/\d+/configurations/1$
skipTest: true
powershell:
- command: Update-RemoteAccessConfiguration -Device device01 -Id 1 -Name hello
- command: Update-RemoteAccessConfiguration -Device device01 -Id 1 -NewName hello
description: Update an existing remote access configuration
skipTest: true
method: PUT
Expand Down
2 changes: 1 addition & 1 deletion cmd/gen-tests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func formatJsonAssertion(jsonAssertion map[string]string, propType string, prop
if strings.HasSuffix(prop, ".data") || strings.EqualFold(propType, "json_custom") {
data := make(map[string]interface{})
if err := jsonUtilities.ParseJSON(values[0], data); err != nil {
loggerS.Warnf("Could not parse shorthand json. %s", err)
loggerS.Warnf("Could not parse shorthand json. error=%s, data=%s", err, values[0])
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/remoteaccess/configurations/update/update.auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions scripts/build-cli-tests.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#!/bin/bash
#!/usr/bin/env bash
set -e
#--------------------------------------------
# Generate the command tests from the specs
#--------------------------------------------

# Delete existing folders to ensure there are no stale test files left behind
rm -Rf ./tests/auto

for file in $( find ./api/spec \( -name "*.yml" -or -name "*.yaml" \) )
while IFS= read -r -d '' file
do
name=$( basename "$file" | sed -E 's/.ya?ml//g' | tr A-Z a-z )
go run cmd/gen-tests/main.go "./tests/mocks.yaml" "$file" "./tests/auto/$name/tests"
code=$?
if [[ $code -ne 0 ]]; then
echo "Error code: $file, exit_code=$code"
name=$( basename "$file" | sed -E 's/.ya?ml//g' | tr '[:upper:]' '[:lower:]' )
if ! go run cmd/gen-tests/main.go "./tests/mocks.yaml" "$file" "./tests/auto/$name/tests"; then
echo "Failed to generate cli tests: $file" >&2
exit 1
fi

done
done < <( find ./api/spec \( -name "*.yml" -or -name "*.yaml" \) -print0 )
2 changes: 1 addition & 1 deletion scripts/build-cli/New-C8yApiGoCommand.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$NameCamel = ($Name[0].ToString().ToUpperInvariant() + $Name.Substring(1)) -replace '-(\p{L})', { $_.Groups[1].Value.ToUpper() }
$PackageName = $Name.ToLower() -replace "-", "_"

$FileName = $PackageName
$FileName = $NameCamel[0].ToString().ToLowerInvariant() + $NameCamel.Substring(1)
$File = Join-Path -Path $OutputDir -ChildPath ("{0}.auto.go" -f $FileName)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests:
remoteaccess/configurations_update_Update an existing remote access configuration:
command: c8y remoteaccess configurations update --device device01 --id 1 --name hello
command: c8y remoteaccess configurations update --device device01 --id 1 --newName hello
exit-code: 0
skip: true
stdout:
Expand Down

0 comments on commit 2aac348

Please sign in to comment.