package profile import ( "context" "errors" "os" "path/filepath" "testing" ) func TestFilesystemRepository_GetProfile(t *testing.T) { tmpDir, err := os.MkdirTemp("", "profile_test") if err != nil { t.Fatal(err) } defer os.RemoveAll(tmpDir) testDataDir := "testdata" files, err := os.ReadDir(testDataDir) if err != nil { t.Fatalf("failed to read testdata: %v", err) } for _, f := range files { src := filepath.Join(testDataDir, f.Name()) dst := filepath.Join(tmpDir, f.Name()) data, err := os.ReadFile(src) if err != nil { t.Fatal(err) } if err := os.WriteFile(dst, data, 0644); err != nil { t.Fatal(err) } } repo := NewFilesystemRepository(tmpDir) ctx := context.Background() t.Run("valid profile", func(t *testing.T) { p, err := repo.GetProfile(ctx, "test-profile", "") if err != nil { t.Fatalf("expected no error, got %v", err) } if p == nil || p.ID != "test-profile" { t.Errorf("expected profile test-profile, got %v", p) } }) t.Run("invalid YAML", func(t *testing.T) { _, err := repo.GetProfile(ctx, "invalid_yaml", "") if !errors.Is(err, ErrInvalidYAML) { t.Errorf("expected ErrInvalidYAML, got %v", err) } }) t.Run("missing ID", func(t *testing.T) { _, err := repo.GetProfile(ctx, "missing-id", "") if !errors.Is(err, ErrProfileNotFound) { t.Errorf("expected ErrProfileNotFound for profile with missing ID, got %v", err) } }) t.Run("no templates", func(t *testing.T) { _, err := repo.GetProfile(ctx, "no-templates", "") if !errors.Is(err, ErrInvalidProfile) { t.Errorf("expected ErrInvalidProfile for profile with no templates, got %v", err) } }) t.Run("profile not found", func(t *testing.T) { _, err := repo.GetProfile(ctx, "unknown", "") if !errors.Is(err, ErrProfileNotFound) { t.Errorf("expected ErrProfileNotFound, got %v", err) } }) }