11package config
22
33import (
4+ "encoding/json"
45 "os"
56 "path/filepath"
67 "strings"
@@ -13,14 +14,14 @@ func TestLoadValidConfig(t *testing.T) {
1314
1415 content := `{
1516 "s3": {
16- "bucket": "my-backups ",
17- "access_key": "AKIA1234 ",
18- "secret_key": "secret1234 ",
17+ "bucket": "real-bucket ",
18+ "access_key": "AKIAREAL1234 ",
19+ "secret_key": "realSecretKey1234 ",
1920 "region": "us-east-1"
2021 },
21- "restic_password": "testpass ",
22+ "restic_password": "real-strong-password ",
2223 "paths": ["C:\\Users\\Me\\Documents"],
23- "slack_webhook_url": "https://hooks.slack.com/services/T/B/X ",
24+ "slack_webhook_url": "https://hooks.slack.com/services/T123/B456/realwebhook ",
2425 "schedule_interval_hours": 4
2526 }`
2627
@@ -33,8 +34,8 @@ func TestLoadValidConfig(t *testing.T) {
3334 t .Fatalf ("unexpected error: %v" , err )
3435 }
3536
36- if cfg .S3 .Bucket != "my-backups " {
37- t .Errorf ("bucket = %q, want %q" , cfg .S3 .Bucket , "my-backups " )
37+ if cfg .S3 .Bucket != "real-bucket " {
38+ t .Errorf ("bucket = %q, want %q" , cfg .S3 .Bucket , "real-bucket " )
3839 }
3940 if cfg .ScheduleIntervalHours != 4 {
4041 t .Errorf ("schedule = %d, want 4" , cfg .ScheduleIntervalHours )
@@ -95,6 +96,22 @@ func TestLoadMissingFields(t *testing.T) {
9596 }
9697}
9798
99+ func TestLoadPlaceholderValues (t * testing.T ) {
100+ dir := t .TempDir ()
101+ path := filepath .Join (dir , "config.json" )
102+
103+ // Use the example config directly — should be rejected
104+ WriteExample (path )
105+
106+ _ , err := Load (path )
107+ if err == nil {
108+ t .Fatal ("expected error for unedited example config" )
109+ }
110+ if ! strings .Contains (err .Error (), "still has the example value" ) {
111+ t .Errorf ("expected placeholder error, got: %v" , err )
112+ }
113+ }
114+
98115func TestRepoURL (t * testing.T ) {
99116 tests := []struct {
100117 name string
@@ -136,12 +153,21 @@ func TestWriteExample(t *testing.T) {
136153 t .Fatal (err )
137154 }
138155
139- cfg , err := Load (path )
156+ // Verify it's valid JSON with expected fields
157+ data , err := os .ReadFile (path )
140158 if err != nil {
141- t .Fatalf ("example config should be loadable: %v" , err )
159+ t .Fatal (err )
160+ }
161+
162+ var cfg Config
163+ if err := json .Unmarshal (data , & cfg ); err != nil {
164+ t .Fatalf ("example config is not valid JSON: %v" , err )
142165 }
143166
144167 if cfg .S3 .Bucket == "" {
145168 t .Error ("example config should have a non-empty bucket" )
146169 }
170+ if cfg .ResticPassword == "" {
171+ t .Error ("example config should have a non-empty restic_password" )
172+ }
147173}
0 commit comments