package main

import "testing"

func TestRepositoryNeedsInit(t *testing.T) {
	tests := []struct {
		name    string
		profile Profile
		code    int
		output  string
		want    bool
	}{
		{"restic exit code", Profile{Backend: "restic"}, 10, "", true},
		{"restic other code", Profile{Backend: "restic"}, 1, "repository does not exist", false},
		{"rustic missing repository", Profile{Backend: "rustic"}, 1, "Repository is not initialized", true},
		{"rustic config missing", Profile{Backend: "rustic"}, 1, "no such file or directory: config", true},
		{"rustic auth error", Profile{Backend: "rustic"}, 1, "password failed", false},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := repositoryNeedsInit(tt.profile, tt.code, tt.output); got != tt.want {
				t.Fatalf("repositoryNeedsInit() = %v, want %v", got, tt.want)
			}
		})
	}
}
