Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/thv-operator/pkg/registryapi/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,13 @@ func buildGitSourceConfig(git *mcpv1alpha1.GitSource) (*GitConfig, error) {
return nil, fmt.Errorf("git repository is required")
}

if git.Path == "" {
return nil, fmt.Errorf("git path is required")
}

serverGitConfig := GitConfig{
Repository: git.Repository,
Path: git.Path,
}

switch {
Expand Down
34 changes: 34 additions & 0 deletions cmd/thv-operator/pkg/registryapi/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func TestBuildConfig_GitSource(t *testing.T) {
Format: mcpv1alpha1.RegistryFormatToolHive,
Git: &mcpv1alpha1.GitSource{
Repository: "https://github.com/example/repo.git",
Path: "registry.json",
// No branch, tag, or commit specified - should cause an error
},
},
Expand All @@ -292,6 +293,33 @@ func TestBuildConfig_GitSource(t *testing.T) {
assert.Nil(t, config)
})

t.Run("no git path specified", func(t *testing.T) {
t.Parallel()
mcpRegistry := &mcpv1alpha1.MCPRegistry{
ObjectMeta: metav1.ObjectMeta{
Name: "test-registry",
},
Spec: mcpv1alpha1.MCPRegistrySpec{
Registries: []mcpv1alpha1.MCPRegistryConfig{
{
Name: "default",
Format: mcpv1alpha1.RegistryFormatToolHive,
Git: &mcpv1alpha1.GitSource{
Repository: "https://github.com/example/repo.git",
},
},
},
},
}

manager := NewConfigManagerForTesting(mcpRegistry)
config, err := manager.BuildConfig()

require.Error(t, err)
assert.Contains(t, err.Error(), "path is required")
assert.Nil(t, config)
})

t.Run("valid git source with branch", func(t *testing.T) {
t.Parallel()
mcpRegistry := &mcpv1alpha1.MCPRegistry{
Expand All @@ -306,6 +334,7 @@ func TestBuildConfig_GitSource(t *testing.T) {
Git: &mcpv1alpha1.GitSource{
Repository: "https://github.com/example/repo.git",
Branch: "main",
Path: "registry.json",
},
SyncPolicy: &mcpv1alpha1.SyncPolicy{
Interval: "1h",
Expand Down Expand Up @@ -347,6 +376,7 @@ func TestBuildConfig_GitSource(t *testing.T) {
Git: &mcpv1alpha1.GitSource{
Repository: "git@github.com:example/repo.git",
Tag: "v1.2.3",
Path: "registry.json",
},
SyncPolicy: &mcpv1alpha1.SyncPolicy{
Interval: "1h",
Expand Down Expand Up @@ -388,6 +418,7 @@ func TestBuildConfig_GitSource(t *testing.T) {
Git: &mcpv1alpha1.GitSource{
Repository: "https://github.com/example/repo.git",
Commit: "abc123def456",
Path: "registry.json",
},
SyncPolicy: &mcpv1alpha1.SyncPolicy{
Interval: "1h",
Expand Down Expand Up @@ -722,6 +753,7 @@ func TestBuildConfig_Filter(t *testing.T) {
Git: &mcpv1alpha1.GitSource{
Repository: "https://github.com/example/repo.git",
Branch: "main",
Path: "registry.json",
},
SyncPolicy: &mcpv1alpha1.SyncPolicy{
Interval: "30m",
Expand Down Expand Up @@ -866,6 +898,7 @@ func TestToConfigMapWithContentChecksum(t *testing.T) {
Git: &GitConfig{
Repository: "https://github.com/example/mcp-servers.git",
Branch: "main",
Path: "registry.json",
},
SyncPolicy: &SyncPolicyConfig{
Interval: "15m",
Expand Down Expand Up @@ -960,6 +993,7 @@ func TestBuildConfig_MultipleRegistries(t *testing.T) {
Git: &mcpv1alpha1.GitSource{
Repository: "https://github.com/example/repo.git",
Branch: "main",
Path: "registry.json",
},
SyncPolicy: &mcpv1alpha1.SyncPolicy{
Interval: "30m",
Expand Down
Loading