forked from openshift-online/ocm-api-metamodel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch changes the code generator so that errors support the `operation_id` attribute. This attribute and the existing ones will now be used to generate more complete error messages. For example, the following JSON error response: ``` { "kind": "Error", "id": "401", "href": "/api/clusters_mgmt/v1/errors/401", "code": "CLUSTERS-MGMT-401", "reason": "My reason", "operation_id": "456" } ``` Will result in the following error string (in one single line): ``` identifier is '401', code is 'CLUSTERS-MGMT-401' and operation identifier is '456': My reason ``` Related: openshift-online/ocm-sdk-go#150 Signed-off-by: Juan Hernandez <jhernand@redhat.com>
- Loading branch information
Showing
5 changed files
with
223 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
Copyright (c) 2020 Red Hat, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// This file contains tests for errors. | ||
|
||
package tests | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo/extensions/table" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/openshift-online/ocm-api-metamodel/tests/go/generated/errors" | ||
) | ||
|
||
var _ = Describe("Errors", func() { | ||
DescribeTable( | ||
"Conversion to string", | ||
func(input, expected string) { | ||
object, err := errors.UnmarshalError(input) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(object).ToNot(BeNil()) | ||
actual := object.Error() | ||
Expect(actual).To(Equal(expected)) | ||
}, | ||
Entry( | ||
"Empty", | ||
`{}`, | ||
"unknown error", | ||
), | ||
Entry( | ||
"Only identifier", | ||
`{ | ||
"id": "401" | ||
}`, | ||
"identifier is '401'", | ||
), | ||
Entry( | ||
"Only code", | ||
`{ | ||
"code": "CLUSTERS-MGMT-401" | ||
}`, | ||
"code is 'CLUSTERS-MGMT-401'", | ||
), | ||
Entry( | ||
"Only operation identifier", | ||
`{ | ||
"operation_id": "456" | ||
}`, | ||
"operation identifier is '456'", | ||
), | ||
Entry( | ||
"Only reason", | ||
`{ | ||
"reason": "My reason" | ||
}`, | ||
`My reason`, | ||
), | ||
Entry( | ||
"Identifier and code", | ||
`{ | ||
"id": "401", | ||
"code": "CLUSTERS-MGMT-401" | ||
}`, | ||
"identifier is '401' and code is 'CLUSTERS-MGMT-401'", | ||
), | ||
Entry( | ||
"Identifier, code and operation identifier", | ||
`{ | ||
"id": "401", | ||
"code": "CLUSTERS-MGMT-401", | ||
"operation_id": "456" | ||
}`, | ||
"identifier is '401', code is 'CLUSTERS-MGMT-401' and operation "+ | ||
"identifier is '456'", | ||
), | ||
Entry( | ||
"Identifier, code, operation identifier and reason", | ||
`{ | ||
"id": "401", | ||
"code": "CLUSTERS-MGMT-401", | ||
"reason": "My reason", | ||
"operation_id": "456" | ||
}`, | ||
"identifier is '401', code is 'CLUSTERS-MGMT-401' and operation "+ | ||
"identifier is '456': My reason", | ||
), | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters