diff --git a/README.md b/README.md index d68bb12..ad2f411 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,6 @@ Golang SDK to emit [CDEvents](https://cdevents.dev). The SDK can be used to create CDEvents and send them as CloudEvents, as well as parse a received CloudEvent into a CDEvent. -## Disclaimer 🚧 - -This SDK is work in work in progress, it will be maintained in sync with the -specification and it now covers all events from the specification. -The [old SDK/CLI][old-sdk] is still available, with the caveat that it's -not aligned with the new version of the specification. - ## Get started Add the module as dependency using go mod: diff --git a/pkg/api/artifactpackaged.go b/pkg/api/artifactpackaged.go index 4f6f6de..9b34535 100644 --- a/pkg/api/artifactpackaged.go +++ b/pkg/api/artifactpackaged.go @@ -32,7 +32,7 @@ var ( ArtifactPackagedEventV1 CDEventType = CDEventType{ Subject: "artifact", Predicate: "packaged", - Version: "0.1.0", + Version: "0.1.1", } ) diff --git a/pkg/api/bindings_test.go b/pkg/api/bindings_test.go index 743f700..994b34f 100644 --- a/pkg/api/bindings_test.go +++ b/pkg/api/bindings_test.go @@ -105,653 +105,12 @@ var ( eventNonJsonCustomData *ArtifactPackagedEvent eventJsonCustomDataUnmarshalled *ArtifactPackagedEvent - pipelineRunQueuedEventJsonTemplate = ` -{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.pipelinerun.queued.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "pipelineRun", - "content": { - "pipelineName": "myPipeline", - "url": "https://www.example.com/mySubject123" - } - } -}` - - pipelineRunStartedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.pipelinerun.started.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "pipelineRun", - "content": { - "pipelineName": "myPipeline", - "url": "https://www.example.com/mySubject123" - } - } -}` - - pipelineRunFinishedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.pipelinerun.finished.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "pipelineRun", - "content": { - "pipelineName": "myPipeline", - "url": "https://www.example.com/mySubject123", - "outcome": "failure", - "errors": "Something went wrong\nWith some more details" - } - } -}` - - taskRunStartedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.taskrun.started.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "taskRun", - "content": { - "taskName": "myTask", - "url": "https://www.example.com/mySubject123", - "pipelineRun": { - "id": "mySubject123" - } - } - } -}` - - taskRunFinishedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.taskrun.finished.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "taskRun", - "content": { - "taskName": "myTask", - "url": "https://www.example.com/mySubject123", - "pipelineRun": { - "id": "mySubject123" - }, - "outcome": "failure", - "errors": "Something went wrong\nWith some more details" - } - } -}` - - changeCreatedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.change.created.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "change", - "content": { - "repository": { - "id": "TestRepo/TestOrg", - "source": "https://example.org" - } - } - } -}` - - changeUpdatedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.change.updated.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "change", - "content": { - "repository": { - "id": "TestRepo/TestOrg", - "source": "https://example.org" - } - } - } -}` - - changeReviewedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.change.reviewed.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "change", - "content": { - "repository": { - "id": "TestRepo/TestOrg", - "source": "https://example.org" - } - } - } -}` - - changeMergedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.change.merged.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "change", - "content": { - "repository": { - "id": "TestRepo/TestOrg", - "source": "https://example.org" - } - } - } -}` - - changeAbandonedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.change.abandoned.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "change", - "content": { - "repository": { - "id": "TestRepo/TestOrg", - "source": "https://example.org" - } - } - } -}` - - repositoryCreatedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.repository.created.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "repository", - "content": { - "name": "TestRepo", - "owner": "TestOrg", - "url": "https://example.org/TestOrg/TestRepo", - "viewUrl": "https://example.org/view/TestOrg/TestRepo" - } - } -}` - - repositoryModifiedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.repository.modified.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "repository", - "content": { - "name": "TestRepo", - "owner": "TestOrg", - "url": "https://example.org/TestOrg/TestRepo", - "viewUrl": "https://example.org/view/TestOrg/TestRepo" - } - } -}` - - repositoryDeletedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.repository.deleted.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "repository", - "content": { - "name": "TestRepo", - "owner": "TestOrg", - "url": "https://example.org/TestOrg/TestRepo", - "viewUrl": "https://example.org/view/TestOrg/TestRepo" - } - } -}` - - branchCreatedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.branch.created.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "branch", - "content": { - "repository": { - "id": "TestRepo/TestOrg", - "source": "https://example.org" - } - } - } -}` - - branchDeletedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.branch.deleted.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "branch", - "content": { - "repository": { - "id": "TestRepo/TestOrg", - "source": "https://example.org" - } - } - } -}` - - testCaseQueuedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.testcase.queued.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "testCase", - "content": {} - } -}` - - testCaseStartedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.testcase.started.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "testCase", - "content": {} - } -}` - - testCaseFinishedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.testcase.finished.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "testCase", - "content": {} - } -}` - - testSuiteStartedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.testsuite.started.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "testSuite", - "content": {} - } -}` - - testSuiteFinishedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.testsuite.finished.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "testSuite", - "content": {} - } -}` - - buildQueuedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.build.queued.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "build", - "content": {} - } -}` - - buildStartedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.build.started.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "build", - "content": {} - } -}` - - buildFinishedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.build.finished.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "build", - "content": { - "artifactId": "pkg:oci/myapp@sha256%%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427" - } - } -}` - - artifactPackagedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.artifact.packaged.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "artifact", - "content": { - "change": { - "id": "myChange123" - } - } - } -}` - - artifactPublishedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.artifact.published.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "artifact", - "content": {} - } -}` - - environmentCreatedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.environment.created.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "environment", - "content": { - "name": "testEnv", - "url": "https://example.org/testEnv" - } - } -}` - - environmentModifiedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.environment.modified.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "environment", - "content": { - "name": "testEnv", - "url": "https://example.org/testEnv" - } - } -}` - - environmentDeletedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.environment.deleted.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "environment", - "content": { - "name": "testEnv" - } - } -}` - - serviceDeployedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.service.deployed.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "service", - "content": { - "environment": { - "id": "test123" - }, - "artifactId": "pkg:oci/myapp@sha256%%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427" - } - } -}` - - serviceUpgradedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.service.upgraded.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "service", - "content": { - "environment": { - "id": "test123" - }, - "artifactId": "pkg:oci/myapp@sha256%%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427" - } - } -}` - - serviceRolledBackEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.service.rolledback.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "service", - "content": { - "environment": { - "id": "test123" - }, - "artifactId": "pkg:oci/myapp@sha256%%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427" - } - } -}` - - serviceRemovedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.service.removed.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "service", - "content": { - "environment": { - "id": "test123" - } - } - } -}` - - servicePublishedEventJsonTemplate = `{ - "context": { - "version": "0.1.0", - "id": "%s", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.service.published.0.1.0", - "timestamp": "%s" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "service", - "content": { - "environment": { - "id": "test123" - } - } - } -}` - eventJsonCustomDataTemplate = `{ "context": { - "version": "0.1.0", + "version": "0.1.1", "id": "%s", "source": "TestAsCloudEvent", - "type": "dev.cdevents.artifact.packaged.0.1.0", + "type": "dev.cdevents.artifact.packaged.0.1.1", "timestamp": "%s" }, "subject": { @@ -775,10 +134,10 @@ var ( eventImplicitJsonCustomDataTemplate = `{ "context": { - "version": "0.1.0", + "version": "0.1.1", "id": "%s", "source": "TestAsCloudEvent", - "type": "dev.cdevents.artifact.packaged.0.1.0", + "type": "dev.cdevents.artifact.packaged.0.1.1", "timestamp": "%s" }, "subject": { @@ -802,10 +161,10 @@ var ( eventNonJsonCustomDataTemplate = `{ "context": { - "version": "0.1.0", + "version": "0.1.1", "id": "%s", "source": "TestAsCloudEvent", - "type": "dev.cdevents.artifact.packaged.0.1.0", + "type": "dev.cdevents.artifact.packaged.0.1.1", "timestamp": "%s" }, "subject": { @@ -822,39 +181,7 @@ var ( "customDataContentType": "application/xml" }` - pipelineRunQueuedEventJson string - pipelineRunStartedEventJson string - pipelineRunFinishedEventJson string - taskRunStartedEventJson string - taskRunFinishedEventJson string - changeCreateEventJson string - changeUpdatedEventJson string - changeReviewedEventJson string - changeMergedEventJson string - changeAbandonedEventJson string - repositoryCreatedEventJson string - repositoryModifiedEventJson string - repositoryDeletedEventJson string - branchCreatedEventJson string - branchDeletedEventJson string - testCaseQueuedEventJson string - testCaseStartedEventJson string - testCaseFinishedEventJson string - testSuiteStartedEventJson string - testSuiteFinishedEventJson string - buildQueuedEventJson string - buildStartedEventJson string - buildFinishedEventJson string - artifactPackagedEventJson string - artifactPublishedEventJson string - environmentCreatedEventJson string - environmentModifiedEventJson string - environmentDeletedEventJson string - serviceDeployedEventJson string - serviceUpgradedEventJson string - serviceRolledBackEventJson string - serviceRemovedEventJson string - servicePublishedEventJson string + testEvents map[string][]byte eventJsonCustomDataJson string eventImplicitJsonCustomDataJson string eventNonJsonCustomDataJson string @@ -863,13 +190,13 @@ var ( func init() { // Get the time once - t := time.Now().Round(0) + t, _ := time.Parse(time.RFC3339Nano, "2023-03-20T14:27:05.315384Z") timeNow = func() time.Time { return t } - // Get the UUID once - u, _ := uuid.NewRandom() + // Set the UUID to a fixed one + u, _ := uuid.Parse("271069a8-fc18-44f1-b38f-9d70a1695819") uuidNewRandom = func() (uuid.UUID, error) { return u, nil } @@ -1050,39 +377,17 @@ func init() { newUUID, _ := uuidNewRandom() newTime := timeNow().Format(time.RFC3339Nano) - pipelineRunQueuedEventJson = fmt.Sprintf(pipelineRunQueuedEventJsonTemplate, newUUID, newTime) - pipelineRunStartedEventJson = fmt.Sprintf(pipelineRunStartedEventJsonTemplate, newUUID, newTime) - pipelineRunFinishedEventJson = fmt.Sprintf(pipelineRunFinishedEventJsonTemplate, newUUID, newTime) - taskRunStartedEventJson = fmt.Sprintf(taskRunStartedEventJsonTemplate, newUUID, newTime) - taskRunFinishedEventJson = fmt.Sprintf(taskRunFinishedEventJsonTemplate, newUUID, newTime) - changeCreateEventJson = fmt.Sprintf(changeCreatedEventJsonTemplate, newUUID, newTime) - changeUpdatedEventJson = fmt.Sprintf(changeUpdatedEventJsonTemplate, newUUID, newTime) - changeReviewedEventJson = fmt.Sprintf(changeReviewedEventJsonTemplate, newUUID, newTime) - changeMergedEventJson = fmt.Sprintf(changeMergedEventJsonTemplate, newUUID, newTime) - changeAbandonedEventJson = fmt.Sprintf(changeAbandonedEventJsonTemplate, newUUID, newTime) - repositoryCreatedEventJson = fmt.Sprintf(repositoryCreatedEventJsonTemplate, newUUID, newTime) - repositoryModifiedEventJson = fmt.Sprintf(repositoryModifiedEventJsonTemplate, newUUID, newTime) - repositoryDeletedEventJson = fmt.Sprintf(repositoryDeletedEventJsonTemplate, newUUID, newTime) - branchCreatedEventJson = fmt.Sprintf(branchCreatedEventJsonTemplate, newUUID, newTime) - branchDeletedEventJson = fmt.Sprintf(branchDeletedEventJsonTemplate, newUUID, newTime) - testCaseQueuedEventJson = fmt.Sprintf(testCaseQueuedEventJsonTemplate, newUUID, newTime) - testCaseStartedEventJson = fmt.Sprintf(testCaseStartedEventJsonTemplate, newUUID, newTime) - testCaseFinishedEventJson = fmt.Sprintf(testCaseFinishedEventJsonTemplate, newUUID, newTime) - testSuiteStartedEventJson = fmt.Sprintf(testSuiteStartedEventJsonTemplate, newUUID, newTime) - testSuiteFinishedEventJson = fmt.Sprintf(testSuiteFinishedEventJsonTemplate, newUUID, newTime) - buildQueuedEventJson = fmt.Sprintf(buildQueuedEventJsonTemplate, newUUID, newTime) - buildStartedEventJson = fmt.Sprintf(buildStartedEventJsonTemplate, newUUID, newTime) - buildFinishedEventJson = fmt.Sprintf(buildFinishedEventJsonTemplate, newUUID, newTime) - artifactPackagedEventJson = fmt.Sprintf(artifactPackagedEventJsonTemplate, newUUID, newTime) - artifactPublishedEventJson = fmt.Sprintf(artifactPublishedEventJsonTemplate, newUUID, newTime) - environmentCreatedEventJson = fmt.Sprintf(environmentCreatedEventJsonTemplate, newUUID, newTime) - environmentModifiedEventJson = fmt.Sprintf(environmentModifiedEventJsonTemplate, newUUID, newTime) - environmentDeletedEventJson = fmt.Sprintf(environmentDeletedEventJsonTemplate, newUUID, newTime) - serviceDeployedEventJson = fmt.Sprintf(serviceDeployedEventJsonTemplate, newUUID, newTime) - serviceUpgradedEventJson = fmt.Sprintf(serviceUpgradedEventJsonTemplate, newUUID, newTime) - serviceRolledBackEventJson = fmt.Sprintf(serviceRolledBackEventJsonTemplate, newUUID, newTime) - serviceRemovedEventJson = fmt.Sprintf(serviceRemovedEventJsonTemplate, newUUID, newTime) - servicePublishedEventJson = fmt.Sprintf(servicePublishedEventJsonTemplate, newUUID, newTime) + + testEvents = make(map[string][]byte) + + // Load base event test data + for _, event := range CDEventsTypes { + short := event.GetType().Short() + testEvents[short], err = os.ReadFile(testsFolder + string(os.PathSeparator) + short + ".json") + panicOnError(err) + } + + // Load extra data eventJsonCustomDataJson = fmt.Sprintf(eventJsonCustomDataTemplate, newUUID, newTime) eventImplicitJsonCustomDataJson = fmt.Sprintf(eventImplicitJsonCustomDataTemplate, newUUID, newTime) eventNonJsonCustomDataJson = fmt.Sprintf(eventNonJsonCustomDataTemplate, newUUID, newTime) @@ -1269,135 +574,135 @@ func TestAsJsonString(t *testing.T) { }{{ name: "pipelinerun queued", event: pipelineRunQueuedEvent, - jsonString: pipelineRunQueuedEventJson, + jsonString: string(testEvents[pipelineRunQueuedEvent.GetType().Short()]), }, { name: "pipelinerun started", event: pipelineRunStartedEvent, - jsonString: pipelineRunStartedEventJson, + jsonString: string(testEvents[pipelineRunStartedEvent.GetType().Short()]), }, { name: "pipelinerun finished", event: pipelineRunFinishedEvent, - jsonString: pipelineRunFinishedEventJson, + jsonString: string(testEvents[pipelineRunFinishedEvent.GetType().Short()]), }, { name: "taskrun started", event: taskRunStartedEvent, - jsonString: taskRunStartedEventJson, + jsonString: string(testEvents[taskRunStartedEvent.GetType().Short()]), }, { name: "taskrun finished", event: taskRunFinishedEvent, - jsonString: taskRunFinishedEventJson, + jsonString: string(testEvents[taskRunFinishedEvent.GetType().Short()]), }, { name: "change created", event: changeCreatedEvent, - jsonString: changeCreateEventJson, + jsonString: string(testEvents[changeCreatedEvent.GetType().Short()]), }, { name: "change updated", event: changeUpdatedEvent, - jsonString: changeUpdatedEventJson, + jsonString: string(testEvents[changeUpdatedEvent.GetType().Short()]), }, { name: "change reviewed", event: changeReviewedEvent, - jsonString: changeReviewedEventJson, + jsonString: string(testEvents[changeReviewedEvent.GetType().Short()]), }, { name: "change merged", event: changeMergedEvent, - jsonString: changeMergedEventJson, + jsonString: string(testEvents[changeMergedEvent.GetType().Short()]), }, { name: "change abandoned", event: changeAbandonedEvent, - jsonString: changeAbandonedEventJson, + jsonString: string(testEvents[changeAbandonedEvent.GetType().Short()]), }, { name: "repository created", event: repositoryCreatedEvent, - jsonString: repositoryCreatedEventJson, + jsonString: string(testEvents[repositoryCreatedEvent.GetType().Short()]), }, { name: "repository modified", event: repositoryModifiedEvent, - jsonString: repositoryModifiedEventJson, + jsonString: string(testEvents[repositoryModifiedEvent.GetType().Short()]), }, { name: "repository deleted", event: repositoryDeletedEvent, - jsonString: repositoryDeletedEventJson, + jsonString: string(testEvents[repositoryDeletedEvent.GetType().Short()]), }, { name: "branch created", event: branchCreatedEvent, - jsonString: branchCreatedEventJson, + jsonString: string(testEvents[branchCreatedEvent.GetType().Short()]), }, { name: "branch deleted", event: branchDeletedEvent, - jsonString: branchDeletedEventJson, + jsonString: string(testEvents[branchDeletedEvent.GetType().Short()]), }, { name: "testcase queued", event: testCaseQueuedEvent, - jsonString: testCaseQueuedEventJson, + jsonString: string(testEvents[testCaseQueuedEvent.GetType().Short()]), }, { name: "testcase started", event: testCaseStartedEvent, - jsonString: testCaseStartedEventJson, + jsonString: string(testEvents[testCaseStartedEvent.GetType().Short()]), }, { name: "testcase finished", event: testCaseFinishedEvent, - jsonString: testCaseFinishedEventJson, + jsonString: string(testEvents[testCaseFinishedEvent.GetType().Short()]), }, { name: "testsuite started", event: testSuiteStartedEvent, - jsonString: testSuiteStartedEventJson, + jsonString: string(testEvents[testSuiteStartedEvent.GetType().Short()]), }, { name: "testsuite finished", event: testSuiteFinishedEvent, - jsonString: testSuiteFinishedEventJson, + jsonString: string(testEvents[testSuiteFinishedEvent.GetType().Short()]), }, { name: "build queued", event: buildQueuedEvent, - jsonString: buildQueuedEventJson, + jsonString: string(testEvents[buildQueuedEvent.GetType().Short()]), }, { name: "build started", event: buildStartedEvent, - jsonString: buildStartedEventJson, + jsonString: string(testEvents[buildStartedEvent.GetType().Short()]), }, { name: "build finished", event: buildFinishedEvent, - jsonString: buildFinishedEventJson, + jsonString: string(testEvents[buildFinishedEvent.GetType().Short()]), }, { name: "artifact packaged", event: artifactPackagedEvent, - jsonString: artifactPackagedEventJson, + jsonString: string(testEvents[artifactPackagedEvent.GetType().Short()]), }, { name: "artifact published", event: artifactPublishedEvent, - jsonString: artifactPublishedEventJson, + jsonString: string(testEvents[artifactPublishedEvent.GetType().Short()]), }, { name: "environment created", event: environmentCreatedEvent, - jsonString: environmentCreatedEventJson, + jsonString: string(testEvents[environmentCreatedEvent.GetType().Short()]), }, { name: "environment modified", event: environmentModifiedEvent, - jsonString: environmentModifiedEventJson, + jsonString: string(testEvents[environmentModifiedEvent.GetType().Short()]), }, { name: "environment deleted", event: environmentDeletedEvent, - jsonString: environmentDeletedEventJson, + jsonString: string(testEvents[environmentDeletedEvent.GetType().Short()]), }, { name: "service deployed", event: serviceDeployedEvent, - jsonString: serviceDeployedEventJson, + jsonString: string(testEvents[serviceDeployedEvent.GetType().Short()]), }, { name: "service upgraded", event: serviceUpgradedEvent, - jsonString: serviceUpgradedEventJson, + jsonString: string(testEvents[serviceUpgradedEvent.GetType().Short()]), }, { name: "service rolledback", event: serviceRolledBackEvent, - jsonString: serviceRolledBackEventJson, + jsonString: string(testEvents[serviceRolledBackEvent.GetType().Short()]), }, { name: "service removed", event: serviceRemovedEvent, - jsonString: serviceRemovedEventJson, + jsonString: string(testEvents[serviceRemovedEvent.GetType().Short()]), }, { name: "service published", event: servicePublishedEvent, - jsonString: servicePublishedEventJson, + jsonString: string(testEvents[servicePublishedEvent.GetType().Short()]), }, { name: "json custom data", event: eventJsonCustomData, @@ -1548,135 +853,135 @@ func TestNewFromJsonString(t *testing.T) { }{{ name: "pipelinerun queued", event: pipelineRunQueuedEvent, - jsonString: pipelineRunQueuedEventJson, + jsonString: string(testEvents[pipelineRunQueuedEvent.GetType().Short()]), }, { name: "pipelinerun started", event: pipelineRunStartedEvent, - jsonString: pipelineRunStartedEventJson, + jsonString: string(testEvents[pipelineRunStartedEvent.GetType().Short()]), }, { name: "pipelinerun finished", event: pipelineRunFinishedEvent, - jsonString: pipelineRunFinishedEventJson, + jsonString: string(testEvents[pipelineRunFinishedEvent.GetType().Short()]), }, { name: "taskrun started", event: taskRunStartedEvent, - jsonString: taskRunStartedEventJson, + jsonString: string(testEvents[taskRunStartedEvent.GetType().Short()]), }, { name: "taskrun finished", event: taskRunFinishedEvent, - jsonString: taskRunFinishedEventJson, + jsonString: string(testEvents[taskRunFinishedEvent.GetType().Short()]), }, { name: "change created", event: changeCreatedEvent, - jsonString: changeCreateEventJson, + jsonString: string(testEvents[changeCreatedEvent.GetType().Short()]), }, { name: "change updated", event: changeUpdatedEvent, - jsonString: changeUpdatedEventJson, + jsonString: string(testEvents[changeUpdatedEvent.GetType().Short()]), }, { name: "change reviewed", event: changeReviewedEvent, - jsonString: changeReviewedEventJson, + jsonString: string(testEvents[changeReviewedEvent.GetType().Short()]), }, { name: "change merged", event: changeMergedEvent, - jsonString: changeMergedEventJson, + jsonString: string(testEvents[changeMergedEvent.GetType().Short()]), }, { name: "change abandoned", event: changeAbandonedEvent, - jsonString: changeAbandonedEventJson, + jsonString: string(testEvents[changeAbandonedEvent.GetType().Short()]), }, { name: "repository created", event: repositoryCreatedEvent, - jsonString: repositoryCreatedEventJson, + jsonString: string(testEvents[repositoryCreatedEvent.GetType().Short()]), }, { name: "repository modified", event: repositoryModifiedEvent, - jsonString: repositoryModifiedEventJson, + jsonString: string(testEvents[repositoryModifiedEvent.GetType().Short()]), }, { name: "repository deleted", event: repositoryDeletedEvent, - jsonString: repositoryDeletedEventJson, + jsonString: string(testEvents[repositoryDeletedEvent.GetType().Short()]), }, { name: "branch created", event: branchCreatedEvent, - jsonString: branchCreatedEventJson, + jsonString: string(testEvents[branchCreatedEvent.GetType().Short()]), }, { name: "branch deleted", event: branchDeletedEvent, - jsonString: branchDeletedEventJson, + jsonString: string(testEvents[branchDeletedEvent.GetType().Short()]), }, { name: "testcase queued", event: testCaseQueuedEvent, - jsonString: testCaseQueuedEventJson, + jsonString: string(testEvents[testCaseQueuedEvent.GetType().Short()]), }, { name: "testcase started", event: testCaseStartedEvent, - jsonString: testCaseStartedEventJson, + jsonString: string(testEvents[testCaseStartedEvent.GetType().Short()]), }, { name: "testcase finished", event: testCaseFinishedEvent, - jsonString: testCaseFinishedEventJson, + jsonString: string(testEvents[testCaseFinishedEvent.GetType().Short()]), }, { name: "testsuite started", event: testSuiteStartedEvent, - jsonString: testSuiteStartedEventJson, + jsonString: string(testEvents[testSuiteStartedEvent.GetType().Short()]), }, { name: "testsuite finished", event: testSuiteFinishedEvent, - jsonString: testSuiteFinishedEventJson, + jsonString: string(testEvents[testSuiteFinishedEvent.GetType().Short()]), }, { name: "build queued", event: buildQueuedEvent, - jsonString: buildQueuedEventJson, + jsonString: string(testEvents[buildQueuedEvent.GetType().Short()]), }, { name: "build started", event: buildStartedEvent, - jsonString: buildStartedEventJson, + jsonString: string(testEvents[buildStartedEvent.GetType().Short()]), }, { name: "build finished", event: buildFinishedEvent, - jsonString: buildFinishedEventJson, + jsonString: string(testEvents[buildFinishedEvent.GetType().Short()]), }, { name: "artifact packaged", event: artifactPackagedEvent, - jsonString: artifactPackagedEventJson, + jsonString: string(testEvents[artifactPackagedEvent.GetType().Short()]), }, { name: "artifact published", event: artifactPublishedEvent, - jsonString: artifactPublishedEventJson, + jsonString: string(testEvents[artifactPublishedEvent.GetType().Short()]), }, { name: "environment created", event: environmentCreatedEvent, - jsonString: environmentCreatedEventJson, + jsonString: string(testEvents[environmentCreatedEvent.GetType().Short()]), }, { name: "environment modified", event: environmentModifiedEvent, - jsonString: environmentModifiedEventJson, + jsonString: string(testEvents[environmentModifiedEvent.GetType().Short()]), }, { name: "environment deleted", event: environmentDeletedEvent, - jsonString: environmentDeletedEventJson, + jsonString: string(testEvents[environmentDeletedEvent.GetType().Short()]), }, { name: "service deployed", event: serviceDeployedEvent, - jsonString: serviceDeployedEventJson, + jsonString: string(testEvents[serviceDeployedEvent.GetType().Short()]), }, { name: "service upgraded", event: serviceUpgradedEvent, - jsonString: serviceUpgradedEventJson, + jsonString: string(testEvents[serviceUpgradedEvent.GetType().Short()]), }, { name: "service rolledback", event: serviceRolledBackEvent, - jsonString: serviceRolledBackEventJson, + jsonString: string(testEvents[serviceRolledBackEvent.GetType().Short()]), }, { name: "service removed", event: serviceRemovedEvent, - jsonString: serviceRemovedEventJson, + jsonString: string(testEvents[serviceRemovedEvent.GetType().Short()]), }, { name: "service published", event: servicePublishedEvent, - jsonString: servicePublishedEventJson, + jsonString: string(testEvents[servicePublishedEvent.GetType().Short()]), }, { name: "json custom data", event: eventJsonCustomDataUnmarshalled, @@ -1825,7 +1130,7 @@ func TestNewFromJsonBytes(t *testing.T) { }{{ testFile: "future_event_major_version", description: "A newer major version in the event is backward incompatible and cannot be parsed", - wantError: "sdk event version 0.1.0 not compatible with 999.0.0", + wantError: "sdk event version 0.1.1 not compatible with 999.0.0", }, { testFile: "future_event_minor_version", description: "A newer minor version in the event is compatible and can be parsed, data is lost", diff --git a/pkg/api/spec b/pkg/api/spec index f8e25fa..8e8b3e0 160000 --- a/pkg/api/spec +++ b/pkg/api/spec @@ -1 +1 @@ -Subproject commit f8e25faf6fb5bb5b3446e267838ed0a9723208f9 +Subproject commit 8e8b3e0c4bf7656abd32a258a4a86b97e2d4d6f5 diff --git a/pkg/api/tests/artifact_packaged.json b/pkg/api/tests/artifact_packaged.json new file mode 100644 index 0000000..4153a88 --- /dev/null +++ b/pkg/api/tests/artifact_packaged.json @@ -0,0 +1,19 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.artifact.packaged.0.1.1", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "artifact", + "content": { + "change": { + "id": "myChange123" + } + } + } +} diff --git a/pkg/api/tests/artifact_published.json b/pkg/api/tests/artifact_published.json new file mode 100644 index 0000000..fed876c --- /dev/null +++ b/pkg/api/tests/artifact_published.json @@ -0,0 +1,15 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.artifact.published.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "artifact", + "content": {} + } +} diff --git a/pkg/api/tests/branch_created.json b/pkg/api/tests/branch_created.json new file mode 100644 index 0000000..98dc72c --- /dev/null +++ b/pkg/api/tests/branch_created.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.branch.created.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "branch", + "content": { + "repository": { + "id": "TestRepo/TestOrg", + "source": "https://example.org" + } + } + } +} \ No newline at end of file diff --git a/pkg/api/tests/branch_deleted.json b/pkg/api/tests/branch_deleted.json new file mode 100644 index 0000000..93c4813 --- /dev/null +++ b/pkg/api/tests/branch_deleted.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.branch.deleted.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "branch", + "content": { + "repository": { + "id": "TestRepo/TestOrg", + "source": "https://example.org" + } + } + } +} \ No newline at end of file diff --git a/pkg/api/tests/build_finished.json b/pkg/api/tests/build_finished.json new file mode 100644 index 0000000..48b33ab --- /dev/null +++ b/pkg/api/tests/build_finished.json @@ -0,0 +1,17 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.build.finished.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "build", + "content": { + "artifactId": "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427" + } + } +} diff --git a/pkg/api/tests/build_queued.json b/pkg/api/tests/build_queued.json new file mode 100644 index 0000000..2940af2 --- /dev/null +++ b/pkg/api/tests/build_queued.json @@ -0,0 +1,15 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.build.queued.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "build", + "content": {} + } +} diff --git a/pkg/api/tests/build_started.json b/pkg/api/tests/build_started.json new file mode 100644 index 0000000..a8a4812 --- /dev/null +++ b/pkg/api/tests/build_started.json @@ -0,0 +1,15 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.build.started.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "build", + "content": {} + } +} diff --git a/pkg/api/tests/change_abandoned.json b/pkg/api/tests/change_abandoned.json new file mode 100644 index 0000000..6cf8dec --- /dev/null +++ b/pkg/api/tests/change_abandoned.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.change.abandoned.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "change", + "content": { + "repository": { + "id": "TestRepo/TestOrg", + "source": "https://example.org" + } + } + } +} \ No newline at end of file diff --git a/pkg/api/tests/change_created.json b/pkg/api/tests/change_created.json new file mode 100644 index 0000000..01bb534 --- /dev/null +++ b/pkg/api/tests/change_created.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.change.created.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "change", + "content": { + "repository": { + "id": "TestRepo/TestOrg", + "source": "https://example.org" + } + } + } +} \ No newline at end of file diff --git a/pkg/api/tests/change_merged.json b/pkg/api/tests/change_merged.json new file mode 100644 index 0000000..9a7dad9 --- /dev/null +++ b/pkg/api/tests/change_merged.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.change.merged.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "change", + "content": { + "repository": { + "id": "TestRepo/TestOrg", + "source": "https://example.org" + } + } + } +} \ No newline at end of file diff --git a/pkg/api/tests/change_reviewed.json b/pkg/api/tests/change_reviewed.json new file mode 100644 index 0000000..dc8687d --- /dev/null +++ b/pkg/api/tests/change_reviewed.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.change.reviewed.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "change", + "content": { + "repository": { + "id": "TestRepo/TestOrg", + "source": "https://example.org" + } + } + } +} \ No newline at end of file diff --git a/pkg/api/tests/change_updated.json b/pkg/api/tests/change_updated.json new file mode 100644 index 0000000..200a8c4 --- /dev/null +++ b/pkg/api/tests/change_updated.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.change.updated.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "change", + "content": { + "repository": { + "id": "TestRepo/TestOrg", + "source": "https://example.org" + } + } + } +} \ No newline at end of file diff --git a/pkg/api/tests/environment_created.json b/pkg/api/tests/environment_created.json new file mode 100644 index 0000000..a469da5 --- /dev/null +++ b/pkg/api/tests/environment_created.json @@ -0,0 +1,18 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.environment.created.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "environment", + "content": { + "name": "testEnv", + "url": "https://example.org/testEnv" + } + } +} diff --git a/pkg/api/tests/environment_deleted.json b/pkg/api/tests/environment_deleted.json new file mode 100644 index 0000000..a4ded1f --- /dev/null +++ b/pkg/api/tests/environment_deleted.json @@ -0,0 +1,17 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.environment.deleted.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "environment", + "content": { + "name": "testEnv" + } + } +} diff --git a/pkg/api/tests/environment_modified.json b/pkg/api/tests/environment_modified.json new file mode 100644 index 0000000..0e9db8e --- /dev/null +++ b/pkg/api/tests/environment_modified.json @@ -0,0 +1,18 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.environment.modified.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "environment", + "content": { + "name": "testEnv", + "url": "https://example.org/testEnv" + } + } +} diff --git a/pkg/api/tests/future_event_major_version.json b/pkg/api/tests/future_event_major_version.json index c9b531f..9898cd3 100644 --- a/pkg/api/tests/future_event_major_version.json +++ b/pkg/api/tests/future_event_major_version.json @@ -1,25 +1,29 @@ { - "context": { - "version": "0.1.0", - "id": "122CB7D5-84A7-4CCE-AD3F-D93ED17D7D65", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.artifact.packaged.999.0.0", - "timestamp": "2023-03-20T17:31:00Z" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "contentRenamed": { - "change": { - "id": "myChange123" - } - } - }, - "customData": { - "testValues": [ - {"k1": "v1"}, - {"k2": "v2"} - ] - }, - "customDataContentType": "application/json" -} \ No newline at end of file + "context": { + "version": "0.1.1", + "id": "122CB7D5-84A7-4CCE-AD3F-D93ED17D7D65", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.artifact.packaged.999.0.0", + "timestamp": "2023-03-20T17:31:00Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "contentRenamed": { + "change": { + "id": "myChange123" + } + } + }, + "customData": { + "testValues": [ + { + "k1": "v1" + }, + { + "k2": "v2" + } + ] + }, + "customDataContentType": "application/json" +} diff --git a/pkg/api/tests/future_event_minor_version.json b/pkg/api/tests/future_event_minor_version.json index 5fff057..cb3bfc2 100644 --- a/pkg/api/tests/future_event_minor_version.json +++ b/pkg/api/tests/future_event_minor_version.json @@ -1,29 +1,33 @@ { - "context": { - "version": "0.1.0", - "id": "122CB7D5-84A7-4CCE-AD3F-D93ED17D7D65", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.artifact.packaged.0.999.0", - "timestamp": "2023-03-20T17:31:00Z", - "newContextField": "ignored" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "artifact", - "content": { - "change": { - "id": "myChange123" - } - }, - "newSubjectField": "ignored" - }, - "customData": { - "testValues": [ - {"k1": "v1"}, - {"k2": "v2"} - ] - }, - "customDataContentType": "application/json", - "newRootField": "ignored" -} \ No newline at end of file + "context": { + "version": "0.1.1", + "id": "122CB7D5-84A7-4CCE-AD3F-D93ED17D7D65", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.artifact.packaged.0.999.0", + "timestamp": "2023-03-20T17:31:00Z", + "newContextField": "ignored" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "artifact", + "content": { + "change": { + "id": "myChange123" + } + }, + "newSubjectField": "ignored" + }, + "customData": { + "testValues": [ + { + "k1": "v1" + }, + { + "k2": "v2" + } + ] + }, + "customDataContentType": "application/json", + "newRootField": "ignored" +} diff --git a/pkg/api/tests/future_event_patch_version.json b/pkg/api/tests/future_event_patch_version.json index 8f9093f..cae4188 100644 --- a/pkg/api/tests/future_event_patch_version.json +++ b/pkg/api/tests/future_event_patch_version.json @@ -1,26 +1,30 @@ { - "context": { - "version": "0.1.0", - "id": "122CB7D5-84A7-4CCE-AD3F-D93ED17D7D65", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.artifact.packaged.0.1.999", - "timestamp": "2023-03-20T17:31:00Z" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "artifact", - "content": { - "change": { - "id": "myChange123" - } - } - }, - "customData": { - "testValues": [ - {"k1": "v1"}, - {"k2": "v2"} - ] - }, - "customDataContentType": "application/json" -} \ No newline at end of file + "context": { + "version": "0.1.1", + "id": "122CB7D5-84A7-4CCE-AD3F-D93ED17D7D65", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.artifact.packaged.0.1.999", + "timestamp": "2023-03-20T17:31:00Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "artifact", + "content": { + "change": { + "id": "myChange123" + } + } + }, + "customData": { + "testValues": [ + { + "k1": "v1" + }, + { + "k2": "v2" + } + ] + }, + "customDataContentType": "application/json" +} diff --git a/pkg/api/tests/non_unmarshable.json b/pkg/api/tests/non_unmarshable.json index 4d5e2c8..ec41960 100644 --- a/pkg/api/tests/non_unmarshable.json +++ b/pkg/api/tests/non_unmarshable.json @@ -1,6 +1,6 @@ { "context": { - "version": "0.1.0", + "version": "0.1.1", "id": "122CB7D5-84A7-4CCE-AD3F-D93ED17D7D65", "source": "TestAsCloudEvent", "type": "dev.cdevents.artifact.packaged.0.1.0", diff --git a/pkg/api/tests/pipelinerun_finished.json b/pkg/api/tests/pipelinerun_finished.json new file mode 100644 index 0000000..bdae11d --- /dev/null +++ b/pkg/api/tests/pipelinerun_finished.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.pipelinerun.finished.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "pipelineRun", + "content": { + "pipelineName": "myPipeline", + "url": "https://www.example.com/mySubject123", + "outcome": "failure", + "errors": "Something went wrong\nWith some more details" + } + } +} diff --git a/pkg/api/tests/pipelinerun_queued.json b/pkg/api/tests/pipelinerun_queued.json new file mode 100644 index 0000000..0b1cb33 --- /dev/null +++ b/pkg/api/tests/pipelinerun_queued.json @@ -0,0 +1,18 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.pipelinerun.queued.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "pipelineRun", + "content": { + "pipelineName": "myPipeline", + "url": "https://www.example.com/mySubject123" + } + } +} diff --git a/pkg/api/tests/pipelinerun_started.json b/pkg/api/tests/pipelinerun_started.json new file mode 100644 index 0000000..029bfaa --- /dev/null +++ b/pkg/api/tests/pipelinerun_started.json @@ -0,0 +1,18 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.pipelinerun.started.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "pipelineRun", + "content": { + "pipelineName": "myPipeline", + "url": "https://www.example.com/mySubject123" + } + } +} diff --git a/pkg/api/tests/repository_created.json b/pkg/api/tests/repository_created.json new file mode 100644 index 0000000..ce38b6f --- /dev/null +++ b/pkg/api/tests/repository_created.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.repository.created.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "repository", + "content": { + "name": "TestRepo", + "owner": "TestOrg", + "url": "https://example.org/TestOrg/TestRepo", + "viewUrl": "https://example.org/view/TestOrg/TestRepo" + } + } +} diff --git a/pkg/api/tests/repository_deleted.json b/pkg/api/tests/repository_deleted.json new file mode 100644 index 0000000..64b1789 --- /dev/null +++ b/pkg/api/tests/repository_deleted.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.repository.deleted.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "repository", + "content": { + "name": "TestRepo", + "owner": "TestOrg", + "url": "https://example.org/TestOrg/TestRepo", + "viewUrl": "https://example.org/view/TestOrg/TestRepo" + } + } +} diff --git a/pkg/api/tests/repository_modified.json b/pkg/api/tests/repository_modified.json new file mode 100644 index 0000000..82875a3 --- /dev/null +++ b/pkg/api/tests/repository_modified.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.repository.modified.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "repository", + "content": { + "name": "TestRepo", + "owner": "TestOrg", + "url": "https://example.org/TestOrg/TestRepo", + "viewUrl": "https://example.org/view/TestOrg/TestRepo" + } + } +} diff --git a/pkg/api/tests/service_deployed.json b/pkg/api/tests/service_deployed.json new file mode 100644 index 0000000..bddff59 --- /dev/null +++ b/pkg/api/tests/service_deployed.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.service.deployed.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "service", + "content": { + "environment": { + "id": "test123" + }, + "artifactId": "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427" + } + } +} diff --git a/pkg/api/tests/service_published.json b/pkg/api/tests/service_published.json new file mode 100644 index 0000000..585213b --- /dev/null +++ b/pkg/api/tests/service_published.json @@ -0,0 +1,19 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.service.published.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "service", + "content": { + "environment": { + "id": "test123" + } + } + } +} diff --git a/pkg/api/tests/service_removed.json b/pkg/api/tests/service_removed.json new file mode 100644 index 0000000..affbdaa --- /dev/null +++ b/pkg/api/tests/service_removed.json @@ -0,0 +1,19 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.service.removed.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "service", + "content": { + "environment": { + "id": "test123" + } + } + } +} diff --git a/pkg/api/tests/service_rolledback.json b/pkg/api/tests/service_rolledback.json new file mode 100644 index 0000000..a7fc440 --- /dev/null +++ b/pkg/api/tests/service_rolledback.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.service.rolledback.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "service", + "content": { + "environment": { + "id": "test123" + }, + "artifactId": "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427" + } + } +} diff --git a/pkg/api/tests/service_upgraded.json b/pkg/api/tests/service_upgraded.json new file mode 100644 index 0000000..9907ca1 --- /dev/null +++ b/pkg/api/tests/service_upgraded.json @@ -0,0 +1,20 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.service.upgraded.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "service", + "content": { + "environment": { + "id": "test123" + }, + "artifactId": "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427" + } + } +} diff --git a/pkg/api/tests/taskrun_finished.json b/pkg/api/tests/taskrun_finished.json new file mode 100644 index 0000000..bd4286b --- /dev/null +++ b/pkg/api/tests/taskrun_finished.json @@ -0,0 +1,23 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.taskrun.finished.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "taskRun", + "content": { + "taskName": "myTask", + "url": "https://www.example.com/mySubject123", + "pipelineRun": { + "id": "mySubject123" + }, + "outcome": "failure", + "errors": "Something went wrong\nWith some more details" + } + } +} diff --git a/pkg/api/tests/taskrun_started.json b/pkg/api/tests/taskrun_started.json new file mode 100644 index 0000000..ddccfa0 --- /dev/null +++ b/pkg/api/tests/taskrun_started.json @@ -0,0 +1,21 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.taskrun.started.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "taskRun", + "content": { + "taskName": "myTask", + "url": "https://www.example.com/mySubject123", + "pipelineRun": { + "id": "mySubject123" + } + } + } +} diff --git a/pkg/api/tests/testcase_finished.json b/pkg/api/tests/testcase_finished.json new file mode 100644 index 0000000..6e36930 --- /dev/null +++ b/pkg/api/tests/testcase_finished.json @@ -0,0 +1,15 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.testcase.finished.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "testCase", + "content": {} + } +} diff --git a/pkg/api/tests/testcase_queued.json b/pkg/api/tests/testcase_queued.json new file mode 100644 index 0000000..192f3e6 --- /dev/null +++ b/pkg/api/tests/testcase_queued.json @@ -0,0 +1,15 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.testcase.queued.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "testCase", + "content": {} + } +} diff --git a/pkg/api/tests/testcase_started.json b/pkg/api/tests/testcase_started.json new file mode 100644 index 0000000..80b383c --- /dev/null +++ b/pkg/api/tests/testcase_started.json @@ -0,0 +1,15 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.testcase.started.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "testCase", + "content": {} + } +} diff --git a/pkg/api/tests/testsuite_finished.json b/pkg/api/tests/testsuite_finished.json new file mode 100644 index 0000000..0b66c39 --- /dev/null +++ b/pkg/api/tests/testsuite_finished.json @@ -0,0 +1,15 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.testsuite.finished.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "testSuite", + "content": {} + } +} diff --git a/pkg/api/tests/testsuite_started.json b/pkg/api/tests/testsuite_started.json new file mode 100644 index 0000000..905bacf --- /dev/null +++ b/pkg/api/tests/testsuite_started.json @@ -0,0 +1,15 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.testsuite.started.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "testSuite", + "content": {} + } +} diff --git a/pkg/api/tests/unknown_type.json b/pkg/api/tests/unknown_type.json index 7b0a146..28aa491 100644 --- a/pkg/api/tests/unknown_type.json +++ b/pkg/api/tests/unknown_type.json @@ -1,26 +1,30 @@ { - "context": { - "version": "0.1.0", - "id": "122CB7D5-84A7-4CCE-AD3F-D93ED17D7D65", - "source": "TestAsCloudEvent", - "type": "dev.cdevents.artifact.gazumped.0.1.0", - "timestamp": "2023-03-20T17:31:00Z" - }, - "subject": { - "id": "mySubject123", - "source": "TestAsCloudEvent", - "type": "artifact", - "content": { - "change": { - "id": "myChange123" - } - } - }, - "customData": { - "testValues": [ - {"k1": "v1"}, - {"k2": "v2"} - ] - }, - "customDataContentType": "application/json" -} \ No newline at end of file + "context": { + "version": "0.1.1", + "id": "122CB7D5-84A7-4CCE-AD3F-D93ED17D7D65", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.artifact.gazumped.0.1.0", + "timestamp": "2023-03-20T17:31:00Z" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "artifact", + "content": { + "change": { + "id": "myChange123" + } + } + }, + "customData": { + "testValues": [ + { + "k1": "v1" + }, + { + "k2": "v2" + } + ] + }, + "customDataContentType": "application/json" +} diff --git a/pkg/api/tests/unparsable_type.json b/pkg/api/tests/unparsable_type.json index 5a9a0c0..8bef165 100644 --- a/pkg/api/tests/unparsable_type.json +++ b/pkg/api/tests/unparsable_type.json @@ -1,6 +1,6 @@ { "context": { - "version": "0.1.0", + "version": "0.1.1", "id": "122CB7D5-84A7-4CCE-AD3F-D93ED17D7D65", "source": "TestAsCloudEvent", "type": "dev.cdevents.artifact_packaged_0.1.0", diff --git a/pkg/api/types.go b/pkg/api/types.go index 06af5be..3c4692b 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -30,7 +30,7 @@ import ( const ( EventTypeRoot = "dev.cdevents" - CDEventsSpecVersion = "0.1.0" + CDEventsSpecVersion = "0.1.1" CDEventsSchemaURLTemplate = "https://cdevents.dev/%s/schema/%s-%s-event" CDEventsTypeRegex = "^dev\\.cdevents\\.(?P[a-z]+)\\.(?P[a-z]+)\\.(?P.*)$" ) @@ -92,7 +92,7 @@ type Context struct { // uses. This enables the interpretation of the context. Compliant event // producers MUST use a value of draft when referring to this version of the // specification. - Version string `json:"version" jsonschema:"required,enum=0.1.0,default=0.1.0"` + Version string `json:"version" jsonschema:"required"` // Spec: https://cdevents.dev/docs/spec/#id // Description: Identifier for an event. Subsequent delivery attempts of the @@ -174,8 +174,8 @@ func (t CDEventType) UnversionedString() string { return EventTypeRoot + "." + t.Subject + "." + t.Predicate } -func (t CDEventType) SchemaFile() string { - return t.Subject + t.Predicate +func (t CDEventType) Short() string { + return t.Subject + "_" + t.Predicate } // Two CDEventTypes are compatible if the subject and predicates