Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
chipaca committed Nov 24, 2016
1 parent cb79b39 commit 39be7bc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 44 deletions.
20 changes: 16 additions & 4 deletions cmd/snap/cmd_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ func norm(path string) string {
return path
}

func maybePrintType(w io.Writer, t string) {
// XXX: using literals here until we reshuffle snap & client properly
// (and os->core rename happens, etc)
switch t {
case "", "app", "application":
return
case "os":
t = "core"
}

fmt.Fprintf(w, "type:\t%s\n", t)
}

func tryDirect(w io.Writer, path string, verbose bool) bool {
path = norm(path)

Expand Down Expand Up @@ -94,9 +107,7 @@ func tryDirect(w io.Writer, path string, verbose bool) bool {
notes = NotesFromInfo(info)
}
fmt.Fprintf(w, "version:\t%s %s\n", info.Version, notes)
if info.Type != snap.TypeApp {
fmt.Fprintf(w, "type:\t%s\n", info.Type)
}
maybePrintType(w, string(info.Type))

return true
}
Expand Down Expand Up @@ -132,7 +143,7 @@ func (x *infoCmd) Execute([]string) error {
both := coalesce(local, remote)

if both == nil {
fmt.Fprintf(w, "path:\t%q\nwarning:\t%s\n", snapName, i18n.G("not a valid snap"))
fmt.Fprintf(w, "argument:\t%q\nwarning:\t%s\n", snapName, i18n.G("not a valid snap"))
continue
}
noneOK = false
Expand All @@ -142,6 +153,7 @@ func (x *infoCmd) Execute([]string) error {
// TODO: have publisher; use publisher here,
// and additionally print developer if publisher != developer
fmt.Fprintf(w, "publisher:\t%s\n", both.Developer)
maybePrintType(w, both.Type)
if x.Verbose {
fmt.Fprintln(w, "notes:\t")
fmt.Fprintf(w, " private:\t%t\n", both.Private)
Expand Down
91 changes: 52 additions & 39 deletions tests/main/snap-info/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,87 @@
import sys
import yaml

def e(s):
def die(s):
print(s, file=sys.stderr)
sys.exit(1)

def eq(name, s1, s2):
def equals(name, s1, s2):
if s1 != s2:
e("in %s expected %r, got %r" % (name, s2, s1))
die("in %s expected %r, got %r" % (name, s2, s1))

def rx(name, s, r):
def matches(name, s, r):
if not re.search(r, s):
e("in %s expected to match %s, got %r" % (name, r, s))
die("in %s expected to match %s, got %r" % (name, r, s))

def ck(name, d, *a):
def check(name, d, *a):
ka = set()
for k, op, *args in a:
if k not in d:
e("in %s expected to have a key %r" % (name, k))
die("in %s expected to have a key %r" % (name, k))
op(name+"."+k, d[k], *args)
ka.add(k)
kd = set(d)
if ka < kd:
e("in %s: extra keys: %r" % (name, kd-ka))
die("in %s: extra keys: %r" % (name, kd-ka))

def exists(name, d):
pass

verNotesRx = re.compile(r"^\w\S*\s+-$")
def verRevNotesRx(s):
return re.compile(r"^\w\S*\s+\(\d+\)\s+" + s + "$")

res = list(yaml.load_all(sys.stdin))

eq("number of entries", len(res), 5)
equals("number of entries", len(res), 6)

ck("basic", res[0],
("name", eq, "basic"),
("summary", eq, "Basic snap"),
("path", rx, r"^basic_[0-9.]+_all\.snap$"),
("version", rx, verNotesRx),
check("basic", res[0],
("name", equals, "basic"),
("summary", equals, "Basic snap"),
("path", matches, r"^basic_[0-9.]+_all\.snap$"),
("version", matches, verNotesRx),
)

ck("basic-desktop", res[1],
("name", eq, "basic-desktop"),
("path", rx, "snaps/basic-desktop/$"), # note the trailing slash
("summary", eq, ""),
("version", rx, verNotesRx),
check("basic-desktop", res[1],
("name", equals, "basic-desktop"),
("path", matches, "snaps/basic-desktop/$"), # note the trailing slash
("summary", equals, ""),
("version", matches, verNotesRx),
)

ck("test-snapd-tools", res[2],
("name", eq, "test-snapd-tools"),
("publisher", eq, "canonical"),
("summary", eq, "Tools for testing the snapd application"),
("tracking", eq, "stable"),
("installed", rx, verRevNotesRx("-")),
("channels", ck,
("stable", rx, verRevNotesRx("-")),
("candidate", rx, verRevNotesRx("-")),
("beta", rx, verRevNotesRx("-")),
("edge", rx, verRevNotesRx("-")),
check("test-snapd-tools", res[2],
("name", equals, "test-snapd-tools"),
("publisher", equals, "canonical"),
("summary", equals, "Tools for testing the snapd application"),
("tracking", equals, "stable"),
("installed", matches, verRevNotesRx("-")),
("channels", check,
("stable", matches, verRevNotesRx("-")),
("candidate", matches, verRevNotesRx("-")),
("beta", matches, verRevNotesRx("-")),
("edge", matches, verRevNotesRx("-")),
),
)

ck("test-snapd-devmode", res[3],
("name", eq, "test-snapd-devmode"),
("publisher", eq, "canonical"),
("summary", eq, "Basic snap with devmode confinement"),
("tracking", eq, "beta"),
("installed", rx, verRevNotesRx("devmode")),
check("test-snapd-devmode", res[3],
("name", equals, "test-snapd-devmode"),
("publisher", equals, "canonical"),
("summary", equals, "Basic snap with devmode confinement"),
("tracking", equals, "beta"),
("installed", matches, verRevNotesRx("devmode")),
)

check("core", res[4],
("name", equals, "core"),
("publisher", equals, "canonical"),
("type", equals, "core"), # attenti al cane
("summary", exists),
("tracking", exists),
("installed", exists),
("channels", exists),
)

ck("error", res[4],
("path", eq, "/etc/passwd"),
("warning", eq, "not a valid snap"),
check("error", res[5],
("argument", equals, "/etc/passwd"),
("warning", equals, "not a valid snap"),
)
2 changes: 1 addition & 1 deletion tests/main/snap-info/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ execute: |
echo "With one non-snap argument, errors out"
snap info /etc/passwd && exit 1 || true
snap info basic_1.0_all.snap $TESTSLIB/snaps/basic-desktop test-snapd-tools test-snapd-devmode /etc/passwd > out
snap info basic_1.0_all.snap $TESTSLIB/snaps/basic-desktop test-snapd-tools test-snapd-devmode core /etc/passwd > out
python3 check.py < out

0 comments on commit 39be7bc

Please sign in to comment.