package catalogue import ( "strings" "testing" ) // A backup contribution written by hand still names its module's own directories; one it does not // declare is refused where it is written rather than reaching the holder as the literal text. (The // catalogue check refuses a hand-written backup line at all since ADR 0233; parsing still reads one, // because a module on the shelf was written before.) func TestABackupNamingAnUndeclaredDirectoryIsRefused(t *testing.T) { _, err := ParseManifest([]byte(`{"module":"pg","version":"1", "contributions":[{"seat":"node-backup","kind":"backup","content":"path ${dir:nowhere}"}]}`)) if err == nil || !strings.Contains(err.Error(), "nowhere") { t.Fatalf("a backup of an undeclared directory was accepted: %v", err) } } // A module on the shelf from before ADR 0233, which writes its backup lines by hand and declares no // data, is still backed up: its lines are placed as written, each module's under a comment naming it. func TestHandWrittenBackupLinesOfAnOlderModuleArePlaced(t *testing.T) { pg, err := ParseManifest([]byte(`{"module":"pg","version":"1", "resources":[{"id":"dumps","type":"directory","path":"/srv/pg/dumps","mode":"0700"}], "contributions":[{"seat":"node-backup","kind":"backup","content":"run pg-dump-all\npath ${dir:dumps}"}]}`)) if err != nil { t.Fatal(err) } mail, err := ParseManifest([]byte(`{"module":"mail","version":"1", "resources":[{"id":"spool","type":"directory","mode":"0700"}], "contributions":[{"seat":"node-backup","kind":"backup","content":"path ${dir:spool}"}]}`)) if err != nil { t.Fatal(err) } placed, err := seatContributions([]Manifest{pg, mail}, BackupSeat, "backup", Rendering{}, nil) if err != nil { t.Fatal(err) } for _, want := range []string{"# pg\nrun pg-dump-all\npath /srv/pg/dumps\n", "# mail\npath /var/lib/mail/spool\n"} { if !strings.Contains(placed, want) { t.Errorf("placed contributions lack %q:\n%s", want, placed) } } if strings.Contains(placed, "${dir:") { t.Errorf("a directory reached the holder unfilled:\n%s", placed) } }