package packs

import "testing"

func TestLegacySourceBackedBackfillPackSourceIdentityFallsBackToOfficialRepo(t *testing.T) {
	tests := []struct {
		name       string
		sourceKind string
		sourceURI  string
		wantKind   string
		wantURI    string
	}{
		{name: "missing both", wantKind: string(PackSourceKindOfficialRepo), wantURI: "salesforce-crm-standard"},
		{name: "missing uri", sourceKind: string(PackSourceKindOfficialRepo), wantKind: string(PackSourceKindOfficialRepo), wantURI: "salesforce-crm-standard"},
		{name: "legacy uri only", sourceURI: "salesforce-crm-standard", wantKind: string(PackSourceKindOfficialRepo), wantURI: "salesforce-crm-standard"},
		{name: "local path passthrough", sourceKind: string(PackSourceKindLocalPath), sourceURI: "/tmp/app-pack", wantKind: string(PackSourceKindLocalPath), wantURI: "/tmp/app-pack"},
	}

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			gotKind, gotURI, err := legacySourceBackedBackfillPackSourceIdentity("salesforce-crm-standard", tc.sourceKind, tc.sourceURI)
			if err != nil {
				t.Fatalf("legacySourceBackedBackfillPackSourceIdentity() error = %v", err)
			}
			if gotKind != tc.wantKind || gotURI != tc.wantURI {
				t.Fatalf("legacySourceBackedBackfillPackSourceIdentity() = (%q, %q), want (%q, %q)", gotKind, gotURI, tc.wantKind, tc.wantURI)
			}
		})
	}
}
