mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
- TestParseOpts_ProjectMode_NoFallbackToGlobal: server project mode returns empty hosts when project has none, never falls back to global - TestParseOpts_ProjectMode_MergesEnvVar: env var merges with project config, not global - TestLoadProject_GitLabHosts_EffectiveGitLabHosts: project config EffectiveGitLabHosts() merges env var while GitLabHosts stays config-file-only
65 lines
1.8 KiB
Go
65 lines
1.8 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])
|
|
}
|
|
}
|