Files
github--github-mcp-server/pkg/github/instructions_test.go
JoannaaKL 6793b9d376
Build and Test Go Project / build (macos-latest) (push) Has been cancelled
Build and Test Go Project / build (ubuntu-latest) (push) Has been cancelled
Build and Test Go Project / build (windows-latest) (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
Docker / build (push) Has been cancelled
GoReleaser Release / release (push) Has been cancelled
License Check / license-check (push) Has been cancelled
Publish to MCP Registry / publish (push) Has been cancelled
Add tools to add, update and delete project items (#1152)
* Add add_project_item tool

* Add tools to update and delete project items

* Update pkg/github/projects.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update pkg/github/projects.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Add tests

* Lint the code

* Fix req params

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-30 10:08:15 +02:00

167 lines
3.7 KiB
Go

package github
import (
"os"
"testing"
)
func TestGenerateInstructions(t *testing.T) {
tests := []struct {
name string
enabledToolsets []string
expectedEmpty bool
}{
{
name: "empty toolsets",
enabledToolsets: []string{},
expectedEmpty: false,
},
{
name: "only context toolset",
enabledToolsets: []string{"context"},
expectedEmpty: false,
},
{
name: "pull requests toolset",
enabledToolsets: []string{"pull_requests"},
expectedEmpty: false,
},
{
name: "issues toolset",
enabledToolsets: []string{"issues"},
expectedEmpty: false,
},
{
name: "discussions toolset",
enabledToolsets: []string{"discussions"},
expectedEmpty: false,
},
{
name: "multiple toolsets (context + pull_requests)",
enabledToolsets: []string{"context", "pull_requests"},
expectedEmpty: false,
},
{
name: "multiple toolsets (issues + pull_requests)",
enabledToolsets: []string{"issues", "pull_requests"},
expectedEmpty: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := GenerateInstructions(tt.enabledToolsets)
if tt.expectedEmpty {
if result != "" {
t.Errorf("Expected empty instructions but got: %s", result)
}
} else {
if result == "" {
t.Errorf("Expected non-empty instructions but got empty result")
}
}
})
}
}
func TestGenerateInstructionsWithDisableFlag(t *testing.T) {
tests := []struct {
name string
disableEnvValue string
enabledToolsets []string
expectedEmpty bool
}{
{
name: "DISABLE_INSTRUCTIONS=true returns empty",
disableEnvValue: "true",
enabledToolsets: []string{"context", "issues", "pull_requests"},
expectedEmpty: true,
},
{
name: "DISABLE_INSTRUCTIONS=false returns normal instructions",
disableEnvValue: "false",
enabledToolsets: []string{"context"},
expectedEmpty: false,
},
{
name: "DISABLE_INSTRUCTIONS unset returns normal instructions",
disableEnvValue: "",
enabledToolsets: []string{"issues"},
expectedEmpty: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Save original env value
originalValue := os.Getenv("DISABLE_INSTRUCTIONS")
defer func() {
if originalValue == "" {
os.Unsetenv("DISABLE_INSTRUCTIONS")
} else {
os.Setenv("DISABLE_INSTRUCTIONS", originalValue)
}
}()
// Set test env value
if tt.disableEnvValue == "" {
os.Unsetenv("DISABLE_INSTRUCTIONS")
} else {
os.Setenv("DISABLE_INSTRUCTIONS", tt.disableEnvValue)
}
result := GenerateInstructions(tt.enabledToolsets)
if tt.expectedEmpty {
if result != "" {
t.Errorf("Expected empty instructions but got: %s", result)
}
} else {
if result == "" {
t.Errorf("Expected non-empty instructions but got empty result")
}
}
})
}
}
func TestGetToolsetInstructions(t *testing.T) {
tests := []struct {
toolset string
expectedEmpty bool
}{
{
toolset: "pull_requests",
expectedEmpty: false,
},
{
toolset: "issues",
expectedEmpty: false,
},
{
toolset: "discussions",
expectedEmpty: false,
},
{
toolset: "nonexistent",
expectedEmpty: true,
},
}
for _, tt := range tests {
t.Run(tt.toolset, func(t *testing.T) {
result := getToolsetInstructions(tt.toolset)
if tt.expectedEmpty {
if result != "" {
t.Errorf("Expected empty result for toolset '%s', but got: %s", tt.toolset, result)
}
} else {
if result == "" {
t.Errorf("Expected non-empty result for toolset '%s', but got empty", tt.toolset)
}
}
})
}
}