-
Notifications
You must be signed in to change notification settings - Fork 6
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
refactor instance filters #283
Open
dominik-przybyl-wttech
wants to merge
9
commits into
main
Choose a base branch
from
instance-filters
base: main
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 6 commits
Commits
Show all changes
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
//go:build int_test | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/wttech/aemc/pkg" | ||
"sort" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func testInstanceList(t *testing.T, args []string, expectedResult bool, expectedIDs []string) { | ||
cli := NewCLI() | ||
cmd := cli.cmd | ||
cmd.SetArgs(args) | ||
|
||
defer func() { | ||
err := recover() | ||
actualResult := err != nil | ||
if actualResult != expectedResult { | ||
t.Errorf("InstanceList(%v) = %v; want %v", args, actualResult, expectedResult) | ||
} else if actualResult && expectedResult { | ||
actualIDs := []string{} | ||
instances := cli.outputResponse.Data["instances"].([]pkg.Instance) | ||
for _, i := range instances { | ||
actualIDs = append(actualIDs, i.ID()) | ||
} | ||
sort.SliceStable(actualIDs, func(i, j int) bool { | ||
return strings.Compare(actualIDs[i], actualIDs[j]) < 0 | ||
}) | ||
sort.SliceStable(expectedIDs, func(i, j int) bool { | ||
return strings.Compare(expectedIDs[i], expectedIDs[j]) < 0 | ||
}) | ||
result := len(actualIDs) == len(expectedIDs) | ||
for i := range actualIDs { | ||
result = result && actualIDs[i] == expectedIDs[i] | ||
} | ||
if !result { | ||
t.Errorf("InstanceList(%v) = %v; want %v", args, actualIDs, expectedIDs) | ||
} | ||
} | ||
}() | ||
|
||
_ = cmd.Execute() | ||
} | ||
|
||
func TestAllInstances(t *testing.T) { | ||
testInstanceList(t, []string{"instance", "list", "--output-value", "NONE"}, true, []string{"local_author", "local_publish"}) | ||
} | ||
|
||
func TestAuthorInstances(t *testing.T) { | ||
testInstanceList(t, []string{"instance", "list", "-A", "--output-value", "NONE"}, true, []string{"local_author"}) | ||
} | ||
|
||
func TestPublishInstances(t *testing.T) { | ||
testInstanceList(t, []string{"instance", "list", "-P", "--output-value", "NONE"}, true, []string{"local_publish"}) | ||
} | ||
|
||
func TestInstanceByID(t *testing.T) { | ||
testInstanceList(t, []string{"instance", "list", "-I", "local_author", "-I", "local_publish", "--output-value", "NONE"}, true, []string{"local_author", "local_publish"}) | ||
} | ||
|
||
func TestInstanceByURL(t *testing.T) { | ||
testInstanceList(t, []string{"instance", "list", "-U", "http://admin:[email protected]:4502", "-U", "http://admin:[email protected]:4503", "-U", "test_author=http://admin:[email protected]:4502", "--output-value", "NONE"}, true, []string{"remote_adhoc_1", "remote_adhoc_2", "test_author"}) | ||
} | ||
|
||
func TestAuthorInstanceByURL(t *testing.T) { | ||
testInstanceList(t, []string{"instance", "list", "-U", "dev-auth_author=http://admin:[email protected]:4502", "-U", "dev-pub1_publish=http://admin:[email protected]:4503", "-U", "dev-pub2_publish=http://admin:[email protected]:4504", "-A", "--output-value", "NONE"}, true, []string{"dev-auth_author"}) | ||
} | ||
|
||
func TestPublishInstanceByURL(t *testing.T) { | ||
testInstanceList(t, []string{"instance", "list", "-U", "dev-auth_author=http://admin:[email protected]:4502", "-U", "dev-pub1_publish=http://admin:[email protected]:4503", "-U", "dev-pub2_publish=http://admin:[email protected]:4504", "-P", "--output-value", "NONE"}, true, []string{"dev-pub1_publish", "dev-pub2_publish"}) | ||
} | ||
|
||
func TestConflictAuthorAndPublish(t *testing.T) { | ||
testInstanceList(t, []string{"instance", "list", "-A", "-P"}, false, []string{}) | ||
} | ||
|
||
func TestConflictByIDAndAuthor(t *testing.T) { | ||
testInstanceList(t, []string{"instance", "list", "-I", "local_author", "-A"}, false, []string{}) | ||
} | ||
|
||
func TestConflictByIDAndPublish(t *testing.T) { | ||
testInstanceList(t, []string{"instance", "list", "-I", "local_author", "-P"}, false, []string{}) | ||
} | ||
|
||
func TestConflictIDAndURL(t *testing.T) { | ||
testInstanceList(t, []string{"instance", "list", "-I", "local_author", "-U", "http://admin:[email protected]:4502"}, false, []string{}) | ||
} |
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 |
---|---|---|
|
@@ -71,16 +71,17 @@ func (c *CLI) rootFlags(cmd *cobra.Command) { | |
cmd.PersistentFlags().StringSliceP("instance-url", "U", cv.GetStringSlice("instance.adhoc_url"), "Use only AEM instance(s) at ad-hoc specified URL(s)") | ||
_ = cv.BindPFlag("instance.adhoc_url", cmd.PersistentFlags().Lookup("instance-url")) | ||
|
||
cmd.PersistentFlags().StringP("instance-id", "I", cv.GetString("instance.filter.id"), "Use only AEM instance configured with the exact ID") | ||
cmd.PersistentFlags().StringSliceP("instance-id", "I", cv.GetStringSlice("instance.filter.id"), "Use only AEM instance(s) configured with the exact ID") | ||
_ = cv.BindPFlag("instance.filter.id", cmd.PersistentFlags().Lookup("instance-id")) | ||
|
||
cmd.PersistentFlags().BoolP("instance-author", "A", cv.GetBool("instance.filter.authors"), "Use only AEM author instance") | ||
cmd.PersistentFlags().BoolP("instance-author", "A", cv.GetBool("instance.filter.authors"), "Use only AEM author instance(s)") | ||
_ = cv.BindPFlag("instance.filter.authors", cmd.PersistentFlags().Lookup("instance-author")) | ||
|
||
cmd.PersistentFlags().BoolP("instance-publish", "P", cv.GetBool("instance.filter.publishes"), "Use only AEM publish instance") | ||
cmd.PersistentFlags().BoolP("instance-publish", "P", cv.GetBool("instance.filter.publishes"), "Use only AEM publish instance(s)") | ||
_ = cv.BindPFlag("instance.filter.publishes", cmd.PersistentFlags().Lookup("instance-publish")) | ||
|
||
cmd.MarkFlagsMutuallyExclusive("instance-author", "instance-publish") | ||
cmd.MarkFlagsMutuallyExclusive("instance-url", "instance-id") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is wrong; you could always define all urls and then filter one to be used only with instance-id |
||
cmd.MarkFlagsMutuallyExclusive("instance-id", "instance-author", "instance-publish") | ||
|
||
cmd.PersistentFlags().String("instance-processing", cv.GetString("instance.processing_mode"), "Controls processing mode for instances ("+(strings.Join(instance.ProcessingModes(), "|")+")")) | ||
_ = cv.BindPFlag("instance.processing_mode", cmd.PersistentFlags().Lookup("instance-processing")) | ||
|
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
Oops, something went wrong.
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.
much better with adhoc urls ;) thx