Files
pmg/config/config_template_test.go
T
Abhisek DattaGitHubdevin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
e67735c1c3 feat: Add cloud sync event emit (#212)
* feat: Add cloud sync event emit

* fix: Linter fixes

* fix: Include malysis metadata in confirmed event

* fix: Code review fixes

* fix: Emit session complet event

* fix: Code review fixes

* chore: Add comment

* chore: Add cloud info in setup info command

* fix: Proxy flow must call install started

* fix: Code review fixes

* fix: Code review fixes

* Update internal/audit/cloud_sink.go

Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Signed-off-by: Abhisek Datta <abhisek.datta@gmail.com>

* fix: Code review fixes

---------

Signed-off-by: Abhisek Datta <abhisek.datta@gmail.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-04-11 12:33:27 +05:30

70 lines
2.8 KiB
Go

package config
import (
"strings"
"testing"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
func TestTemplateParsesAsYAML(t *testing.T) {
var cfg Config
// Defensive check: Ensure template is valid YAML (not used for mapstructure mapping)
var raw map[string]any
err := yaml.Unmarshal([]byte(templateConfig), &raw)
assert.NoError(t, err, "templateConfig must be valid YAML")
// Ensure Viper (mapstructure) maps to Config as expected
v := viper.New()
v.SetConfigType("yaml")
err = v.ReadConfig(strings.NewReader(templateConfig))
assert.NoError(t, err, "expected no error while reading config")
err = v.Unmarshal(&cfg)
assert.NoError(t, err, "expected no error while unmarshalling config")
assert.True(t, true, cfg.Transitive, "expected Transitive true")
assert.Equal(t, 5, cfg.TransitiveDepth, "expected TransitiveDepth 5")
assert.False(t, false, cfg.IncludeDevDependencies, "expected IncludeDevDependencies false")
assert.False(t, false, cfg.Paranoid, "expected Paranoid false")
assert.False(t, false, cfg.SkipEventLogging, "expected SkipEventLogging false")
assert.Equal(t, 7, cfg.EventLogRetentionDays, "expected EventLogRetentionDays 7")
assert.Len(t, cfg.TrustedPackages, 1)
}
func TestTemplateMatchesDefaults(t *testing.T) {
var parsed Config
v := viper.New()
v.SetConfigType("yaml")
err := v.ReadConfig(strings.NewReader(templateConfig))
assert.NoError(t, err, "expected no error while reading config")
err = v.Unmarshal(&parsed)
assert.NoError(t, err, "expected no error while unmarshalling config")
def := DefaultConfig().Config
assert.Equal(t, def.Transitive, parsed.Transitive, "transitive mismatch")
assert.Equal(t, def.TransitiveDepth, parsed.TransitiveDepth, "transitive_depth mismatch")
assert.Equal(t, def.IncludeDevDependencies, parsed.IncludeDevDependencies, "include_dev_dependencies mismatch")
assert.Equal(t, def.Paranoid, parsed.Paranoid, "paranoid mismatch")
assert.Equal(t, def.SkipEventLogging, parsed.SkipEventLogging, "skip_event_logging mismatch")
assert.Equal(t, def.EventLogRetentionDays, parsed.EventLogRetentionDays, "event_log_retention_days mismatch")
assert.Equal(t, def.Verbosity, parsed.Verbosity, "verbosity mismatch")
assert.NotEmpty(t, parsed.TrustedPackages, "expected at least one trusted_packages entry")
first := parsed.TrustedPackages[0]
assert.NotEmpty(t, first.Purl, "first trusted package has empty purl")
assert.NotEmpty(t, first.Reason, "first trusted package has empty reason")
assert.Equal(t, def.DependencyCooldown.Enabled, parsed.DependencyCooldown.Enabled, "dependency_cooldown.enabled mismatch")
assert.Equal(t, def.DependencyCooldown.Days, parsed.DependencyCooldown.Days, "dependency_cooldown.days mismatch")
assert.Equal(t, def.Cloud.Enabled, parsed.Cloud.Enabled, "cloud.enabled mismatch")
}