feat: Phase 1 — config, auth, OAuth2 PKCE, CLI scaffold, token store

This commit is contained in:
GoCalGoo
2026-04-01 21:25:49 +02:00
parent 514372fa6b
commit 10db895ada
14 changed files with 977 additions and 29 deletions

View File

@@ -0,0 +1,73 @@
package config
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLoadDefaults(t *testing.T) {
cfg, err := Load("", "")
require.NoError(t, err)
assert.Equal(t, "GoCalGoo", cfg.App.Name)
assert.Equal(t, 53682, cfg.OAuth.DefaultPort)
assert.Equal(t, "primary", cfg.Google.DefaultCalendarID)
assert.Equal(t, 8080, cfg.Server.Port)
assert.NotEmpty(t, cfg.Google.Scopes)
}
func TestValidate(t *testing.T) {
tests := []struct {
name string
mutate func(*Config)
wantErr bool
}{
{
name: "valid config",
mutate: func(c *Config) {},
wantErr: false,
},
{
name: "missing credentials file",
mutate: func(c *Config) {
c.OAuth.ClientCredentialsFile = ""
},
wantErr: true,
},
{
name: "missing token store",
mutate: func(c *Config) {
c.OAuth.TokenStoreFile = ""
},
wantErr: true,
},
{
name: "empty scopes",
mutate: func(c *Config) {
c.Google.Scopes = nil
},
wantErr: true,
},
{
name: "invalid port",
mutate: func(c *Config) {
c.Server.Port = 0
},
wantErr: true,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cfg, err := Load("", "")
require.NoError(t, err)
tc.mutate(cfg)
err = Validate(cfg)
if tc.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}