Merge lp:~sergiusens/snappy/storeSnapType into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Sergio Schvezov
Status: Merged
Approved by: John Lenton
Approved revision: 444
Merged at revision: 444
Proposed branch: lp:~sergiusens/snappy/storeSnapType
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 110 lines (+57/-3)
3 files modified
snappy/parts.go (+24/-0)
snappy/snapp.go (+2/-3)
snappy/snapp_test.go (+31/-0)
To merge this branch: bzr merge lp:~sergiusens/snappy/storeSnapType
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
Review via email: mp+258437@code.launchpad.net

Commit message

Setup proper SnapType's from the store

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Thanks! Code looks fine, I wonder if the store could send us "app" instead of application but I guess thats problematic for click(?).

review: Approve
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

On Thu, May 07, 2015 at 06:03:36AM -0000, Michael Vogt wrote:
> Review: Approve
>
> Thanks! Code looks fine, I wonder if the store could send us "app" instead of application but I guess thats problematic for click(?).

I argued for app in the original bug feature request and was told no,
reason for this to exist :-/

Revision history for this message
Michael Vogt (mvo) wrote :

What is the original bugreport? If there is no reason for app vs application I think we should ask again for app to avoid client side mangling.

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

On Fri, May 08, 2015 at 07:13:12AM -0000, Michael Vogt wrote:
> What is the original bugreport? If there is no reason for app vs application I think we should ask again for app to avoid client side mangling.

http://pad.lv/1443537

In any case we need to add support for 'os', 'gadget' and 'kernel'

We also need an API name cleanup (for consistency between the store and
snappy) and I already requested Ursula, whom is gathering requirements
for the store now, to take a look at adding that story.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snappy/parts.go'
2--- snappy/parts.go 2015-05-05 15:25:55 +0000
3+++ snappy/parts.go 2015-05-06 23:27:22 +0000
4@@ -18,6 +18,7 @@
5 package snappy
6
7 import (
8+ "encoding/json"
9 "fmt"
10 "net"
11 "net/url"
12@@ -30,6 +31,29 @@
13 // SnapType represents the kind of snap (app, core, frameworks, oem)
14 type SnapType string
15
16+// MarshalJSON returns *m as the JSON encoding of m.
17+func (m SnapType) MarshalJSON() ([]byte, error) {
18+ return json.Marshal(string(m))
19+}
20+
21+// UnmarshalJSON sets *m to a copy of data.
22+func (m *SnapType) UnmarshalJSON(data []byte) error {
23+ var str string
24+ if err := json.Unmarshal(data, &str); err != nil {
25+ return err
26+ }
27+
28+ // this is a workaround as the store sends "application" but snappy uses
29+ // "app" for SnapTypeApp
30+ if str == "application" {
31+ *m = SnapTypeApp
32+ } else {
33+ *m = SnapType(str)
34+ }
35+
36+ return nil
37+}
38+
39 // SystemConfig is a config map holding configs for multiple packages
40 type SystemConfig map[string]interface{}
41
42
43=== modified file 'snappy/snapp.go'
44--- snappy/snapp.go 2015-05-06 12:26:38 +0000
45+++ snappy/snapp.go 2015-05-06 23:27:22 +0000
46@@ -240,7 +240,7 @@
47 RatingsAverage float64 `json:"ratings_average,omitempty"`
48 SupportURL string `json:"support_url"`
49 Title string `json:"title"`
50- Type string `json:"content,omitempty"`
51+ Type SnapType `json:"content,omitempty"`
52 Version string `json:"version"`
53 }
54
55@@ -872,8 +872,7 @@
56
57 // Type returns the type of the SnapPart (app, oem, ...)
58 func (s *RemoteSnapPart) Type() SnapType {
59- // FIXME: the store does not publish this info
60- return SnapTypeApp
61+ return s.pkg.Type
62 }
63
64 // Name returns the name
65
66=== modified file 'snappy/snapp_test.go'
67--- snappy/snapp_test.go 2015-05-05 16:42:09 +0000
68+++ snappy/snapp_test.go 2015-05-06 23:27:22 +0000
69@@ -18,6 +18,7 @@
70 package snappy
71
72 import (
73+ "encoding/json"
74 "io"
75 "io/ioutil"
76 "net/http"
77@@ -1384,3 +1385,33 @@
78 c.Assert(cmds[1], DeepEquals, aCmd{"udevadm", "trigger"})
79 c.Assert(cmds, HasLen, 2)
80 }
81+
82+type SnapTypeSuite struct{}
83+
84+var _ = Suite(&SnapTypeSuite{})
85+
86+func (s *SnapTypeSuite) TestMarshalTypes(c *C) {
87+ out, err := json.Marshal(SnapTypeApp)
88+ c.Assert(err, IsNil)
89+ c.Check(string(out), Equals, "\"app\"")
90+
91+ out, err = json.Marshal(SnapTypeOem)
92+ c.Assert(err, IsNil)
93+ c.Check(string(out), Equals, "\"oem\"")
94+}
95+
96+func (s *SnapTypeSuite) TestUnmarshalTypes(c *C) {
97+ var st SnapType
98+
99+ err := json.Unmarshal([]byte("\"application\""), &st)
100+ c.Assert(err, IsNil)
101+ c.Check(st, Equals, SnapTypeApp)
102+
103+ err = json.Unmarshal([]byte("\"app\""), &st)
104+ c.Assert(err, IsNil)
105+ c.Check(st, Equals, SnapTypeApp)
106+
107+ err = json.Unmarshal([]byte("\"oem\""), &st)
108+ c.Assert(err, IsNil)
109+ c.Check(st, Equals, SnapTypeOem)
110+}

Subscribers

People subscribed via source and target branches