-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #491 from zong-zhe/split-client-resolver
refactor: split resolver from client
- Loading branch information
Showing
12 changed files
with
124 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package resolver | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"sort" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"kcl-lang.io/kpm/pkg/downloader" | ||
"kcl-lang.io/kpm/pkg/env" | ||
pkg "kcl-lang.io/kpm/pkg/package" | ||
"kcl-lang.io/kpm/pkg/settings" | ||
) | ||
|
||
const testDataDir = "test_data" | ||
|
||
func getTestDir(subDir string) string { | ||
pwd, _ := os.Getwd() | ||
testDir := filepath.Join(pwd, testDataDir) | ||
testDir = filepath.Join(testDir, subDir) | ||
|
||
return testDir | ||
} | ||
|
||
func TestResolver(t *testing.T) { | ||
resolve_path := getTestDir("test_resolve_graph") | ||
pkgPath := filepath.Join(resolve_path, "pkg") | ||
defaultCachePath, err := env.GetAbsPkgPath() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
var res []string | ||
var buf bytes.Buffer | ||
|
||
resolver := DepsResolver{ | ||
Downloader: &downloader.DepDownloader{}, | ||
Settings: settings.GetSettings(), | ||
LogWriter: &buf, | ||
DefaultCachePath: defaultCachePath, | ||
ResolveFuncs: []resolveFunc{func(dep *pkg.Dependency, parentPkg *pkg.KclPkg) error { | ||
res = append(res, fmt.Sprintf("%s -> %s", parentPkg.GetPkgName(), dep.Name)) | ||
return nil | ||
}}, | ||
} | ||
|
||
err = resolver.Resolve( | ||
WithEnableCache(true), | ||
WithSourceUrl(pkgPath), | ||
) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
expected := []string{ | ||
"dep1 -> helloworld", | ||
"pkg -> dep1", | ||
"pkg -> helloworld", | ||
} | ||
|
||
sort.Strings(res) | ||
assert.Equal(t, len(res), 3) | ||
assert.Equal(t, res, expected) | ||
assert.Equal(t, buf.String(), "") | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.