make the modelfile path relative for ollama create (#8380)

This commit is contained in:
Patrick Devine
2025-01-10 16:14:08 -08:00
committed by GitHub
parent 9446c2c902
commit 32bd37adf8
5 changed files with 155 additions and 25 deletions

View File

@@ -31,27 +31,29 @@ func TestExpandPath(t *testing.T) {
}
tests := []struct {
input string
path string
relativeDir string
expected string
windowsExpected string
shouldErr bool
}{
{"~", "/home/testuser", "D:\\home\\testuser", false},
{"~/myfolder/myfile.txt", "/home/testuser/myfolder/myfile.txt", "D:\\home\\testuser\\myfolder\\myfile.txt", false},
{"~anotheruser/docs/file.txt", "/home/anotheruser/docs/file.txt", "D:\\home\\anotheruser\\docs\\file.txt", false},
{"~nonexistentuser/file.txt", "", "", true},
{"relative/path/to/file", filepath.Join(os.Getenv("PWD"), "relative/path/to/file"), "relative\\path\\to\\file", false},
{"/absolute/path/to/file", "/absolute/path/to/file", "D:\\absolute\\path\\to\\file", false},
{".", os.Getenv("PWD"), os.Getenv("PWD"), false},
{"~", "", "/home/testuser", "D:\\home\\testuser", false},
{"~/myfolder/myfile.txt", "", "/home/testuser/myfolder/myfile.txt", "D:\\home\\testuser\\myfolder\\myfile.txt", false},
{"~anotheruser/docs/file.txt", "", "/home/anotheruser/docs/file.txt", "D:\\home\\anotheruser\\docs\\file.txt", false},
{"~nonexistentuser/file.txt", "", "", "", true},
{"relative/path/to/file", "", filepath.Join(os.Getenv("PWD"), "relative/path/to/file"), "relative\\path\\to\\file", false},
{"/absolute/path/to/file", "", "/absolute/path/to/file", "D:\\absolute\\path\\to\\file", false},
{".", os.Getenv("PWD"), "", os.Getenv("PWD"), false},
{"somefile", "somedir", filepath.Join(os.Getenv("PWD"), "somedir", "somefile"), "somedir\\somefile", false},
}
for _, test := range tests {
result, err := expandPathImpl(test.input, mockCurrentUser, mockLookupUser)
result, err := expandPathImpl(test.path, test.relativeDir, mockCurrentUser, mockLookupUser)
if (err != nil) != test.shouldErr {
t.Errorf("expandPathImpl(%q) returned error: %v, expected error: %v", test.input, err != nil, test.shouldErr)
t.Errorf("expandPathImpl(%q) returned error: %v, expected error: %v", test.path, err != nil, test.shouldErr)
}
if result != test.expected && result != test.windowsExpected && !test.shouldErr {
t.Errorf("expandPathImpl(%q) = %q, want %q", test.input, result, test.expected)
t.Errorf("expandPathImpl(%q) = %q, want %q", test.path, result, test.expected)
}
}
}