testutil,skills/types,skills,daemon: tweak discovery of know skill types #478

Merged
merged 8 commits into from Feb 25, 2016

Conversation

Projects
None yet
4 participants
Contributor

zyga commented Feb 12, 2016

This branch moves the discovery of known skill types from skills/ to skills/types.

zyga added some commits Feb 12, 2016

testutil: handle interface types in Contains
This patch fixes Contains (and DeepContains) to handle collections of
interface types. In the past, the code would reject such checks as it
would look at the actual underlying type. Now, if the collection element
is an interface the test checks if the element being looked for
implements that interface.

The change is accompanied with a few simple tests to ensure both failing
and successful cases are working correctly.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
skills/types: add a way to find all the types
This patch adds a replacement to skills.LoadBuiltInTypes() that lives in
the skills/types package. The said package is going to contain all the
implemented skill types so it makes sense for the knowledge about
available types to be stored there to avoid circular imports back to the
skills/ package.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
daemon: use skills/types.AllTypes() to add skill types
This patch changes the mechanism for discovering known types to
AllTypes() since LoadBuiltInTypes() is about to go away.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
skills: remove LoadBuildInTypes()
LoadBuiltInTypes() is now entirely replaced by skills/types/AllTypes().

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
testutils: actually use the dummy tree type
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Contributor

zyga commented Feb 23, 2016

Merged with master to re-test with integration test fixes

Collaborator

mvo5 commented Feb 23, 2016

There are two test failures in the integration tests that are worth investigating

Contributor

fgimenez commented Feb 23, 2016

@mvo5 we have had this problem before [1] it appears eventually when trying to install a snap from the local filesystem, maybe related to the snap.yaml filled with '\0'

[1] http://pastebin.ubuntu.com/15126149/

Collaborator

mvo5 commented Feb 23, 2016

I rerun the tests and its happy again

testutil/checkers.go
- containerV.Type().Elem(), elemV.Type())
- return true
+ containerElemType := containerV.Type().Elem()
+ if containerV.Type().Elem().Kind() == reflect.Interface {
@niemeyer

niemeyer Feb 23, 2016

Contributor

This can be containerElemType as well, created right above.

@zyga

zyga Feb 24, 2016

Contributor

Right, nice, I didn't notice that, updated.

Contributor

niemeyer commented Feb 23, 2016

Nice change, LGTM.

testutil: reuse containerElemType
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
- err = skills.LoadBuiltInTypes(skillRepo)
- if err != nil {
- panic(err.Error())
+ for _, skillType := range types.AllTypes() {
@mvo5

mvo5 Feb 25, 2016

Collaborator

Nice!

+
+func (s *AllSuite) TestAllTypes(c *C) {
+ allTypes := types.AllTypes()
+ c.Check(allTypes, Contains, &types.BoolFileType{})
@mvo5

mvo5 Feb 25, 2016

Collaborator

Sorry for being "mr-smarty-pants" here: c.Check(allTypes, DeepEquals, []skills.Type{&types.BoolFileType{}}) would have worked as well. But now Contains knows about interfaces which is nice as well!

@@ -111,12 +146,16 @@ func (s *CheckersS) TestContainsSlice(c *C) {
c.Assert([]int{1, 2, 3}, Contains, 2)
c.Assert([]int{1, 2, 3}, Contains, 3)
c.Assert([]int{1, 2, 3}, Not(Contains), 4)
+ c.Assert([]animal{&dog{}, &cat{}}, Contains, &dog{})
@mvo5

mvo5 Feb 25, 2016

Collaborator

Nice!

Collaborator

mvo5 commented Feb 25, 2016

Looks good!

mvo5 added a commit that referenced this pull request Feb 25, 2016

Merge pull request #478 from zyga/skill-type-registry
testutil,skills/types,skills,daemon: tweak discovery of know skill types

@mvo5 mvo5 merged commit d2ac5ee into snapcore:master Feb 25, 2016

3 checks passed

Integration tests Success 64 tests run, 0 skipped, 0 failed.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls First build on master at 70.299%
Details

@zyga zyga deleted the zyga:skill-type-registry branch Mar 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment