mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
Add azure_hosts config parameter (analogous to gitlab_hosts) that allows users to register self-hosted Azure DevOps Server hostnames so they receive proper URL parsing without appending .git to clone URLs. - Add AzureHosts field to Config and ProjectConfig structs - Add SKILLSHARE_AZURE_HOSTS env var support with merge semantics - Generalize hostname validation into shared normalizeHostList/mergeHostsFromEnv - Add azureOnPremPattern regex and parseAzureOnPrem for /_git/ URL routing - Add isAzureHost for config-based host detection (no auto-detect) - Update TrackName to handle on-prem Azure DevOps clone URLs - Wire AzureHosts through InstallContext, ParseOptions, and Server - Add JSON Schema, UI fieldDocs, and website documentation - Add 19 new tests covering config, source parsing, and server Closes #147
88 lines
2.5 KiB
Go
88 lines
2.5 KiB
Go
package server
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"skillshare/internal/config"
|
|
)
|
|
|
|
func TestParseOpts_GlobalMode(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
s.cfg.GitLabHosts = []string{"global.host"}
|
|
|
|
opts := s.parseOpts()
|
|
if len(opts.GitLabHosts) != 1 || opts.GitLabHosts[0] != "global.host" {
|
|
t.Errorf("global mode: expected [global.host], got %v", opts.GitLabHosts)
|
|
}
|
|
}
|
|
|
|
func TestParseOpts_ProjectMode_UsesProjectConfig(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
s.cfg.GitLabHosts = []string{"global.host"}
|
|
s.projectRoot = t.TempDir()
|
|
s.projectCfg = &config.ProjectConfig{
|
|
GitLabHosts: []string{"project.host"},
|
|
}
|
|
|
|
opts := s.parseOpts()
|
|
if len(opts.GitLabHosts) != 1 || opts.GitLabHosts[0] != "project.host" {
|
|
t.Errorf("project mode: expected [project.host], got %v", opts.GitLabHosts)
|
|
}
|
|
}
|
|
|
|
func TestParseOpts_ProjectMode_NoFallbackToGlobal(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
s.cfg.GitLabHosts = []string{"global.host"}
|
|
s.projectRoot = t.TempDir()
|
|
s.projectCfg = &config.ProjectConfig{} // no gitlab_hosts
|
|
|
|
opts := s.parseOpts()
|
|
if len(opts.GitLabHosts) != 0 {
|
|
t.Errorf("project mode with no hosts should not fall back to global, got %v", opts.GitLabHosts)
|
|
}
|
|
}
|
|
|
|
func TestParseOpts_ProjectMode_MergesEnvVar(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
s.projectRoot = t.TempDir()
|
|
s.projectCfg = &config.ProjectConfig{
|
|
GitLabHosts: []string{"project.host"},
|
|
}
|
|
|
|
t.Setenv("SKILLSHARE_GITLAB_HOSTS", "env.host")
|
|
|
|
opts := s.parseOpts()
|
|
if len(opts.GitLabHosts) != 2 {
|
|
t.Fatalf("expected 2 hosts (project + env), got %d: %v", len(opts.GitLabHosts), opts.GitLabHosts)
|
|
}
|
|
if opts.GitLabHosts[0] != "project.host" {
|
|
t.Errorf("[0] = %s, want project.host", opts.GitLabHosts[0])
|
|
}
|
|
if opts.GitLabHosts[1] != "env.host" {
|
|
t.Errorf("[1] = %s, want env.host", opts.GitLabHosts[1])
|
|
}
|
|
}
|
|
|
|
func TestParseOpts_GlobalMode_AzureHosts(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
s.cfg.AzureHosts = []string{"azure.company.com"}
|
|
|
|
opts := s.parseOpts()
|
|
if len(opts.AzureHosts) != 1 || opts.AzureHosts[0] != "azure.company.com" {
|
|
t.Errorf("global mode: expected [azure.company.com], got %v", opts.AzureHosts)
|
|
}
|
|
}
|
|
|
|
func TestParseOpts_ProjectMode_AzureHosts(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
s.projectRoot = t.TempDir()
|
|
s.projectCfg = &config.ProjectConfig{
|
|
AzureHosts: []string{"azure.company.com"},
|
|
}
|
|
|
|
opts := s.parseOpts()
|
|
if len(opts.AzureHosts) != 1 || opts.AzureHosts[0] != "azure.company.com" {
|
|
t.Errorf("project mode: expected [azure.company.com], got %v", opts.AzureHosts)
|
|
}
|
|
}
|