72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package profile
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadRealProfile(t *testing.T) {
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
t.Skip("no home")
|
|
}
|
|
path := filepath.Join(home, ".apex", "config", "profile.yml")
|
|
if _, err := os.Stat(path); err != nil {
|
|
t.Skip("no real profile: " + err.Error())
|
|
}
|
|
p, err := Load(path)
|
|
if err != nil {
|
|
t.Fatalf("Load: %v", err)
|
|
}
|
|
out := p.Render()
|
|
if out == "" {
|
|
t.Fatal("Render returned empty for populated profile")
|
|
}
|
|
if len(out) > 8*1024 {
|
|
t.Errorf("Render output too large: %d bytes", len(out))
|
|
}
|
|
if strings.Contains(out, "<nil>") || strings.Contains(out, "null") {
|
|
t.Errorf("Render leaked null placeholder")
|
|
}
|
|
}
|
|
|
|
func TestRenderEmptyProfileSkipsHeadings(t *testing.T) {
|
|
p := &Profile{}
|
|
out := p.Render()
|
|
for _, hdr := range []string{"**Compensation:**", "**Deal-Breakers**", "**Target Archetypes**"} {
|
|
if strings.Contains(out, hdr) {
|
|
t.Errorf("empty profile leaked %q", hdr)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRenderPopulated(t *testing.T) {
|
|
p := &Profile{}
|
|
p.Candidate.FullName = "Test User"
|
|
p.Compensation.Minimum = "$165K"
|
|
p.DealBreakers = []string{"Small or unstable startups", ""}
|
|
p.DreamCompanies = []string{"Deloitte", ""}
|
|
p.TargetRoles.Archetypes = []struct {
|
|
Name string `yaml:"name"`
|
|
Level string `yaml:"level"`
|
|
Fit string `yaml:"fit"`
|
|
}{{Name: "Red Team Operator", Level: "Senior", Fit: "primary"}}
|
|
out := p.Render()
|
|
for _, want := range []string{"Test User", "Hard floor:** $165K", "Small or unstable startups", "Deloitte", "Red Team Operator (Senior)"} {
|
|
if !strings.Contains(out, want) {
|
|
t.Errorf("missing %q in:\n%s", want, out)
|
|
}
|
|
}
|
|
if strings.Contains(out, "- \n") {
|
|
t.Errorf("empty list item leaked:\n%s", out)
|
|
}
|
|
}
|
|
|
|
func TestLoadMissingFile(t *testing.T) {
|
|
if _, err := Load("/tmp/definitely/does/not/exist.yml"); err == nil {
|
|
t.Fatal("expected error for missing file")
|
|
}
|
|
}
|