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 storeBulkURI, err = url.Parse(mockServer.URL + "/updates/") c.Assert(err, IsNil) snap := NewUbuntuStoreSnapRepository() c.Assert(snap, NotNil) // override the real ActiveSnapIterByType to return our // mock data mockActiveSnapIterByType([]string{funkyAppName}) // the actual test results, err := snap.Updates() c.Assert(err, IsNil) c.Assert(results, HasLen, 1) c.Assert(results[0].Name(), Equals, funkyAppName) c.Assert(results[0].Version(), Equals, "42") }
func (s *SnapTestSuite) TestUbuntuStoreRepositoryUpdatesNoSnaps(c *C) { var err error storeDetailsURI, err = url.Parse("https://some-uri") c.Assert(err, IsNil) snap := NewUbuntuStoreSnapRepository() c.Assert(snap, NotNil) // ensure we do not hit the net if there is nothing installed // (otherwise the store will send us all snaps) snap.bulkURI = "http://i-do.not-exist.really-not" mockActiveSnapIterByType([]string{}) // the actual test results, err := snap.Updates() c.Assert(err, IsNil) c.Assert(results, HasLen, 0) }