Example #1
0
func (s *SnapTestSuite) TestUbuntuStoreRepositoryUpdates(c *C) {
	mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		jsonReq, err := ioutil.ReadAll(r.Body)
		c.Assert(err, IsNil)
		c.Assert(string(jsonReq), Equals, `{"name":["`+funkyAppName+`"]}`)
		io.WriteString(w, MockUpdatesJSON)
	}))

	c.Assert(mockServer, NotNil)
	defer mockServer.Close()

	var err error
	s.storeCfg.BulkURI, err = url.Parse(mockServer.URL + "/updates/")
	c.Assert(err, IsNil)
	repo := store.NewUbuntuStoreSnapRepository(s.storeCfg, "")
	c.Assert(repo, NotNil)

	// override the real ActiveSnapIterByType to return our
	// mock data
	mockActiveSnapIterByType([]string{funkyAppName})

	// the actual test
	results, err := snapUpdates(repo)
	c.Assert(err, IsNil)
	c.Assert(results, HasLen, 1)
	c.Assert(results[0].Name(), Equals, funkyAppName)
	c.Assert(results[0].Revision, Equals, 3)
	c.Assert(results[0].Version, Equals, "42")
}
Example #2
0
// NewConfiguredUbuntuStoreSnapRepository creates a new fully configured store.SnapUbuntuStoreRepository with the store id selected by the gadget.
func NewConfiguredUbuntuStoreSnapRepository() *store.SnapUbuntuStoreRepository {
	storeID := ""
	if cand := os.Getenv("UBUNTU_STORE_ID"); cand != "" {
		storeID = cand
	} else if cand := StoreID(); cand != "" {
		storeID = cand
	}
	return store.NewUbuntuStoreSnapRepository(storeConfig, storeID)
}
Example #3
0
func (s *SnapTestSuite) TestUbuntuStoreRepositoryUpdatesNoSnaps(c *C) {

	var err error
	s.storeCfg.SearchURI, err = url.Parse("https://some-uri")
	c.Assert(err, IsNil)
	repo := store.NewUbuntuStoreSnapRepository(s.storeCfg, "")
	c.Assert(repo, NotNil)

	mockActiveSnapIterByType([]string{})

	// the actual test
	results, err := snapUpdates(repo)
	c.Assert(err, IsNil)
	c.Assert(results, HasLen, 0)
}
Example #4
0
func (s *SnapTestSuite) TestRemoteSnapUpgradeService(c *C) {
	snapPackage := makeTestSnapPackage(c, `name: foo
version: 1.0
apps:
 svc:
  command: svc
  daemon: forking
`)
	snapR, err := os.Open(snapPackage)
	c.Assert(err, IsNil)

	iconContent := "icon"
	mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.URL.Path {
		case "/snap":
			io.Copy(w, snapR)
			snapR.Seek(0, 0)
		case "/icon":
			fmt.Fprintf(w, iconContent)
		default:
			panic("unexpected url path: " + r.URL.Path)
		}
	}))
	c.Assert(mockServer, NotNil)
	defer mockServer.Close()

	r := &snap.Info{}
	r.OfficialName = "foo"
	r.Developer = "bar"
	r.Version = "1.0"
	r.Developer = testDeveloper
	r.AnonDownloadURL = mockServer.URL + "/snap"
	r.DownloadURL = mockServer.URL + "/snap"
	r.IconURL = mockServer.URL + "/icon"

	mStore := store.NewUbuntuStoreSnapRepository(s.storeCfg, "")
	p := &MockProgressMeter{}
	name, err := installRemote(mStore, r, 0, p)
	c.Assert(err, IsNil)
	c.Check(name, Equals, "foo")
	c.Check(p.notified, HasLen, 0)

	_, err = installRemote(mStore, r, 0, p)
	c.Assert(err, IsNil)
	c.Check(name, Equals, "foo")
	c.Check(p.notified, HasLen, 1)
	c.Check(p.notified[0], Matches, "Waiting for .* stop.")
}
Example #5
0
func (s *SnapTestSuite) TestUbuntuStoreRepositoryInstallRemoteSnap(c *C) {
	snapPackage := makeTestSnapPackage(c, "")
	snapR, err := os.Open(snapPackage)
	c.Assert(err, IsNil)

	mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.URL.Path {
		case "/snap":
			io.Copy(w, snapR)
		default:
			panic("unexpected url path: " + r.URL.Path)
		}
	}))
	c.Assert(mockServer, NotNil)
	defer mockServer.Close()

	r := &snap.Info{}
	r.OfficialName = "foo"
	r.Revision = 42
	r.Developer = "bar"
	r.EditedDescription = "this is a description"
	r.Version = "1.0"
	r.AnonDownloadURL = mockServer.URL + "/snap"
	r.DownloadURL = mockServer.URL + "/snap"
	r.IconURL = mockServer.URL + "/icon"

	mStore := store.NewUbuntuStoreSnapRepository(s.storeCfg, "")
	p := &MockProgressMeter{}
	name, err := installRemote(mStore, r, 0, p)
	c.Assert(err, IsNil)
	c.Check(name, Equals, "foo")
	st, err := os.Stat(snapPackage)
	c.Assert(err, IsNil)
	c.Assert(p.written, Equals, int(st.Size()))

	installed, err := (&Overlord{}).Installed()
	c.Assert(err, IsNil)
	c.Assert(installed, HasLen, 1)

	c.Check(installed[0].Info().Revision, Equals, 42)
	c.Check(installed[0].Developer(), Equals, "bar")
	c.Check(installed[0].Info().Description(), Equals, "this is a description")

	_, err = os.Stat(filepath.Join(dirs.SnapMetaDir, "foo_42.manifest"))
	c.Check(err, IsNil)
}