Skip to content

Commit

Permalink
download: include goget tests + hacky hack
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan-at-work committed Jul 26, 2018
1 parent 5379fa0 commit 66b2be1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/download/goget/goget.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package goget

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand All @@ -10,12 +11,11 @@ import (
"strings"
"time"

"github.com/gomods/athens/pkg/module"

"github.com/gomods/athens/pkg/config"
"github.com/gomods/athens/pkg/config/env"
"github.com/gomods/athens/pkg/download"
"github.com/gomods/athens/pkg/errors"
"github.com/gomods/athens/pkg/module"
"github.com/gomods/athens/pkg/storage"
"github.com/spf13/afero"
)
Expand Down Expand Up @@ -48,7 +48,7 @@ func (gg *goget) List(ctx context.Context, mod string) ([]string, error) {
type listResp struct {
Path string
Version string
Versions []string
Versions []string `json:"omitempty"`
Time time.Time
}

Expand Down Expand Up @@ -131,6 +131,12 @@ func (gg *goget) list(op errors.Op, mod string) (*listResp, error) {
return nil, errors.E(op, errFmt)
}

// ugly hack until go cli implements -quiet flag.
// https://github.com/golang/go/issues/26628
if bytes.HasPrefix(bts, []byte("go: finding")) {
bts = bts[bytes.Index(bts, []byte{'\n'}):]
}

var lr listResp
err = json.Unmarshal(bts, &lr)
if err != nil {
Expand Down
37 changes: 37 additions & 0 deletions pkg/download/goget/goget_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package goget

import (
"context"
"testing"
)

type testCase struct {
name string
mod string
version string
}

// TODO(marwan): we should create Test Repos under github.com/gomods
// so we can get reproducible results from live VCS repos.
// For now, I cannot test that github.com/pkg/errors returns v0.8.0
// from goget.Latest, because they could very well introduce a new tag
// in the near future.
var tt = []testCase{
{"basic list", "github.com/pkg/errors", "latest"},
{"list non tagged", "github.com/marwan-at-work/gowatch", "latest"},
{"list vanity", "golang.org/x/tools", "latest"},
}

func TestList(t *testing.T) {
dp := New()
ctx := context.Background()

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
_, err := dp.List(ctx, tc.mod) // TODO ensure list is correct per TODO above.
if err != nil {
t.Fatal(err)
}
})
}
}

0 comments on commit 66b2be1

Please sign in to comment.