Skip to content
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

fix: unexpected error with --select-tag and multiple files #571

Merged
merged 2 commits into from
Jan 26, 2022

Conversation

GGabriele
Copy link
Collaborator

@GGabriele GGabriele commented Jan 26, 2022

When running sync with multiple files and --select-tag,
deck simply appends the existing _info.select_tags of the
various files. If the same tag(s) are present in the files,
these are appended together making deck fail because the
tags passed via the command flag and the ones coming from
the files are expected to match, but the way files are
merged may cause duplicates, hence the unexpected failure.

This removes duplicates from the _info.select_tags resulted
from the merged files.

Related to #561

When running sync with multiple files and --select-tag,
deck simply appends the existing _info.select_tags of the
various files. If the same tag(s) are present in the files,
these are appended together and making deck fail because
tags passed via the command flag and the ones coming from
the files are expected to match, but the way files are
merged may cause duplicates, hence the unexpected failure.

This removes duplicates from the _info.select_tags resulted
from the merged files.
@GGabriele GGabriele requested a review from a team as a code owner January 26, 2022 15:38
@hbagdi hbagdi requested a review from rainest January 26, 2022 17:28
Copy link
Contributor

@rainest rainest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a case to

deck/cmd/common_test.go

Lines 11 to 67 in d0573b4

func TestDetermineSelectorTag(t *testing.T) {
type args struct {
dumpConfig dump.Config
fileContent file.Content
}
tests := []struct {
name string
args args
want []string
wantErr bool
}{
{
name: "both present and equal",
args: args{
dumpConfig: dump.Config{SelectorTags: []string{"foo"}},
fileContent: file.Content{Info: &file.Info{SelectorTags: []string{"foo"}}},
},
want: []string{"foo"},
wantErr: false,
},
{
name: "both present and equal order invariant",
args: args{
dumpConfig: dump.Config{SelectorTags: []string{"foo", "bar"}},
fileContent: file.Content{Info: &file.Info{SelectorTags: []string{"bar", "foo"}}},
},
want: []string{"bar", "foo"},
wantErr: false,
},
{
name: "both present and not equal",
args: args{
dumpConfig: dump.Config{SelectorTags: []string{"bar"}},
fileContent: file.Content{Info: &file.Info{SelectorTags: []string{"foo"}}},
},
want: nil,
wantErr: true,
},
{
name: "only file has tags",
args: args{
dumpConfig: dump.Config{},
fileContent: file.Content{Info: &file.Info{SelectorTags: []string{"foo"}}},
},
want: []string{"foo"},
wantErr: false,
},
{
name: "only config has tags",
args: args{
dumpConfig: dump.Config{SelectorTags: []string{"foo"}},
fileContent: file.Content{Info: &file.Info{}},
},
want: []string{"foo"},
wantErr: false,
},
}
that would trigger the issue without this fix?

@GGabriele
Copy link
Collaborator Author

Can you add a case to

deck/cmd/common_test.go

Lines 11 to 67 in d0573b4

func TestDetermineSelectorTag(t *testing.T) {
type args struct {
dumpConfig dump.Config
fileContent file.Content
}
tests := []struct {
name string
args args
want []string
wantErr bool
}{
{
name: "both present and equal",
args: args{
dumpConfig: dump.Config{SelectorTags: []string{"foo"}},
fileContent: file.Content{Info: &file.Info{SelectorTags: []string{"foo"}}},
},
want: []string{"foo"},
wantErr: false,
},
{
name: "both present and equal order invariant",
args: args{
dumpConfig: dump.Config{SelectorTags: []string{"foo", "bar"}},
fileContent: file.Content{Info: &file.Info{SelectorTags: []string{"bar", "foo"}}},
},
want: []string{"bar", "foo"},
wantErr: false,
},
{
name: "both present and not equal",
args: args{
dumpConfig: dump.Config{SelectorTags: []string{"bar"}},
fileContent: file.Content{Info: &file.Info{SelectorTags: []string{"foo"}}},
},
want: nil,
wantErr: true,
},
{
name: "only file has tags",
args: args{
dumpConfig: dump.Config{},
fileContent: file.Content{Info: &file.Info{SelectorTags: []string{"foo"}}},
},
want: []string{"foo"},
wantErr: false,
},
{
name: "only config has tags",
args: args{
dumpConfig: dump.Config{SelectorTags: []string{"foo"}},
fileContent: file.Content{Info: &file.Info{}},
},
want: []string{"foo"},
wantErr: false,
},
}

that would trigger the issue without this fix?

Done: 32071ed

@rainest rainest enabled auto-merge (squash) January 26, 2022 22:59
@rainest rainest merged commit be847ba into main Jan 26, 2022
@rainest rainest deleted the select_tags_multiple_files branch January 26, 2022 22:59
AntoineJac pushed a commit that referenced this pull request Jan 23, 2024
* fix: unexpected error with --select-tag and multiple files

When running sync with multiple files and --select-tag,
deck simply appends the existing _info.select_tags of the
various files. If the same tag(s) are present in the files,
these are appended together and making deck fail because
tags passed via the command flag and the ones coming from
the files are expected to match, but the way files are
merged may cause duplicates, hence the unexpected failure.

This removes duplicates from the _info.select_tags resulted
from the merged files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants