Skip to content

Add unit tests for VCH create#6764

Merged
jzt merged 2 commits intovmware:feature/vic-machine-servicefrom
jzt:vic-machine/6018
Nov 18, 2017
Merged

Add unit tests for VCH create#6764
jzt merged 2 commits intovmware:feature/vic-machine-servicefrom
jzt:vic-machine/6018

Conversation

@jzt
Copy link
Contributor

@jzt jzt commented Nov 14, 2017

This main purpose of this change is to test the buildCreate function in vch_create.go, to verify that the Create struct that is generated matches the same struct that would be generated using the CLI.

There are some tests around help functions as well.

Fixes #6018

@jzt jzt force-pushed the vic-machine/6018 branch 2 times, most recently from 41a6a1c to f4b1c0b Compare November 15, 2017 01:24
@jzt jzt requested review from andrewtchin and zjs November 15, 2017 18:12
@zjs zjs force-pushed the feature/vic-machine-service branch from 501e8a9 to 208aa39 Compare November 15, 2017 18:24
@zjs zjs force-pushed the feature/vic-machine-service branch from 208aa39 to 729d15f Compare November 15, 2017 21:52
@jzt jzt force-pushed the vic-machine/6018 branch from f4b1c0b to 54560ad Compare November 16, 2017 02:04
expected = m.ID
actual, err = fromManagedObject(op, mf, "t", m)
assert.NoError(t, err, "Expected nil error, got %#v", err)
assert.Equal(t, expected, actual, "Expected %s, got %s", expected, actual)
Copy link
Member

Choose a reason for hiding this comment

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

Curious (since I'm new to unit testing in go): what's the goal of explicitly passing Expected %s, got %s", expected, actual? Shouldn't the default behavior be to print something along those lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've been using this pattern since I started because of some other test I referenced in the beginning. :)

But, upon investigating:

func TestTest(t *testing.T) {                
        assert.Equal(t, "expected", "actual")
}
--- FAIL: TestTest (0.00s)
  Error Trace:  vch_create_test.go:47
  Error:    Not equal: "expected" (expected)
              != "actual" (actual)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

assert.NoError(t, err, "Expected nil error, got %#v", err)
assert.Equal(t, expected, actual, "Expected %s, got %s", expected, actual)

m.ID = "testID"
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't clear the Name. Should there be a separate test case for having an ID and no name?

Copy link
Contributor Author

@jzt jzt Nov 16, 2017

Choose a reason for hiding this comment

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

Edit: sorry, misread this the first time around:

fromManagedObject will return finder.Element.Path if m.ID is not empty. Otherwise, it will return m.Name.

So even if there's an ID and no Name, we still get ID.

Copy link
Member

Choose a reason for hiding this comment

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

Good enough for now 👍

"github.com/vmware/vic/pkg/trace"
)

type mockFinder struct {
Copy link
Member

Choose a reason for hiding this comment

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

Would it be valuable to make this embed a testify mock.Mock so that we can verify that the Element method is called with the expected arguments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will look into this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add this at a later time as per our slack convo.

@jzt jzt force-pushed the vic-machine/6018 branch 2 times, most recently from ba864e1 to b983a04 Compare November 16, 2017 03:33
@zjs zjs force-pushed the feature/vic-machine-service branch from 729d15f to dd3128a Compare November 16, 2017 22:50
@jzt jzt force-pushed the vic-machine/6018 branch from b983a04 to 20693d8 Compare November 18, 2017 17:18
"github.com/vmware/vic/lib/install/data"
"github.com/vmware/vic/lib/install/management"
"github.com/vmware/vic/lib/install/validate"

Copy link
Member

Choose a reason for hiding this comment

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

nit: I don't think this line should be here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, fixed

@jzt jzt merged commit 03360ce into vmware:feature/vic-machine-service Nov 18, 2017
zjs pushed a commit that referenced this pull request Nov 20, 2017
AngieCris pushed a commit to AngieCris/vic that referenced this pull request Nov 20, 2017
@jzt jzt deleted the vic-machine/6018 branch April 26, 2018 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants