diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ada56ed..eeb5981 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -44,7 +44,7 @@ jobs: name: Build & push Docker standalone image with: image: qest - tags: standalone-latest, standalone-${{ github.ref_name }} + tags: standalone, standalone-latest, standalone-${{ github.ref_name }} registry: ghcr.io dockerfile: standalone.dockerfile username: ${{ secrets.DOCKER_USERNAME }} @@ -60,7 +60,7 @@ jobs: name: Build & push Docker bundle image with: image: qest - tags: bundle-latest, bundle-${{ github.ref_name }} + tags: bundle, bundle-latest, bundle-${{ github.ref_name }} registry: ghcr.io dockerfile: bundle.dockerfile username: ${{ secrets.DOCKER_USERNAME }} diff --git a/README.md b/README.md index 09828fb..30722e1 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ You need to provide: - the scripts: the folder containing them wil be mounted on the `/scripts` container folder -Please note: for this default image to work, YAML files have to reference the _File_ scripts in the `scripts/{filename}` form. See [docs](https://github.com/Geims83/qest/wiki/YamlFormat). +Please note: for this default image to work, YAML files have to reference the _File_ scripts in the `scripts/{filename}` form. See [docs](https://github.com/Geims83/qest/wiki/YAML-test-definition). Run the image binding the `tests`, `scripts` and `db` directories and providing the correct environment variables: ``` diff --git a/docs/yamlSchema.json b/docs/yamlSchema.json new file mode 100644 index 0000000..174f089 --- /dev/null +++ b/docs/yamlSchema.json @@ -0,0 +1,147 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema", + + "definitions": { + "Test": { + "properties": { + "name": { "type": "string" }, + "variables": { + "type": "object", + "additionalProperties": true + }, + "before": { "$ref": "#/definitions/Scripts" }, + "steps": { + "type": "array", + "items": { "$ref": "#/definitions/TestStep" } + }, + "after": { "$ref": "#/definitions/Scripts" } + }, + "required": ["name", "steps"], + "additionalProperties": false + }, + "TestStep": { + "properties": { + "name": { "type": "string" }, + "command": { "$ref": "#/definitions/TestCommand" }, + "results": { "$ref": "#/definitions/ResultGroup" }, + "asserts": { + "type": "array", + "items": { "$ref": "#/definitions/Assert" } + } + }, + "required": ["name", "command", "results"], + "additionalProperties": false + }, + "TestCommand": { + "properties": { + "commandText": { "type": "string" }, + "parameters": { "additionalProperties": true } + }, + "required": ["commandText"], + "additionalProperties": false + }, + "ResultGroup": { + "properties": { + "resultSets": { + "type": "array", + "items": { "$ref": "#/definitions/ResultSet" } + }, + "outputParameters": { + "type": "array", + "items": { "$ref": "#/definitions/OutputParameter" } + }, + "returnCode": { "type": "number" } + }, + "additionalProperties": false + }, + "ResultSet": { + "properties": { + "name": { "type": "string" }, + "rowNumber": { "type": "number" }, + "columns": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "type": { "$ref": "#/definitions/SqlDbType" } + }, + "required": ["name", "type"], + "additionalProperties": false + } + } + }, + "required": ["name", "columns"], + "additionalProperties": false + }, + "OutputParameter": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "type": { "$ref": "#/definitions/SqlDbType" }, + "value": {} + }, + "required": ["name", "type", "value"], + "additionalProperties": false + }, + "Assert": { + "type": "object", + "properties": { + "sqlQuery": { "type": "string" }, + "scalarType": { "$ref": "#/definitions/SqlDbType" }, + "scalarValue": {} + }, + "required": ["sqlQuery", "scalarType", "scalarValue"], + "additionalProperties": false + }, + "Scripts": { + "type": "array", + "items": { + "$ref": "#/definitions/Script" + } + }, + "Script": { + "type": "object", + "properties": { + "type": { + "$ref": "#/definitions/ScriptType" + }, + "values": { + "type": "array", + "items": { "type": "string" } + } + }, + "additionalProperties": false + }, + "ScriptType": { + "type": "string", + "enum": ["File", "Inline"] + }, + "SqlDbType": { + "type": "string", + "enum": [ + "Bit", + "TinyInt", + "SmallInt", + "BigInt", + "Float", + "Int", + "NVarChar", + "Date", + "DateTime", + "DateTime2", + "DateTimeOffset", + "Time", + "Real", + "Decimal", + "Money" + ] + } + }, + + "type": "array", + "items": { + "$ref": "#/definitions/Test" + }, + "additionalProperties": false +} diff --git a/samples/tests/sampleSp.yml b/samples/tests/sampleSp.yml index 20d0de7..5058182 100644 --- a/samples/tests/sampleSp.yml +++ b/samples/tests/sampleSp.yml @@ -1,3 +1,6 @@ +# the next row is a directive for validating this file using Yaml VSCode addin (redhat.vscode-yaml) +# yaml-language-server: $schema=../../docs/yamlSchema.json + - name: SampleSP variables: nameVar: SampleName @@ -25,7 +28,7 @@ - name: TinyIntValue type: TinyInt - name: SmallintValue - type: Smallint + type: SmallInt - name: IntValue type: Int - name: BigIntValue @@ -75,7 +78,7 @@ - name: TinyIntValue type: TinyInt - name: SmallintValue - type: Smallint + type: SmallInt - name: IntValue type: Int - name: BigIntValue diff --git a/src/TestBase/Test.cs b/src/TestBase/Test.cs index d10aff2..7b1954e 100644 --- a/src/TestBase/Test.cs +++ b/src/TestBase/Test.cs @@ -7,7 +7,6 @@ namespace TestBase public class Test { public string Name { get; set; } - public string Description { get; set; } public Scripts? Before { get; set; } [YamlIgnore] public SqlConnection? Connection { get; set; } diff --git a/src/qest/Commands/GenerateCommand.cs b/src/qest/Commands/GenerateCommand.cs index ef2c070..ff392e9 100644 --- a/src/qest/Commands/GenerateCommand.cs +++ b/src/qest/Commands/GenerateCommand.cs @@ -30,6 +30,9 @@ ORDER BY p.parameter_id "; + internal const string yamlSchema = + @"# yaml-language-server: $schema=https://raw.githubusercontent.com/Geims83/qest/features/yamlschema/docs/yamlSchema.json"; + internal static async Task Run(DirectoryInfo? folder, string tcs) { var sqlConnection = new SqlConnection(tcs); @@ -110,8 +113,7 @@ private static Test GenerateNewTest(string schemaName, string spName) string completeName = $"{schemaName}.{spName}"; currentTest.Name = $"{completeName}"; - currentTest.Description = $"Template for {completeName} tests"; - currentStep.Name = $"Step for {completeName} test"; + currentStep.Name = $"Template for {completeName} test"; currentCommand.CommandText = $"[{schemaName}].[{spName}]"; return currentTest; @@ -127,9 +129,10 @@ static async Task SafeWriteYamlAsync(DirectoryInfo folder, Test testTemplate) try { - using var stream = new StreamWriter(output.FullName, false); + await using var stream = new StreamWriter(output.FullName, false); - string yaml = serializer.Serialize(testTemplate); + string yaml = serializer.Serialize(new Test[] {testTemplate}); + await stream.WriteLineAsync(yamlSchema); await stream.WriteAsync(yaml); Console.WriteLine($"Created template {output.Name}");