Merge lp:~elopio/snappy/licensed_test into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Leo Arias
Status: Work in progress
Proposed branch: lp:~elopio/snappy/licensed_test
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 74 lines (+41/-0)
3 files modified
_integration-tests/tests/examples_test.go (+27/-0)
progress/progress.go (+3/-0)
progress/progress_test.go (+11/-0)
To merge this branch: bzr merge lp:~elopio/snappy/licensed_test
Reviewer Review Type Date Requested Status
John Lenton Pending
Snappy Developers Pending
Review via email: mp+275744@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

@Chipaca, maybe you can give us a hand here. I don't understand why the CombinedOutput of the command only shows:

Installing licensed.canonical\nlicensed failed to install: license not accepted\n

Where did the rest of the output go?

Revision history for this message
Leo Arias (elopio) wrote :

To reproduce:

$ go run ./_integration-tests/main.go --filter licensedExampleSuite

Revision history for this message
John Lenton (chipaca) wrote :

Just to document (and expand a little) what I told elopio on IRC, the problem is that snappy checks whether it's running on a tty and uses a different "progress bar" kind of thing, which includes the functionality for checking for license acceptance. If you don't have a tty, you get a nop.

Two ways around it: change the test so it's snappy is running under a tty (using a pseudo tty), or, http://pastebin.ubuntu.com/12971806/ and set that env var when running a test that needs it.

lp:~elopio/snappy/licensed_test updated
785. By Leo Arias

Added an environment variable to overwrite the terminal check.

786. By Leo Arias

Set the env ar during the test.

Unmerged revisions

786. By Leo Arias

Set the env ar during the test.

785. By Leo Arias

Added an environment variable to overwrite the terminal check.

784. By Leo Arias

Simplify the test to show the problem.

783. By Leo Arias

Merged with trunk.

782. By Leo Arias

Test

781. By Leo Arias

Merged with prerequisite.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '_integration-tests/tests/examples_test.go'
2--- _integration-tests/tests/examples_test.go 2015-10-19 23:12:30 +0000
3+++ _integration-tests/tests/examples_test.go 2015-10-27 00:54:02 +0000
4@@ -24,6 +24,7 @@
5 "io/ioutil"
6 "net/http"
7 "os"
8+ "os/exec"
9
10 "launchpad.net/snappy/_integration-tests/testutils/cli"
11 "launchpad.net/snappy/_integration-tests/testutils/common"
12@@ -172,3 +173,29 @@
13 c.Assert(output, check.Equals, t.message, check.Commentf("Wrong message"))
14 }
15 }
16+
17+var _ = check.Suite(&licensedExampleSuite{})
18+
19+type licensedExampleSuite struct {
20+ common.SnappySuite
21+}
22+
23+func (s *licensedExampleSuite) TestAcceptLicenseMustInstallSnap(c *check.C) {
24+ originalValue := os.Getenv("SNAPPY_HAS_TERMINAL")
25+ defer os.Setenv("SNAPPY_HAS_TERMINAL", originalValue)
26+
27+ cmd := exec.Command("sudo", "snappy", "install", "licensed.canonical")
28+ output, _ := cmd.CombinedOutput()
29+
30+ expected := "Installing licensed.canonical\n" +
31+ "Starting download of licensed\n" +
32+ ".*\n" +
33+ "Done\n" +
34+ "licensed requires that you accept the following license before continuing\n" +
35+ "This product is meant for educational purposes only. .* No other warranty expressed or implied.\n" +
36+ "\n" +
37+ "Do you agree? [y/n] "
38+ c.Assert(string(output), check.Matches, expected)
39+
40+ defer common.RemoveSnap(c, "licensed.canonical")
41+}
42
43=== modified file 'progress/progress.go'
44--- progress/progress.go 2015-06-03 11:48:37 +0000
45+++ progress/progress.go 2015-10-27 00:54:02 +0000
46@@ -198,6 +198,9 @@
47 // attachedToTerminal returns true if the calling process is attached to
48 // a terminal device.
49 var attachedToTerminal = func() bool {
50+ if os.Getenv("SNAPPY_HAS_TERMINAL") != "" {
51+ return true
52+ }
53 fd := int(os.Stdin.Fd())
54
55 return isatty(fd)
56
57=== modified file 'progress/progress_test.go'
58--- progress/progress_test.go 2015-06-08 14:25:07 +0000
59+++ progress/progress_test.go 2015-10-27 00:54:02 +0000
60@@ -148,3 +148,14 @@
61 c.Assert(pbar, FitsTypeOf, &NullProgress{})
62
63 }
64+
65+func (ts *ProgressTestSuite) TestSnappyHasTerminalEnvVar(c *C) {
66+ originalValue := os.Getenv("SNAPPY_HAS_TERMINAL")
67+ defer os.Setenv("SNAPPY_HAS_TERMINAL", originalValue)
68+
69+ os.Setenv("SNAPPY_HAS_TERMINAL", "1")
70+ c.Assert(attachedToTerminal(), Equals, true)
71+
72+ os.Setenv("SNAPPY_HAS_TERMINAL", "")
73+ c.Assert(attachedToTerminal(), Equals, false)
74+}

Subscribers

People subscribed via source and target branches