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
add and refactor testcase for exchange #1900
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1900 +/- ##
=========================================
+ Coverage 47.29% 47.39% +0.1%
=========================================
Files 89 89
Lines 8830 8830
=========================================
+ Hits 4176 4185 +9
+ Misses 3968 3959 -9
Partials 686 686
Continue to review full report at Codecov.
|
events/exchange/exchange_test.go
Outdated
testevents := []events.Event{ | ||
exchange := NewExchange() | ||
|
||
t.Log("config events, All events will be published") |
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.
What's the purpose of these t.Log()
messages? They read more like comments
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.
done
filters/filter_test.go
Outdated
@@ -287,9 +302,25 @@ func TestFilters(t *testing.T) { | |||
} | |||
} | |||
|
|||
if !reflect.DeepEqual(results, testcase.expected) { | |||
if compareEvents(results, testcase.expected) { |
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.
assert.Equal()
is already being used in this repo. Probably makes more sense to use that instead of writing a custom assertion that does the same thing.
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.
We need to compare two slice. and The element of slice has different order. So assert.Equal cann't do it.
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.
assert.Equal(t, sorted(testcase.expected), sorted(results))
I would argue this make the expected behaviour really obvious to anyone reading the test.
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.
The element of slice has different order.
If this is the case, something has been broken. The filtered set should have the same order as the original set. Moving away from reflect.DeepEqual here is a bug in this "refactoring".
Like I said, remove the changes to filter_test.go from this PR.
The testing for exchange filters is good but the refactoring of filters_test.go is completely unnecessary. |
@stevvooe
|
filters/filter_test.go
Outdated
errString: `filters: parse error: [image~= >|,|< id?=?fbaq]: expected value or quoted`, | ||
}, | ||
} { | ||
t.Run(testcase.name, func(t *testing.T) { | ||
t.Logf("testcase: %q", testcase.input) | ||
filter, err := Parse(testcase.input) | ||
var filter Filter |
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.
Completely unnecessary change here.
The case you are proposing is just two separate test cases. Its not really adding anything to the test. If you want to test
Not really. Just go based on the names. This test also gets it wrong because it changes the type of the target from |
events/exchange/exchange_test.go
Outdated
@@ -17,23 +17,104 @@ import ( | |||
|
|||
func TestExchangeBasic(t *testing.T) { | |||
ctx := namespaces.WithNamespace(context.Background(), t.Name()) | |||
testevents := []events.Event{ | |||
exchange := NewExchange() |
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.
Use a var block here.
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.
Do you mean var declaration block?
var (
testevents :=
exchange:=
xxxxx
)
@yanxuean So, |
Signed-off-by: yason <yan.xuean@zte.com.cn>
@stevvooe PTAL |
LGTM |
1 similar comment
LGTM |
1.add and refactor testcase for exchange
Signed-off-by: yason yan.xuean@zte.com.cn