Browse Source

tests: add unit test for marketplace pattern

Yeuoly 8 months ago
parent
commit
95a6c8aa4d
1 changed files with 99 additions and 0 deletions
  1. 99 0
      internal/types/entities/bundle_entities/dependency_test.go

+ 99 - 0
internal/types/entities/bundle_entities/dependency_test.go

@@ -145,3 +145,102 @@ func TestGithubDependencyPatternRegex(t *testing.T) {
 		})
 	}
 }
+
+func TestMarketplacePattern(t *testing.T) {
+	testCases := []struct {
+		name     string
+		input    string
+		expected bool
+	}{
+		{
+			name:     "valid pattern with exact version",
+			input:    "owner/plugin:1.0.0",
+			expected: true,
+		},
+		{
+			name:     "valid pattern with caret version",
+			input:    "owner/plugin:^1.0.0",
+			expected: true,
+		},
+		{
+			name:     "valid pattern with tilde version",
+			input:    "owner/plugin:~1.0.0",
+			expected: true,
+		},
+		{
+			name:     "valid pattern with x version",
+			input:    "owner/plugin:1.x.x",
+			expected: true,
+		},
+		{
+			name:     "valid pattern with version range",
+			input:    "owner/plugin:1.0.0-2.0.0",
+			expected: true,
+		},
+		{
+			name:     "valid pattern with pre-release",
+			input:    "owner/plugin:1.0.0-beta",
+			expected: true,
+		},
+		{
+			name:     "invalid pattern without version",
+			input:    "owner/plugin",
+			expected: false,
+		},
+		{
+			name:     "invalid pattern with empty version",
+			input:    "owner/plugin:",
+			expected: false,
+		},
+		{
+			name:     "uppercase in owner",
+			input:    "Owner/plugin:1.0.0",
+			expected: false,
+		},
+		{
+			name:     "uppercase in plugin",
+			input:    "owner/Plugin:1.0.0",
+			expected: false,
+		},
+		{
+			name:     "invalid characters in owner",
+			input:    "owner@/plugin:1.0.0",
+			expected: false,
+		},
+		{
+			name:     "invalid characters in plugin",
+			input:    "owner/plugin#:1.0.0",
+			expected: false,
+		},
+		{
+			name:     "too long owner name",
+			input:    "ownerwithaverylongnamethatshouldnotbeallowedinthiscaseownerwithaverylongnamethatshouldnotbeallowedinthiscase/plugin:1.0.0",
+			expected: false,
+		},
+		{
+			name:     "too long plugin name",
+			input:    "owner/pluginwithaverylongnamethatshouldnotbeallowedinthiscaseandshouldbeshorterthanspecifiedintherequirementspluginwithaverylongnamethatshouldnotbeallowedinthiscaseandshouldbeshorterthanspecifiedintherequirementspluginwithaverylongnamethatshouldnotbeallowedinthiscaseandshouldbeshorterthanspecifiedintherequirements:1.0.0",
+			expected: false,
+		},
+		{
+			name:     "invalid version range format",
+			input:    "owner/plugin:1.0.0-",
+			expected: false,
+		},
+		{
+			name:     "invalid pre-release format",
+			input:    "owner/plugin:1.0.0-toolongprerelease",
+			expected: false,
+		},
+	}
+
+	for _, testCase := range testCases {
+		t.Run(testCase.name, func(t *testing.T) {
+			result := MARKETPLACE_PATTERN_REGEX_COMPILED.MatchString(testCase.input)
+			if result != testCase.expected {
+				t.Errorf("Test case '%s' failed: input '%s' expected %v but got %v, pattern: %s",
+					testCase.name, testCase.input, testCase.expected, result, MARKETPLACE_PATTERN_REGEX_COMPILED.String())
+			}
+		})
+	}
+}