Ver Fonte

x/model: add CompleteNoBuild

Blake Mizerany há 1 ano atrás
pai
commit
6e464ebef8
2 ficheiros alterados com 13 adições e 4 exclusões
  1. 6 0
      x/model/name.go
  2. 7 4
      x/model/name_test.go

+ 6 - 0
x/model/name.go

@@ -286,6 +286,12 @@ func (r Name) Complete() bool {
 	return !slices.Contains(r.Parts(), "")
 }
 
+// CompleteNoBuild reports whether the Name is fully qualified without the
+// build part.
+func (r Name) CompleteNoBuild() bool {
+	return !slices.Contains(r.Parts()[:4], "")
+}
+
 // EqualFold reports whether r and o are equivalent model names, ignoring
 // case.
 func (r Name) EqualFold(o Name) bool {

+ 7 - 4
x/model/name_test.go

@@ -138,11 +138,11 @@ func TestParseName(t *testing.T) {
 	}
 }
 
-func TestComplete(t *testing.T) {
+func TestCompleteWithAndWithoutBuild(t *testing.T) {
 	cases := []struct {
-		in                   string
-		complete             bool
-		completeWithoutBuild bool
+		in              string
+		complete        bool
+		completeNoBuild bool
 	}{
 		{"", false, false},
 		{"incomplete/mistral:7b+x", false, false},
@@ -159,6 +159,9 @@ func TestComplete(t *testing.T) {
 			if g := p.Complete(); g != tt.complete {
 				t.Errorf("Complete(%q) = %v; want %v", tt.in, g, tt.complete)
 			}
+			if g := p.CompleteNoBuild(); g != tt.completeNoBuild {
+				t.Errorf("CompleteNoBuild(%q) = %v; want %v", tt.in, g, tt.completeNoBuild)
+			}
 		})
 	}