Skip to content

Commit 510f28c

Browse files
committed
fix: add all relevant test
1 parent d539068 commit 510f28c

30 files changed

+1429
-187
lines changed

src/dotnet/Schema.Generator/taskfile.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tasks:
1111
- rm -rf dist/dotnet/*
1212
- mkdir -p dist/dotnet
1313
# SchemaGenerator DOTNET
14-
schemagenerator_bin-gen:
14+
bin-gen:
1515
desc: Builds a single binary of the schema generator for each platform
1616
deps:
1717
- clean_dotnet
@@ -28,7 +28,7 @@ tasks:
2828
env:
2929
VERSION: "{{.GIT_TAG}}"
3030

31-
schemagenerator_test:
31+
test:
3232
desc: Runs the tests for SchemaGenerator
3333
cmd: |
3434
cd src/dotnet/Schema.Generator
@@ -38,7 +38,7 @@ tasks:
3838
env:
3939
VERSION: 0.0.1
4040

41-
schemagenerator_show-coverage:
41+
show-coverage:
4242
desc: Shows coverage in a visual tool
4343
preconditions:
4444
- dotnet --help
@@ -49,4 +49,4 @@ tasks:
4949
- |
5050
cd src/dotnet/Schema.Generator
5151
reportgenerator -reports:".coverage/*/coverage.cobertura.xml" -targetdir:".coverage/report" -reporttypes:Html
52-
{{if eq OS "windows"}}start ""{{else}}open{{end}} .coverage/report/index.html
52+
{{if eq OS "windows"}}start ""{{else}}open{{end}} .coverage/report/index.html

src/go/async-api-gen-doc/cmd/async-api-gen-doc/root_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func Test_root_ok(t *testing.T) {
13-
baseDir := "test/bazquxsample"
13+
baseDir := "test/foo.sample"
1414
b := new(bytes.Buffer)
1515

1616
cmd := asyncapigendoc.AsyncAPIGenCmd

src/go/async-api-gen-doc/cmd/async-api-gen-doc/single_ctx_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func Test_single_repo_Analyis_runs_ok(t *testing.T) {
15-
baseDir := "test/bazquxsample"
15+
baseDir := "test/foo.sample"
1616

1717
searchParentDir := fmt.Sprintf("local://%s", fshelper.DebugDirHelper(t, baseDir, "cmd/async-api-gen-doc", "../../"))
1818

src/go/async-api-gen-doc/internal/fshelper/fshelper_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func Test_ListFiles_in_mock_directory(t *testing.T) {
15-
baseDir := "test/bazquxsample"
15+
baseDir := "test/foo.sample"
1616

1717
got, err := fshelper.ListFiles(fshelper.DebugDirHelper(t, baseDir, "internal/fshelper", "../../"))
1818
if err != nil {
@@ -23,9 +23,9 @@ func Test_ListFiles_in_mock_directory(t *testing.T) {
2323
expectPath string
2424
expectType string
2525
}{
26-
{"someeventpoco.cs", "test/bazquxsample/src/someeventpoco.cs", "cs"},
27-
{"index.md", "test/bazquxsample/index.md", "md"},
28-
{"sample.tf", "test/bazquxsample/infra/sample.tf", "tf"},
26+
{"someeventpoco.cs", "test/foo.sample/src/someeventpoco.cs", "cs"},
27+
{"index.md", "test/foo.sample/index.md", "md"},
28+
{"sample.tf", "test/foo.sample/infra/sample.tf", "tf"},
2929
}
3030
var found *fshelper.FileList = nil
3131
for _, tt := range ttests {

src/go/async-api-gen-doc/internal/gendoc/gendoc_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ func Test_GenDoc_marshalled_successfully_from_string(t *testing.T) {
1717
expect gendoc.GenDoc
1818
}{
1919
"when using full property names": {
20-
`parent=domain-foo~bar-assigned id=BizContextAreaEvent category=message type=example subscribers=bazquxdemand,bazquxfoo,bazquxbar`,
20+
`parent=domain-foo~bar-assigned id=BizContextAreaEvent category=message type=example subscribers=bazquxoperation,bazquxfoo,bazquxbar`,
2121
gendoc.GenDoc{Id: "BizContextAreaEvent", Parent: "domain-foo~bar-assigned", CategoryType: gendoc.MessageBlock, ContentType: gendoc.Example},
2222
},
2323
"when using shorthand property names": {
24-
`parent=domain-foo~bar-assigned id=BizContextAreaEvent c=message type=example sbs=bazquxdemand,bazquxfoo,bazquxbar`,
24+
`parent=domain-foo~bar-assigned id=BizContextAreaEvent c=message type=example sbs=bazquxoperation,bazquxfoo,bazquxbar`,
2525
gendoc.GenDoc{Id: "BizContextAreaEvent", Parent: "domain-foo~bar-assigned", CategoryType: gendoc.MessageBlock, ContentType: gendoc.Example},
2626
},
2727
"when setting serviceId": {
28-
`parent=domain-foo~bar-assigned id=BizContextAreaEvent serviceId=bazquxsample c=message type=example sbs=bazquxdemand,bazquxfoo,bazquxbar producers=bazquxsample`,
28+
`parent=domain-foo~bar-assigned id=BizContextAreaEvent serviceId=bazquxsample c=message type=example sbs=bazquxoperation,bazquxfoo,bazquxbar producers=bazquxsample`,
2929
gendoc.GenDoc{Id: "BizContextAreaEvent",
3030
Parent: "domain-foo~bar-assigned",
3131
CategoryType: gendoc.MessageBlock,
@@ -34,7 +34,7 @@ func Test_GenDoc_marshalled_successfully_from_string(t *testing.T) {
3434
},
3535
},
3636
"when setting channelId": {
37-
`parent=domain-foo~bar-assigned id=BizContextAreaEvent serviceId=bazquxsample channelId=bazquxsample c=message type=example sbs=bazquxdemand,bazquxfoo,bazquxbar producers=bazquxsample`,
37+
`parent=domain-foo~bar-assigned id=BizContextAreaEvent serviceId=bazquxsample channelId=bazquxsample c=message type=example sbs=bazquxoperation,bazquxfoo,bazquxbar producers=bazquxsample`,
3838
gendoc.GenDoc{Id: "BizContextAreaEvent",
3939
Parent: "domain-foo~bar-assigned",
4040
CategoryType: gendoc.MessageBlock,
@@ -44,7 +44,7 @@ func Test_GenDoc_marshalled_successfully_from_string(t *testing.T) {
4444
},
4545
},
4646
"when including closing comments": {
47-
`parent=domain-foo~bar-assigned id=BizContextAreaEvent serviceId=bazquxsample channelId=bazquxsample c=message type=example sbs=bazquxdemand,bazquxfoo,bazquxbar producers=bazquxsample -->`,
47+
`parent=domain-foo~bar-assigned id=BizContextAreaEvent serviceId=bazquxsample channelId=bazquxsample c=message type=example sbs=bazquxoperation,bazquxfoo,bazquxbar producers=bazquxsample -->`,
4848
gendoc.GenDoc{Id: "BizContextAreaEvent",
4949
Parent: "domain-foo~bar-assigned",
5050
CategoryType: gendoc.MessageBlock,
@@ -73,7 +73,7 @@ func Test_Unmarshal_from_token_should_succeed(t *testing.T) {
7373
expect gendoc.GenDoc
7474
}{
7575
"when using correct annotation": {
76-
token.Token{MetaAnnotation: `parent=domain-foo~bar-assigned id=BizContextAreaEvent serviceId=bazquxsample channelId=bazquxsample c=message type=example sbs=bazquxdemand,bazquxfoo,bazquxbar producers=bazquxsample`},
76+
token.Token{MetaAnnotation: `parent=domain-foo~bar-assigned id=BizContextAreaEvent serviceId=bazquxsample channelId=bazquxsample c=message type=example sbs=bazquxoperation,bazquxfoo,bazquxbar producers=bazquxsample`},
7777
gendoc.GenDoc{Id: "BizContextAreaEvent",
7878
Parent: "domain-foo~bar-assigned",
7979
CategoryType: gendoc.MessageBlock,

src/go/async-api-gen-doc/internal/generate/generate_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package generate_test
22

33
import (
44
"bytes"
5-
"os"
65
"testing"
76

87
"github.com/dnitsch/async-api-generator/internal/fshelper"
@@ -11,12 +10,12 @@ import (
1110
log "github.com/dnitsch/simplelog"
1211
)
1312

14-
var baseDir = "test/bazquxsample"
13+
var baseDir = "test/foo.sample"
1514

1615
func Test_SAMPLE_Generate_ProcessedInputs_from_directory_input(t *testing.T) {
1716

1817
inputs, _ := fshelper.ListFiles(fshelper.DebugDirHelper(t, baseDir, "internal/generate", "../../"))
19-
g := generate.New(&generate.Config{ParserConfig: parser.Config{ServiceId: "bazquxsample", ServiceRepoUrl: "https://github.com/asynapi-gen"}}, log.New(os.Stderr, log.ErrorLvl))
18+
g := generate.New(&generate.Config{ParserConfig: parser.Config{ServiceId: "bazquxsample", ServiceRepoUrl: "https://github.com/asynapi-gen"}}, log.New(&bytes.Buffer{}, log.ErrorLvl))
2019
g.LoadInputsFromFiles(inputs)
2120

2221
err := g.GenDocBlox()

src/go/async-api-gen-doc/internal/generate/template_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func Test_BuildAsyncAPIRoot_from_tree(t *testing.T) {
153153
},
154154
}
155155

156-
g := generate.New(globalConf, log.New(os.Stdout, log.DebugLvl))
156+
g := generate.New(globalConf, log.New(&bytes.Buffer{}, log.DebugLvl))
157157
g.LoadInputsFromFiles(input)
158158

159159
if err := g.ConvertProcessed(); err != nil {
@@ -171,7 +171,7 @@ func Test_BuildAsyncAPIRoot_from_tree(t *testing.T) {
171171
got, _ := fshelper.ListFiles(testDir)
172172

173173
if len(got) != 2 {
174-
t.Error("wanted 2 services written out")
174+
t.Errorf("got (%v) wanted 2 services written out", len(got))
175175
}
176176

177177
// for _, file := range got {

src/go/async-api-gen-doc/internal/parser/parser.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -315,16 +315,16 @@ func (p *Parser) serviceUrn(id string) string {
315315
// locals {
316316
// topics = [
317317
// //+gendoc category=channel type=nameId
318-
// "domain-demand~demand-cancelled-domain-event",
318+
// "foo~bar",
319319
// //-gendoc
320-
// "domain-demand~demand-updated-domain-event",
320+
// "domain-operation~operation-updated-domain-event",
321321
// ...
322322
// ]
323323
//
324324
// ...
325325
// ```
326326
//
327-
// The extracted Id will be `domain-demand~demand-cancelled-domain-event`
327+
// The extracted Id will be `foo~bar`
328328
//
329329
// If an Id is successfully extracted it is assigned to the Id value and it is returned else the object is returned unchanged
330330
func attemptIdExtract(a gendoc.GenDoc, docBlock *GenDocBlock) gendoc.GenDoc {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- //+gendoc type=description category=info id=foo.sample -->
2+
# Sample
3+
4+
This is some lengthy description of the service itself.
5+
6+
encompassed and in a Markdown readable format as per usual
7+
8+
<!--//-gendoc -->

src/go/async-api-gen-doc/test/foo.sample/infra/sample.tf

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
some: yml
2+
3+
# //+gendoc category=info type=description
4+
envs:
5+
dev:
6+
url: "dev.domain.com"
7+
preprod:
8+
url: "pre.domain.com"
9+
prod:
10+
url: "prod.domain.com"
11+
# //-gendoc
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
locals {
2+
topics = [
3+
//+gendoc category=channel type=nameId service_id=[foo.bar.app]
4+
"foo-stuff~operation-cancelled-domain-event",
5+
//-gendoc
6+
"foo-stuff~operation-updated-domain-event",
7+
"foo-stuff~operation-completed-domain-event",
8+
"foo-stuff~operation-skipped-domain-event",
9+
]
10+
11+
subscriptions = [
12+
{
13+
//+gendoc category=channel id=foo-stuff-subscription service_id=[foo.bar.app]
14+
topic : azurerm_servicebus_topic.cancelled-topic,
15+
name : "foo-stuff-subscription"
16+
//-gendoc
17+
},
18+
{
19+
/*
20+
//+gendoc category=channel id=foo-stuff-subscription type=description service_id=[foo.bar.app]
21+
This channel is used to convey subscriptions
22+
//-gendoc
23+
*/
24+
topic : azurerm_servicebus_topic.ItemSortation-waypointComplete-topic,
25+
//+gendoc category=channel id=foo-stuff-subscription type=nameId service_id=[foo.bar.app]
26+
//-gendoc
27+
name : "foo-stuff-subscription"
28+
},
29+
{
30+
topic : azurerm_servicebus_topic.ItemSortation-operationWaypointStarted-topic,
31+
name : "foo-stuff-subscription"
32+
},
33+
34+
]
35+
}
36+
37+
resource "azurerm_servicebus_topic" "default" {
38+
for_each = toset(local.topics)
39+
...
40+
}
41+
42+
# Add the proper subscriptions
43+
resource "azurerm_servicebus_subscription" "default" {
44+
for_each = toset(local.topics)
45+
...
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"$id": "https://example.com/address.schema.json",
3+
"$schema": "https://json-schema.org/draft/2020-12/schema",
4+
"description": "An address similar to http://microformats.org/wiki/h-card",
5+
"type": "object",
6+
"properties": {
7+
"postOfficeBox": {
8+
"type": "string"
9+
},
10+
"extendedAddress": {
11+
"type": "string"
12+
},
13+
"streetAddress": {
14+
"type": "string"
15+
},
16+
"locality": {
17+
"type": "string"
18+
},
19+
"region": {
20+
"type": "string"
21+
},
22+
"postalCode": {
23+
"type": "string"
24+
},
25+
"countryName": {
26+
"type": "string"
27+
}
28+
},
29+
"required": [ "locality", "region", "countryName" ],
30+
"dependentRequired": {
31+
"postOfficeBox": [ "streetAddress" ],
32+
"extendedAddress": [ "streetAddress" ]
33+
}
34+
}
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
3+
/*
4+
//+gendoc category=pubOperation type=description id=BuxQuz parent=foo-stuff~operation-cancelled-domain-event isSub=true
5+
this operation publishes this message
6+
//-gendoc
7+
*/
8+
9+
// parent is the channel i.e. queue or topic name
10+
// id is the name of the message itself
11+
//+gendoc id=BuxQuz category=message type=example
12+
namespace Foo.Bar.Contracts.Events;
13+
14+
public class BuxQuz : FooMessage<BuxQuzPayload>
15+
{
16+
public BuxQuz(BuxQuzPayload payload)
17+
{
18+
MessageTypeName = nameof(BuxQuz);
19+
Guid = Guid.NewGuid();
20+
...
21+
}
22+
}
23+
//-gendoc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Diagnostics;
2+
3+
namespace Foo.Bar.Services.Foo;
4+
5+
6+
//+gendoc id=Bar category=message type=example
7+
public class Bar () {
8+
}
9+
//-gendoc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Foo.Bar.Services.BuzQux.Contracts;
2+
3+
public static class BuzQuxServiceConstants
4+
{
5+
public const string Name = "foo-other-services-stuff";
6+
7+
public static class Events
8+
{
9+
public const string BuxQuz = "some-area-event";
10+
}
11+
}

0 commit comments

Comments
 (0)