Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
b1390a7b
Unverified
Commit
b1390a7b
authored
Apr 26, 2024
by
Blake Mizerany
Committed by
GitHub
Apr 26, 2024
Browse files
types/model: export ParseNameBare and Merge (#3957)
These are useful outside this package.
parent
11d83386
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
types/model/name.go
types/model/name.go
+6
-5
types/model/name_test.go
types/model/name_test.go
+4
-4
No files found.
types/model/name.go
View file @
b1390a7b
...
...
@@ -132,11 +132,12 @@ type Name struct {
// field values are left in an undefined state. Use [Name.IsValid] to check
// if the name is valid.
func
ParseName
(
s
string
)
Name
{
return
m
erge
(
p
arseName
(
s
),
DefaultName
())
return
M
erge
(
P
arseName
Bare
(
s
),
DefaultName
())
}
// parseName is the same as [ParseName] without a merge.
func
parseName
(
s
string
)
Name
{
// ParseNameBare parses s as a name string and returns a Name. No merge with
// [DefaultName] is performed.
func
ParseNameBare
(
s
string
)
Name
{
var
n
Name
var
promised
bool
...
...
@@ -161,9 +162,9 @@ func parseName(s string) Name {
return
n
}
//
m
erge merges the host, namespace, and tag parts of the two names,
//
M
erge merges the host, namespace, and tag parts of the two names,
// preferring the non-empty parts of a.
func
m
erge
(
a
,
b
Name
)
Name
{
func
M
erge
(
a
,
b
Name
)
Name
{
a
.
Host
=
cmp
.
Or
(
a
.
Host
,
b
.
Host
)
a
.
Namespace
=
cmp
.
Or
(
a
.
Namespace
,
b
.
Namespace
)
a
.
Tag
=
cmp
.
Or
(
a
.
Tag
,
b
.
Tag
)
...
...
types/model/name_test.go
View file @
b1390a7b
...
...
@@ -93,7 +93,7 @@ func TestParseNameParts(t *testing.T) {
for
_
,
tt
:=
range
cases
{
t
.
Run
(
tt
.
in
,
func
(
t
*
testing
.
T
)
{
got
:=
p
arseName
(
tt
.
in
)
got
:=
P
arseName
Bare
(
tt
.
in
)
if
!
reflect
.
DeepEqual
(
got
,
tt
.
want
)
{
t
.
Errorf
(
"parseName(%q) = %v; want %v"
,
tt
.
in
,
got
,
tt
.
want
)
}
...
...
@@ -166,7 +166,7 @@ func TestNameparseNameDefault(t *testing.T) {
func
TestNameIsValid
(
t
*
testing
.
T
)
{
var
numStringTests
int
for
s
,
want
:=
range
testCases
{
n
:=
p
arseName
(
s
)
n
:=
P
arseName
Bare
(
s
)
t
.
Logf
(
"n: %#v"
,
n
)
got
:=
n
.
IsValid
()
if
got
!=
want
{
...
...
@@ -175,7 +175,7 @@ func TestNameIsValid(t *testing.T) {
// Test roundtrip with String
if
got
{
got
:=
p
arseName
(
s
)
.
String
()
got
:=
P
arseName
Bare
(
s
)
.
String
()
if
got
!=
s
{
t
.
Errorf
(
"parseName(%q).String() = %q; want %q"
,
s
,
got
,
s
)
}
...
...
@@ -221,7 +221,7 @@ func FuzzName(f *testing.F) {
f
.
Add
(
s
)
}
f
.
Fuzz
(
func
(
t
*
testing
.
T
,
s
string
)
{
n
:=
p
arseName
(
s
)
n
:=
P
arseName
Bare
(
s
)
if
n
.
IsValid
()
{
parts
:=
[
...
]
string
{
n
.
Host
,
n
.
Namespace
,
n
.
Model
,
n
.
Tag
,
n
.
RawDigest
}
for
_
,
part
:=
range
parts
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment