From 2e4da8eec2d19d671df5f58c81dfdfa35de8679c Mon Sep 17 00:00:00 2001 From: Josh Yan Date: Fri, 31 May 2024 11:48:07 -0700 Subject: [PATCH] added tests for IsValidNamespace --- types/model/name_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/types/model/name_test.go b/types/model/name_test.go index 27a8ccf8..26d70ef3 100644 --- a/types/model/name_test.go +++ b/types/model/name_test.go @@ -385,3 +385,30 @@ func FuzzName(f *testing.F) { }) } + +func TestIsValidNamespace(t *testing.T) { + cases := []struct { + username string + expected bool + }{ + {"", false}, + {"a", true}, + {"a:b", false}, + {"a/b", false}, + {"a:b/c", false}, + {"a/b:c", false}, + {"a/b:c", false}, + {"a/b:c/d", false}, + {"a/b:c/d@e", false}, + {"a/b:c/d@sha256-100", false}, + {"himynameisjoe", true}, + {"himynameisreallyreallyreallyreallylongbutitshouldstillbevalid", true}, + } + for _, tt := range cases { + t.Run(tt.username, func(t *testing.T) { + if got := IsValidNamespace(tt.username); got != tt.expected { + t.Errorf("IsValidName(%q) = %v; want %v", tt.username, got, tt.expected) + } + }) + } +}