From 7d0d72a0f8ad65b891564a2661ea1a9310a3ec20 Mon Sep 17 00:00:00 2001 From: peefy Date: Fri, 8 Dec 2023 17:01:09 +0800 Subject: [PATCH] test: add e2e tests for all platforms Signed-off-by: peefy --- .github/workflows/example-e2e-tests.yaml | 40 +++++++- examples/import/Makefile | 1 + examples/import/jsonschema/Makefile | 5 + examples/import/jsonschema/test.schema.json | 101 ++++++++++++++++++++ examples/import/jsonschema/test.schema.k | 38 ++++++++ examples/test.ps1 | 21 ++++ examples/test.sh | 3 +- 7 files changed, 205 insertions(+), 4 deletions(-) create mode 100644 examples/import/jsonschema/Makefile create mode 100644 examples/import/jsonschema/test.schema.json create mode 100644 examples/import/jsonschema/test.schema.k create mode 100755 examples/test.ps1 diff --git a/.github/workflows/example-e2e-tests.yaml b/.github/workflows/example-e2e-tests.yaml index 092588d..ab68110 100644 --- a/.github/workflows/example-e2e-tests.yaml +++ b/.github/workflows/example-e2e-tests.yaml @@ -7,7 +7,7 @@ on: branches: - main jobs: - example-e2e-test: + ubuntu: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -15,9 +15,45 @@ jobs: with: go-version: "1.19" - - name: kcl Installation + - name: KCL Installation run: go install ./cmd/kcl - name: Example tests shell: bash -ieo pipefail {0} run: PATH=$PATH:$HOME/go/bin ./examples/test.sh + + macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v1 + with: + go-version: "1.19" + + - name: KCL Installation + run: go install ./cmd/kcl + + - name: e2e tests + run: PATH=$PATH:$HOME/go/bin kcl ./examples/kubernetes.k + + - name: Example tests + shell: bash -ieo pipefail {0} + run: PATH=$PATH:$HOME/go/bin ./examples/test.sh + + windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + + - name: Install Make + run: choco install make -y + + - name: KCL Installation and Tests + shell: powershell + run: | + iwr -useb get.scoop.sh -outfile 'install.ps1' + .\install.ps1 -RunAsAdmin + scoop bucket add kcl-lang https://github.com/kcl-lang/scoop-bucket.git + scoop install kcl-lang/kcl + kcl.exe .\examples\kubernetes.k + .\examples\test.ps1 diff --git a/examples/import/Makefile b/examples/import/Makefile index 6de8565..d13ac3a 100644 --- a/examples/import/Makefile +++ b/examples/import/Makefile @@ -3,3 +3,4 @@ run: test: make -C crd + make -C jsonschema diff --git a/examples/import/jsonschema/Makefile b/examples/import/jsonschema/Makefile new file mode 100644 index 0000000..ba68b3d --- /dev/null +++ b/examples/import/jsonschema/Makefile @@ -0,0 +1,5 @@ +run: + kcl import -m jsonschema test.schema.json + +test: + make run diff --git a/examples/import/jsonschema/test.schema.json b/examples/import/jsonschema/test.schema.json new file mode 100644 index 0000000..99ca8c0 --- /dev/null +++ b/examples/import/jsonschema/test.schema.json @@ -0,0 +1,101 @@ +{ + "$id": "https://example.com/monaco.manifest.schema.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "Dynatrace Monitoring as Code Manifest File", + "type": "object", + "properties": { + "manifestVersion": { + "type": "string", + "description": "The schema version this manifest conforms to - e.g. 1.0" + }, + "projects": { + "type": "array", + "description": "The projects grouped by this manifest", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The name of this project" + }, + "type": { + "type": "string", + "description": "Optional Type of this project. Default: Simple", + "oneOf": [ + { + "const": "simple", + "description": "A simple project, directly containing configuration. Default." + }, + { + "const": "grouping", + "description": "A grouping project, containing several sub-projects." + } + ] + }, + "path": { + "type": "string", + "description": "Optional filepath of the project relative to the manifest.yaml location. Defaults to name" + } + }, + "required": [ + "name" + ] + } + }, + "environmentGroups": { + "description": "The Environment groups to which projects in this manifest are deployed", + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The name of this environment group" + }, + "environments": { + "description": "The environments in this group", + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The name of this environment" + }, + "url": { + "description": "The URL of this environment", + "type": "object", + "properties": { + "type": { + "description": "Optional Type of URL definition.", + "type": "string", + "oneOf": [ + { + "const": "value", + "description": "URL directly defined in the 'value'. Default." + }, + { + "const": "environment", + "description": "URL defined by an environment variable name in 'value' to read from." + } + ] + }, + "value": { + "type": "string", + "description": "The value of the URL, based on type either an URL or environment variable name" + } + } + } + } + } + } + } + } + } + }, + "required": [ + "manifestVersion", + "projects", + "environmentGroups" + ] +} \ No newline at end of file diff --git a/examples/import/jsonschema/test.schema.k b/examples/import/jsonschema/test.schema.k new file mode 100644 index 0000000..ebeb6a7 --- /dev/null +++ b/examples/import/jsonschema/test.schema.k @@ -0,0 +1,38 @@ +""" +This file was generated by the KCL auto-gen tool. DO NOT EDIT. +Editing this file might prove futile when you re-run the KCL auto-gen generate command. +""" + +schema MonacoManifestSchema: + """ + MonacoManifestSchema + + Attributes + ---------- + manifest_version : str, required + The schema version this manifest conforms to - e.g. 1.0 + projects : [items], required + The projects grouped by this manifest + environment_groups : [items], required + The Environment groups to which projects in this manifest are deployed + """ + + manifest_version: str + projects: [items] + environment_groups: [items] + +schema Url: + """ + The URL of this environment + + Attributes + ---------- + type : str, optional + Optional Type of URL definition. + value : str, optional + The value of the URL, based on type either an URL or environment variable name + """ + + type?: str + value?: str + diff --git a/examples/test.ps1 b/examples/test.ps1 new file mode 100755 index 0000000..2d19360 --- /dev/null +++ b/examples/test.ps1 @@ -0,0 +1,21 @@ +# Stop on error. +# Note: Before you start tests, please install kcl and kpm +# kcl Installation: https://kcl-lang.io/docs/user_docs/getting-started/install +# kpm Installation: https://kcl-lang.io/docs/user_docs/guides/package-management/installation +$ErrorActionPreference = "Stop" +$pwd = Split-Path -Parent $MyInvocation.MyCommand.Path + +$paths = @("configuration", "validation", "abstraction", "definition", "konfig", "mutation", "data-integration", "automation", "package-management", "kubernetes", "codelab", "server") +foreach ($path in $paths) { + Write-Host "Testing $path ..." + Set-Location -Path "$pwd\$path" + try { + & make test | Out-Host + Write-Host "Test SUCCESSED - $path" -ForegroundColor Green + } + catch { + Write-Host "Test FAILED - $path" -ForegroundColor Red + exit 1 + } + Write-Host "" +} diff --git a/examples/test.sh b/examples/test.sh index 43e7d70..243db4c 100755 --- a/examples/test.sh +++ b/examples/test.sh @@ -2,9 +2,8 @@ # Stop on error. -# Note: Before you start tests, please install kcl and kpm +# Note: Before you start tests, please install kcl # kcl Installation: https://kcl-lang.io/docs/user_docs/getting-started/install -# kpm Installation: https://kcl-lang.io/docs/user_docs/guides/package-management/installation set -e