Skip to content

Commit

Permalink
fix: restoring tests, cleaning up post-ds.Transform refactor
Browse files Browse the repository at this point in the history
)
  • Loading branch information
b5 committed Dec 12, 2017
1 parent d4778fe commit f3dea07
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 103 deletions.
5 changes: 2 additions & 3 deletions api/handlers/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/qri-io/qri/core"
"github.com/qri-io/qri/logging"
"github.com/qri-io/qri/repo"
"github.com/qri-io/qri/repo/profile"
)

// ProfileHandlers wraps a requests struct to interface with http.HandlerFunc
Expand Down Expand Up @@ -91,7 +90,7 @@ func (h *ProfileHandlers) setProfilePhotoHandler(w http.ResponseWriter, r *http.
}
}

res := &profile.Profile{}
res := &core.Profile{}
if err := h.SetProfilePhoto(p, res); err != nil {
h.log.Infof("error initializing dataset: %s", err.Error())
util.WriteErrResponse(w, http.StatusInternalServerError, err)
Expand Down Expand Up @@ -128,7 +127,7 @@ func (h *ProfileHandlers) setPosterHandler(w http.ResponseWriter, r *http.Reques
}
}

res := &profile.Profile{}
res := &core.Profile{}
if err := h.SetPosterPhoto(p, res); err != nil {
h.log.Infof("error initializing dataset: %s", err.Error())
util.WriteErrResponse(w, http.StatusInternalServerError, err)
Expand Down
19 changes: 17 additions & 2 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,34 @@ import (
"encoding/json"
"fmt"
"github.com/qri-io/dataset"
"github.com/qri-io/qri/core"
"github.com/qri-io/qri/repo"
"github.com/spf13/cobra"
)

var (
dsListLimit, dsListOffset int
)

var datasetListCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "list your local datasets",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
// TODO - add limit & offset params
refs, err := GetRepo(false).Namespace(100, 0)
r, err := DatasetRequests(false)
ExitIfErr(err)

outformat := cmd.Flag("format").Value.String()
p := &core.ListParams{
Limit: dsListLimit,
Offset: dsListOffset,
}
refs := []*repo.DatasetRef{}
err = r.List(p, &refs)
ExitIfErr(err)

outformat := cmd.Flag("format").Value.String()
switch outformat {
case "":
for _, ref := range refs {
Expand All @@ -38,4 +51,6 @@ var datasetListCmd = &cobra.Command{
func init() {
RootCmd.AddCommand(datasetListCmd)
datasetListCmd.Flags().StringP("format", "f", "", "set output format [json]")
datasetListCmd.Flags().IntVarP(&dsListLimit, "limit", "l", 25, "limit results, default 25")
datasetListCmd.Flags().IntVarP(&dsListOffset, "offset", "o", 0, "offset results, default 0")
}
3 changes: 2 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ var runCmd = &cobra.Command{
ErrExit(fmt.Errorf("Please provide a query string to execute"))
}

req, err := QueryRequests(false)
r, cli, err := RepoOrClient(false)
ExitIfErr(err)
req := core.NewQueryRequests(r, cli)

format, err := dataset.ParseDataFormatString(cmd.Flag("format").Value.String())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestHistoryRequestsLog(t *testing.T) {
{&LogParams{Path: path}, []*repo.DatasetRef{&repo.DatasetRef{Path: path}}, ""},
}

req := NewHistoryRequests(mr)
req := NewHistoryRequests(mr, nil)
for i, c := range cases {
got := []*repo.DatasetRef{}
err := req.Log(c.p, &got)
Expand Down
2 changes: 1 addition & 1 deletion core/peers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestPeerRequestsList(t *testing.T) {
}

// TODO - need to upgrade this to include a mock node
req := NewPeerRequests(mr, &p2p.QriNode{})
req := NewPeerRequests(&p2p.QriNode{Repo: mr}, nil)
for i, c := range cases {
got := []*profile.Profile{}
err := req.List(c.p, &got)
Expand Down
17 changes: 14 additions & 3 deletions core/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ type FileParams struct {
Data io.Reader // reader of structured data. either Url or Data is required
}

func (r *ProfileRequests) SetProfilePhoto(p *FileParams, res *profile.Profile) error {
func (r *ProfileRequests) SetProfilePhoto(p *FileParams, res *Profile) error {
if r.cli != nil {
return r.cli.Call("ProfileRequests.SetProfilePhoto", p, res)
}
Expand Down Expand Up @@ -176,11 +176,16 @@ func (r *ProfileRequests) SetProfilePhoto(p *FileParams, res *profile.Profile) e
return fmt.Errorf("error saving profile: %s", err.Error())
}

*res = *pro
_p, err := marshalProfile(pro)
if err != nil {
return err
}

*res = *_p
return nil
}

func (r *ProfileRequests) SetPosterPhoto(p *FileParams, res *profile.Profile) error {
func (r *ProfileRequests) SetPosterPhoto(p *FileParams, res *Profile) error {
if r.cli != nil {
return r.cli.Call("ProfileRequests.SetPosterPhoto", p, res)
}
Expand Down Expand Up @@ -219,5 +224,11 @@ func (r *ProfileRequests) SetPosterPhoto(p *FileParams, res *profile.Profile) er
return fmt.Errorf("error saving profile: %s", err.Error())
}

_p, err := marshalProfile(pro)
if err != nil {
return err
}

*res = *_p
return nil
}
42 changes: 21 additions & 21 deletions core/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func TestProfileRequestsGet(t *testing.T) {
return
}

req := NewProfileRequests(mr)
req := NewProfileRequests(mr, nil)
for i, c := range cases {
got := &profile.Profile{}
got := &Profile{}
err := req.GetProfile(&c.in, got)

if !(err == nil && c.err == "" || err != nil && err.Error() == c.err) {
Expand All @@ -40,12 +40,12 @@ func TestProfileRequestsGet(t *testing.T) {

func TestProfileRequestsSave(t *testing.T) {
cases := []struct {
p *profile.Profile
res *profile.Profile
p *Profile
res *Profile
err string
}{
{nil, nil, "profile required for update"},
{&profile.Profile{}, nil, ""},
{&Profile{}, nil, ""},
// TODO - moar tests
}

Expand All @@ -55,9 +55,9 @@ func TestProfileRequestsSave(t *testing.T) {
return
}

req := NewProfileRequests(mr)
req := NewProfileRequests(mr, nil)
for i, c := range cases {
got := &profile.Profile{}
got := &Profile{}
err := req.SaveProfile(c.p, got)

if !(err == nil && c.err == "" || err != nil && err.Error() == c.err) {
Expand All @@ -73,9 +73,9 @@ func TestProfileRequestsSetProfilePhoto(t *testing.T) {
respath datastore.Key
err string
}{
{"", datastore.Key{}, "file is required"},
{"testdata/ink_big_photo.jpg", datastore.Key{}, "file size too large. max size is 250kb"},
{"testdata/q_bang.svg", datastore.Key{}, "invalid file format. only .jpg & .png images allowed"},
{"", datastore.NewKey(""), "file is required"},
{"testdata/ink_big_photo.jpg", datastore.NewKey(""), "file size too large. max size is 250kb"},
{"testdata/q_bang.svg", datastore.NewKey(""), "invalid file format. only .jpg & .png images allowed"},
{"testdata/rico_400x400.jpg", datastore.NewKey("/map/QmRdexT18WuAKVX3vPusqmJTWLeNSeJgjmMbaF5QLGHna1"), ""},
}

Expand All @@ -85,7 +85,7 @@ func TestProfileRequestsSetProfilePhoto(t *testing.T) {
return
}

req := NewProfileRequests(mr)
req := NewProfileRequests(mr, nil)
for i, c := range cases {
p := &FileParams{}
if c.infile != "" {
Expand All @@ -98,15 +98,15 @@ func TestProfileRequestsSetProfilePhoto(t *testing.T) {
p.Data = r
}

res := &profile.Profile{}
res := &Profile{}
err := req.SetProfilePhoto(p, res)
if !(err == nil && c.err == "" || err != nil && err.Error() == c.err) {
t.Errorf("case %d error mismatch. expected: %s, got: %s", i, c.err, err.Error())
continue
}

if !c.respath.Equal(res.Profile) {
t.Errorf("case %d profile hash mismatch. expected: %s, got: %s", i, c.respath.String(), res.Profile.String())
if !c.respath.Equal(datastore.NewKey(res.Profile)) {
t.Errorf("case %d profile hash mismatch. expected: %s, got: %s", i, c.respath.String(), res.Profile)
continue
}
}
Expand All @@ -118,9 +118,9 @@ func TestProfileRequestsSetPosterPhoto(t *testing.T) {
respath datastore.Key
err string
}{
{"", datastore.Key{}, "file is required"},
{"testdata/ink_big_photo.jpg", datastore.Key{}, "file size too large. max size is 250kb"},
{"testdata/q_bang.svg", datastore.Key{}, "invalid file format. only .jpg & .png images allowed"},
{"", datastore.NewKey(""), "file is required"},
{"testdata/ink_big_photo.jpg", datastore.NewKey(""), "file size too large. max size is 250kb"},
{"testdata/q_bang.svg", datastore.NewKey(""), "invalid file format. only .jpg & .png images allowed"},
{"testdata/rico_poster_1500x500.jpg", datastore.NewKey("/map/QmdJgfxj4rocm88PLeEididS7V2cc9nQosA46RpvAnWvDL"), ""},
}

Expand All @@ -130,7 +130,7 @@ func TestProfileRequestsSetPosterPhoto(t *testing.T) {
return
}

req := NewProfileRequests(mr)
req := NewProfileRequests(mr, nil)
for i, c := range cases {
p := &FileParams{}
if c.infile != "" {
Expand All @@ -143,15 +143,15 @@ func TestProfileRequestsSetPosterPhoto(t *testing.T) {
p.Data = r
}

res := &profile.Profile{}
res := &Profile{}
err := req.SetProfilePhoto(p, res)
if !(err == nil && c.err == "" || err != nil && err.Error() == c.err) {
t.Errorf("case %d error mismatch. expected: %s, got: %s", i, c.err, err.Error())
continue
}

if !c.respath.Equal(res.Profile) {
t.Errorf("case %d profile hash mismatch. expected: %s, got: %s", i, c.respath.String(), res.Profile.String())
if !c.respath.Equal(datastore.NewKey(res.Profile)) {
t.Errorf("case %d profile hash mismatch. expected: %s, got: %s", i, c.respath.String(), res.Profile)
continue
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (r *QueryRequests) Run(p *RunParams, res *repo.DatasetRef) error {
if err != nil {
return fmt.Errorf("formatting error: %s", err.Error())
}
qpath, err := dsfs.SaveTransform(store, abst, false)
qpath, err := dsfs.SaveAbstractTransform(store, abst, false)
if err != nil {
return fmt.Errorf("error calculating query hash: %s", err.Error())
}
Expand Down
Loading

0 comments on commit f3dea07

Please sign in to comment.