|
|
@ -3,9 +3,11 @@ package ctx
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"go/build"
|
|
|
|
"go/build"
|
|
|
|
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"path/filepath"
|
|
|
|
"reflect"
|
|
|
|
"reflect"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
@ -110,3 +112,90 @@ func Test_getRealModule(t *testing.T) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestDecodePackages(t *testing.T) {
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
|
|
|
name string
|
|
|
|
|
|
|
|
data io.Reader
|
|
|
|
|
|
|
|
want []Module
|
|
|
|
|
|
|
|
wantErr bool
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "single module",
|
|
|
|
|
|
|
|
data: strings.NewReader(`{
|
|
|
|
|
|
|
|
"Path":"foo",
|
|
|
|
|
|
|
|
"Dir":"/home/foo",
|
|
|
|
|
|
|
|
"GoMod":"/home/foo/go.mod",
|
|
|
|
|
|
|
|
"GoVersion":"go1.16"}`),
|
|
|
|
|
|
|
|
want: []Module{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Path: "foo",
|
|
|
|
|
|
|
|
Dir: "/home/foo",
|
|
|
|
|
|
|
|
GoMod: "/home/foo/go.mod",
|
|
|
|
|
|
|
|
GoVersion: "go1.16",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "go work multiple modules",
|
|
|
|
|
|
|
|
data: strings.NewReader(`
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"Path":"foo",
|
|
|
|
|
|
|
|
"Dir":"/home/foo",
|
|
|
|
|
|
|
|
"GoMod":"/home/foo/go.mod",
|
|
|
|
|
|
|
|
"GoVersion":"go1.18"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"Path":"bar",
|
|
|
|
|
|
|
|
"Dir":"/home/bar",
|
|
|
|
|
|
|
|
"GoMod":"/home/bar/go.mod",
|
|
|
|
|
|
|
|
"GoVersion":"go1.18"
|
|
|
|
|
|
|
|
}`),
|
|
|
|
|
|
|
|
want: []Module{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Path: "foo",
|
|
|
|
|
|
|
|
Dir: "/home/foo",
|
|
|
|
|
|
|
|
GoMod: "/home/foo/go.mod",
|
|
|
|
|
|
|
|
GoVersion: "go1.18",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Path: "bar",
|
|
|
|
|
|
|
|
Dir: "/home/bar",
|
|
|
|
|
|
|
|
GoMod: "/home/bar/go.mod",
|
|
|
|
|
|
|
|
GoVersion: "go1.18",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "There are extra characters at the beginning",
|
|
|
|
|
|
|
|
data: strings.NewReader(`Active code page: 65001
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"Path":"foo",
|
|
|
|
|
|
|
|
"Dir":"/home/foo",
|
|
|
|
|
|
|
|
"GoMod":"/home/foo/go.mod",
|
|
|
|
|
|
|
|
"GoVersion":"go1.18"
|
|
|
|
|
|
|
|
}`),
|
|
|
|
|
|
|
|
want: []Module{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Path: "foo",
|
|
|
|
|
|
|
|
Dir: "/home/foo",
|
|
|
|
|
|
|
|
GoMod: "/home/foo/go.mod",
|
|
|
|
|
|
|
|
GoVersion: "go1.18",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
|
|
|
result, err := decodePackages(tt.data)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Errorf("decodePackages() error %v,wantErr = %v", err, tt.wantErr)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(result, tt.want) {
|
|
|
|
|
|
|
|
t.Errorf("decodePackages() = %v,want %v", result, tt.want)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|