-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow overriding json values before sending #644
Open
smarthall
wants to merge
2
commits into
openshift:master
Choose a base branch
from
smarthall:override_json_values
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,110 @@ | ||
package servicelog | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/openshift/osdctl/internal/servicelog" | ||
) | ||
|
||
func TestSetup(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Setup Suite") | ||
} | ||
|
||
var _ = Describe("Test posting service logs", func() { | ||
var options *PostCmdOptions | ||
|
||
BeforeEach(func() { | ||
options = &PostCmdOptions{ | ||
Overrides: []string{ | ||
"description=new description", | ||
"summary=new summary", | ||
}, | ||
Message: servicelog.Message{ | ||
Summary: "The original summary", | ||
InternalOnly: false, | ||
}, | ||
} | ||
}) | ||
|
||
Context("overriding a field", func() { | ||
It("overrides string fields successfully", func() { | ||
overrideString := "Overridden Summary" | ||
err := options.overrideField("summary", overrideString) | ||
|
||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(options.Message.Summary).To(Equal(overrideString)) | ||
}) | ||
|
||
It("overrides bool fields correctly", func() { | ||
Expect(options.Message.InternalOnly).ToNot(Equal(true)) | ||
|
||
err := options.overrideField("internal_only", "true") | ||
|
||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(options.Message.InternalOnly).To(Equal(true)) | ||
}) | ||
|
||
It("errors when overriding a field that does not exist", func() { | ||
err := options.overrideField("does_not_exist", "") | ||
|
||
Expect(err).Should(HaveOccurred()) | ||
}) | ||
|
||
It("errors when overriding a bool with an unparsable string", func() { | ||
err := options.overrideField("internal_only", "ThisIsNotABool") | ||
|
||
Expect(err).Should(HaveOccurred()) | ||
}) | ||
|
||
It("errors when overriding an unsupported data type", func() { | ||
err := options.overrideField("doc_references", "DoesntMatter") | ||
|
||
Expect(err).Should(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
Context("parsing overrides", func() { | ||
It("parses correctly", func() { | ||
overrideMap, err := options.parseOverrides() | ||
|
||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(overrideMap).To(HaveKey("description")) | ||
Expect(overrideMap["description"]).To(Equal("new description")) | ||
Expect(overrideMap).To(HaveKey("summary")) | ||
Expect(overrideMap["summary"]).To(Equal("new summary")) | ||
}) | ||
|
||
It("fails when an option contains no equals sign", func() { | ||
options.Overrides = []string{ | ||
"THISDOESNOTHAVEANEQUALS", | ||
} | ||
|
||
_, err := options.parseOverrides() | ||
|
||
Expect(err).Should(HaveOccurred()) | ||
}) | ||
|
||
It("fails when an option has no key", func() { | ||
options.Overrides = []string{ | ||
"=VALUE", | ||
} | ||
|
||
_, err := options.parseOverrides() | ||
|
||
Expect(err).Should(HaveOccurred()) | ||
}) | ||
|
||
It("fails when an option has no value", func() { | ||
options.Overrides = []string{ | ||
"KEY=", | ||
} | ||
|
||
_, err := options.parseOverrides() | ||
|
||
Expect(err).Should(HaveOccurred()) | ||
}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, but here under "external message", the command has a lot of "internal message" content for the summary and description. Not a real issue, but might confuse someone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm not quite sure why you can override the
-i
(--internal
) here, with-r internal_only=False
. That seems unintuitive. That might be a good use case to say something like "-i is incompatible with -r internal_only=false". Definitely an edge case, though.Can you elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to avoid adding another command line argument (like
-e
) that includes a blank template, or a template with some sane defaults. As we discussed lets come back and add it in the future if required.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel it would be a bit confusing if we have to use
-i
to combine with the-r
. I will make me think the override works for internal messages only.Could it be possible we just can make the template optional if the
-r
specified?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I'll make a change to that if neither
-t
or -i
is specified, and at least one-r
option is supplied the following template is used by default:This way the user has to explicitly override the
summary
anddescription
. Then if they want to send it to the customer they also have to explicitly override theinternal_only
variable.