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

add and refactor testcase for exchange #1900

Merged
merged 1 commit into from Dec 15, 2017

Conversation

yanxuean
Copy link
Member

@yanxuean yanxuean commented Dec 8, 2017

1.add and refactor testcase for exchange

Signed-off-by: yason yan.xuean@zte.com.cn

@codecov-io
Copy link

codecov-io commented Dec 8, 2017

Codecov Report

Merging #1900 into master will increase coverage by 0.1%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Flag Coverage Δ
#linux 50.77% <ø> (+0.11%) ⬆️
#windows 42.36% <ø> (+0.11%) ⬆️
Impacted Files Coverage Δ
events/exchange/exchange.go 68.91% <0%> (+6.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 03bc5e9...224417a. Read the comment docs.

testevents := []events.Event{
exchange := NewExchange()

t.Log("config events, All events will be published")
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -287,9 +302,25 @@ func TestFilters(t *testing.T) {
}
}

if !reflect.DeepEqual(results, testcase.expected) {
if compareEvents(results, testcase.expected) {
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

@dnephin dnephin Dec 11, 2017

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.

Copy link
Member

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.

@stevvooe
Copy link
Member

stevvooe commented Dec 8, 2017

The testing for exchange filters is good but the refactoring of filters_test.go is completely unnecessary.

@yanxuean
Copy link
Member Author

yanxuean commented Dec 9, 2017

@stevvooe
I add a testcase for filter. The testcase is for "multi name", and the relation of multi name is ORed.
We cann't test it in the original test framework.
and The original test framework is too difficult to maintain. It depend with the order of config data.
So I think it is necessary. Please take a look at it again. Thanks.

		{
+			name: "Multi name",
+			input: []string{
+				"name==baz",
+				"name==bazo",
+			},
+			expected: []interface{}{
+				corpusS["key6"],
+				corpusS["key7"],
 			},
 		},

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
Copy link
Member

Choose a reason for hiding this comment

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

Completely unnecessary change here.

@stevvooe
Copy link
Member

We cann't test it in the original test framework.

The case you are proposing is just two separate test cases. Its not really adding anything to the test.

If you want to test ParseAll, write a new test, but it is really not necessary, as you are just testing the compiler.

The original test framework is too difficult to maintain.

Not really. Just go based on the names.

This test also gets it wrong because it changes the type of the target from interface{} to cEntry, so the actual invariant we are checking at the end is getting broken.

@yanxuean
Copy link
Member Author

OK, you decide it. Thanks for review @dnephin @stevvooe

@yanxuean yanxuean changed the title add and refactor testcase for filter and exchange add and refactor testcase for exchange Dec 12, 2017
@@ -17,23 +17,104 @@ import (

func TestExchangeBasic(t *testing.T) {
ctx := namespaces.WithNamespace(context.Background(), t.Name())
testevents := []events.Event{
exchange := NewExchange()
Copy link
Member

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.

Copy link
Member Author

@yanxuean yanxuean Dec 13, 2017

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
)

@stevvooe
Copy link
Member

@yanxuean So, TestExchangeBasic should remain a basic test. Let's move these tests for a TestExchangeFilters test. That way, we can be sure the original test preserves the behavior.

Signed-off-by: yason <yan.xuean@zte.com.cn>
@yanxuean
Copy link
Member Author

@stevvooe PTAL

@stevvooe
Copy link
Member

LGTM

1 similar comment
@crosbymichael
Copy link
Member

LGTM

@crosbymichael crosbymichael merged commit 9bb2a6f into containerd:master Dec 15, 2017
@yanxuean yanxuean deleted the filter branch December 15, 2017 23:47
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.

None yet

5 participants