1*60517a1eSAndroid Build Coastguard Workerpackage pythonconfig 2*60517a1eSAndroid Build Coastguard Worker 3*60517a1eSAndroid Build Coastguard Workerimport ( 4*60517a1eSAndroid Build Coastguard Worker "testing" 5*60517a1eSAndroid Build Coastguard Worker) 6*60517a1eSAndroid Build Coastguard Worker 7*60517a1eSAndroid Build Coastguard Workerfunc TestFormatThirdPartyDependency(t *testing.T) { 8*60517a1eSAndroid Build Coastguard Worker type testInput struct { 9*60517a1eSAndroid Build Coastguard Worker RepositoryName string 10*60517a1eSAndroid Build Coastguard Worker DistributionName string 11*60517a1eSAndroid Build Coastguard Worker LabelNormalization LabelNormalizationType 12*60517a1eSAndroid Build Coastguard Worker LabelConvention string 13*60517a1eSAndroid Build Coastguard Worker } 14*60517a1eSAndroid Build Coastguard Worker 15*60517a1eSAndroid Build Coastguard Worker tests := map[string]struct { 16*60517a1eSAndroid Build Coastguard Worker input testInput 17*60517a1eSAndroid Build Coastguard Worker want string 18*60517a1eSAndroid Build Coastguard Worker }{ 19*60517a1eSAndroid Build Coastguard Worker "default / upper case": { 20*60517a1eSAndroid Build Coastguard Worker input: testInput{ 21*60517a1eSAndroid Build Coastguard Worker DistributionName: "DistWithUpperCase", 22*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 23*60517a1eSAndroid Build Coastguard Worker LabelNormalization: DefaultLabelNormalizationType, 24*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 25*60517a1eSAndroid Build Coastguard Worker }, 26*60517a1eSAndroid Build Coastguard Worker want: "@pip//distwithuppercase", 27*60517a1eSAndroid Build Coastguard Worker }, 28*60517a1eSAndroid Build Coastguard Worker "default / dashes": { 29*60517a1eSAndroid Build Coastguard Worker input: testInput{ 30*60517a1eSAndroid Build Coastguard Worker DistributionName: "dist-with-dashes", 31*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 32*60517a1eSAndroid Build Coastguard Worker LabelNormalization: DefaultLabelNormalizationType, 33*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 34*60517a1eSAndroid Build Coastguard Worker }, 35*60517a1eSAndroid Build Coastguard Worker want: "@pip//dist_with_dashes", 36*60517a1eSAndroid Build Coastguard Worker }, 37*60517a1eSAndroid Build Coastguard Worker "default / repeating dashes inside": { 38*60517a1eSAndroid Build Coastguard Worker input: testInput{ 39*60517a1eSAndroid Build Coastguard Worker DistributionName: "friendly--bard", 40*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 41*60517a1eSAndroid Build Coastguard Worker LabelNormalization: DefaultLabelNormalizationType, 42*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 43*60517a1eSAndroid Build Coastguard Worker }, 44*60517a1eSAndroid Build Coastguard Worker want: "@pip//friendly_bard", 45*60517a1eSAndroid Build Coastguard Worker }, 46*60517a1eSAndroid Build Coastguard Worker "default / repeating underscores inside": { 47*60517a1eSAndroid Build Coastguard Worker input: testInput{ 48*60517a1eSAndroid Build Coastguard Worker DistributionName: "hello___something", 49*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 50*60517a1eSAndroid Build Coastguard Worker LabelNormalization: DefaultLabelNormalizationType, 51*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 52*60517a1eSAndroid Build Coastguard Worker }, 53*60517a1eSAndroid Build Coastguard Worker want: "@pip//hello_something", 54*60517a1eSAndroid Build Coastguard Worker }, 55*60517a1eSAndroid Build Coastguard Worker "default / prefix repeating underscores": { 56*60517a1eSAndroid Build Coastguard Worker input: testInput{ 57*60517a1eSAndroid Build Coastguard Worker DistributionName: "__hello-something", 58*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 59*60517a1eSAndroid Build Coastguard Worker LabelNormalization: DefaultLabelNormalizationType, 60*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 61*60517a1eSAndroid Build Coastguard Worker }, 62*60517a1eSAndroid Build Coastguard Worker want: "@pip//hello_something", 63*60517a1eSAndroid Build Coastguard Worker }, 64*60517a1eSAndroid Build Coastguard Worker "default / suffix repeating underscores": { 65*60517a1eSAndroid Build Coastguard Worker input: testInput{ 66*60517a1eSAndroid Build Coastguard Worker DistributionName: "hello-something___", 67*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 68*60517a1eSAndroid Build Coastguard Worker LabelNormalization: DefaultLabelNormalizationType, 69*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 70*60517a1eSAndroid Build Coastguard Worker }, 71*60517a1eSAndroid Build Coastguard Worker want: "@pip//hello_something", 72*60517a1eSAndroid Build Coastguard Worker }, 73*60517a1eSAndroid Build Coastguard Worker "default / prefix repeating dashes": { 74*60517a1eSAndroid Build Coastguard Worker input: testInput{ 75*60517a1eSAndroid Build Coastguard Worker DistributionName: "---hello-something", 76*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 77*60517a1eSAndroid Build Coastguard Worker LabelNormalization: DefaultLabelNormalizationType, 78*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 79*60517a1eSAndroid Build Coastguard Worker }, 80*60517a1eSAndroid Build Coastguard Worker want: "@pip//hello_something", 81*60517a1eSAndroid Build Coastguard Worker }, 82*60517a1eSAndroid Build Coastguard Worker "default / suffix repeating dashes": { 83*60517a1eSAndroid Build Coastguard Worker input: testInput{ 84*60517a1eSAndroid Build Coastguard Worker DistributionName: "hello-something----", 85*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 86*60517a1eSAndroid Build Coastguard Worker LabelNormalization: DefaultLabelNormalizationType, 87*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 88*60517a1eSAndroid Build Coastguard Worker }, 89*60517a1eSAndroid Build Coastguard Worker want: "@pip//hello_something", 90*60517a1eSAndroid Build Coastguard Worker }, 91*60517a1eSAndroid Build Coastguard Worker "default / dots": { 92*60517a1eSAndroid Build Coastguard Worker input: testInput{ 93*60517a1eSAndroid Build Coastguard Worker DistributionName: "dist.with.dots", 94*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 95*60517a1eSAndroid Build Coastguard Worker LabelNormalization: DefaultLabelNormalizationType, 96*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 97*60517a1eSAndroid Build Coastguard Worker }, 98*60517a1eSAndroid Build Coastguard Worker want: "@pip//dist_with_dots", 99*60517a1eSAndroid Build Coastguard Worker }, 100*60517a1eSAndroid Build Coastguard Worker "default / mixed": { 101*60517a1eSAndroid Build Coastguard Worker input: testInput{ 102*60517a1eSAndroid Build Coastguard Worker DistributionName: "FrIeNdLy-._.-bArD", 103*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 104*60517a1eSAndroid Build Coastguard Worker LabelNormalization: DefaultLabelNormalizationType, 105*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 106*60517a1eSAndroid Build Coastguard Worker }, 107*60517a1eSAndroid Build Coastguard Worker want: "@pip//friendly_bard", 108*60517a1eSAndroid Build Coastguard Worker }, 109*60517a1eSAndroid Build Coastguard Worker "default / upper case / custom prefix & suffix": { 110*60517a1eSAndroid Build Coastguard Worker input: testInput{ 111*60517a1eSAndroid Build Coastguard Worker DistributionName: "DistWithUpperCase", 112*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 113*60517a1eSAndroid Build Coastguard Worker LabelNormalization: DefaultLabelNormalizationType, 114*60517a1eSAndroid Build Coastguard Worker LabelConvention: "pReFiX-$distribution_name$-sUfFiX", 115*60517a1eSAndroid Build Coastguard Worker }, 116*60517a1eSAndroid Build Coastguard Worker want: "@pip//prefix_distwithuppercase_suffix", 117*60517a1eSAndroid Build Coastguard Worker }, 118*60517a1eSAndroid Build Coastguard Worker "noop normalization / mixed": { 119*60517a1eSAndroid Build Coastguard Worker input: testInput{ 120*60517a1eSAndroid Build Coastguard Worker DistributionName: "not-TO-be.sanitized", 121*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 122*60517a1eSAndroid Build Coastguard Worker LabelNormalization: NoLabelNormalizationType, 123*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 124*60517a1eSAndroid Build Coastguard Worker }, 125*60517a1eSAndroid Build Coastguard Worker want: "@pip//not-TO-be.sanitized", 126*60517a1eSAndroid Build Coastguard Worker }, 127*60517a1eSAndroid Build Coastguard Worker "noop normalization / mixed / custom prefix & suffix": { 128*60517a1eSAndroid Build Coastguard Worker input: testInput{ 129*60517a1eSAndroid Build Coastguard Worker DistributionName: "not-TO-be.sanitized", 130*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 131*60517a1eSAndroid Build Coastguard Worker LabelNormalization: NoLabelNormalizationType, 132*60517a1eSAndroid Build Coastguard Worker LabelConvention: "pre___$distribution_name$___fix", 133*60517a1eSAndroid Build Coastguard Worker }, 134*60517a1eSAndroid Build Coastguard Worker want: "@pip//pre___not-TO-be.sanitized___fix", 135*60517a1eSAndroid Build Coastguard Worker }, 136*60517a1eSAndroid Build Coastguard Worker "pep503 / upper case": { 137*60517a1eSAndroid Build Coastguard Worker input: testInput{ 138*60517a1eSAndroid Build Coastguard Worker DistributionName: "DistWithUpperCase", 139*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 140*60517a1eSAndroid Build Coastguard Worker LabelNormalization: Pep503LabelNormalizationType, 141*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 142*60517a1eSAndroid Build Coastguard Worker }, 143*60517a1eSAndroid Build Coastguard Worker want: "@pip//distwithuppercase", 144*60517a1eSAndroid Build Coastguard Worker }, 145*60517a1eSAndroid Build Coastguard Worker "pep503 / underscores": { 146*60517a1eSAndroid Build Coastguard Worker input: testInput{ 147*60517a1eSAndroid Build Coastguard Worker DistributionName: "dist_with_underscores", 148*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 149*60517a1eSAndroid Build Coastguard Worker LabelNormalization: Pep503LabelNormalizationType, 150*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 151*60517a1eSAndroid Build Coastguard Worker }, 152*60517a1eSAndroid Build Coastguard Worker want: "@pip//dist-with-underscores", 153*60517a1eSAndroid Build Coastguard Worker }, 154*60517a1eSAndroid Build Coastguard Worker "pep503 / repeating dashes inside": { 155*60517a1eSAndroid Build Coastguard Worker input: testInput{ 156*60517a1eSAndroid Build Coastguard Worker DistributionName: "friendly--bard", 157*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 158*60517a1eSAndroid Build Coastguard Worker LabelNormalization: Pep503LabelNormalizationType, 159*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 160*60517a1eSAndroid Build Coastguard Worker }, 161*60517a1eSAndroid Build Coastguard Worker want: "@pip//friendly-bard", 162*60517a1eSAndroid Build Coastguard Worker }, 163*60517a1eSAndroid Build Coastguard Worker "pep503 / repeating underscores inside": { 164*60517a1eSAndroid Build Coastguard Worker input: testInput{ 165*60517a1eSAndroid Build Coastguard Worker DistributionName: "hello___something", 166*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 167*60517a1eSAndroid Build Coastguard Worker LabelNormalization: Pep503LabelNormalizationType, 168*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 169*60517a1eSAndroid Build Coastguard Worker }, 170*60517a1eSAndroid Build Coastguard Worker want: "@pip//hello-something", 171*60517a1eSAndroid Build Coastguard Worker }, 172*60517a1eSAndroid Build Coastguard Worker "pep503 / prefix repeating underscores": { 173*60517a1eSAndroid Build Coastguard Worker input: testInput{ 174*60517a1eSAndroid Build Coastguard Worker DistributionName: "__hello-something", 175*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 176*60517a1eSAndroid Build Coastguard Worker LabelNormalization: Pep503LabelNormalizationType, 177*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 178*60517a1eSAndroid Build Coastguard Worker }, 179*60517a1eSAndroid Build Coastguard Worker want: "@pip//hello-something", 180*60517a1eSAndroid Build Coastguard Worker }, 181*60517a1eSAndroid Build Coastguard Worker "pep503 / suffix repeating underscores": { 182*60517a1eSAndroid Build Coastguard Worker input: testInput{ 183*60517a1eSAndroid Build Coastguard Worker DistributionName: "hello-something___", 184*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 185*60517a1eSAndroid Build Coastguard Worker LabelNormalization: Pep503LabelNormalizationType, 186*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 187*60517a1eSAndroid Build Coastguard Worker }, 188*60517a1eSAndroid Build Coastguard Worker want: "@pip//hello-something", 189*60517a1eSAndroid Build Coastguard Worker }, 190*60517a1eSAndroid Build Coastguard Worker "pep503 / prefix repeating dashes": { 191*60517a1eSAndroid Build Coastguard Worker input: testInput{ 192*60517a1eSAndroid Build Coastguard Worker DistributionName: "---hello-something", 193*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 194*60517a1eSAndroid Build Coastguard Worker LabelNormalization: Pep503LabelNormalizationType, 195*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 196*60517a1eSAndroid Build Coastguard Worker }, 197*60517a1eSAndroid Build Coastguard Worker want: "@pip//hello-something", 198*60517a1eSAndroid Build Coastguard Worker }, 199*60517a1eSAndroid Build Coastguard Worker "pep503 / suffix repeating dashes": { 200*60517a1eSAndroid Build Coastguard Worker input: testInput{ 201*60517a1eSAndroid Build Coastguard Worker DistributionName: "hello-something----", 202*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 203*60517a1eSAndroid Build Coastguard Worker LabelNormalization: Pep503LabelNormalizationType, 204*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 205*60517a1eSAndroid Build Coastguard Worker }, 206*60517a1eSAndroid Build Coastguard Worker want: "@pip//hello-something", 207*60517a1eSAndroid Build Coastguard Worker }, 208*60517a1eSAndroid Build Coastguard Worker "pep503 / dots": { 209*60517a1eSAndroid Build Coastguard Worker input: testInput{ 210*60517a1eSAndroid Build Coastguard Worker DistributionName: "dist.with.dots", 211*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 212*60517a1eSAndroid Build Coastguard Worker LabelNormalization: Pep503LabelNormalizationType, 213*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 214*60517a1eSAndroid Build Coastguard Worker }, 215*60517a1eSAndroid Build Coastguard Worker want: "@pip//dist-with-dots", 216*60517a1eSAndroid Build Coastguard Worker }, 217*60517a1eSAndroid Build Coastguard Worker "pep503 / mixed": { 218*60517a1eSAndroid Build Coastguard Worker input: testInput{ 219*60517a1eSAndroid Build Coastguard Worker DistributionName: "To-be.sanitized", 220*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 221*60517a1eSAndroid Build Coastguard Worker LabelNormalization: Pep503LabelNormalizationType, 222*60517a1eSAndroid Build Coastguard Worker LabelConvention: DefaultLabelConvention, 223*60517a1eSAndroid Build Coastguard Worker }, 224*60517a1eSAndroid Build Coastguard Worker want: "@pip//to-be-sanitized", 225*60517a1eSAndroid Build Coastguard Worker }, 226*60517a1eSAndroid Build Coastguard Worker "pep503 / underscores / custom prefix & suffix": { 227*60517a1eSAndroid Build Coastguard Worker input: testInput{ 228*60517a1eSAndroid Build Coastguard Worker DistributionName: "dist_with_underscores", 229*60517a1eSAndroid Build Coastguard Worker RepositoryName: "pip", 230*60517a1eSAndroid Build Coastguard Worker LabelNormalization: Pep503LabelNormalizationType, 231*60517a1eSAndroid Build Coastguard Worker LabelConvention: "pre___$distribution_name$___fix", 232*60517a1eSAndroid Build Coastguard Worker }, 233*60517a1eSAndroid Build Coastguard Worker want: "@pip//pre-dist-with-underscores-fix", 234*60517a1eSAndroid Build Coastguard Worker }, 235*60517a1eSAndroid Build Coastguard Worker } 236*60517a1eSAndroid Build Coastguard Worker 237*60517a1eSAndroid Build Coastguard Worker for name, tc := range tests { 238*60517a1eSAndroid Build Coastguard Worker t.Run(name, func(t *testing.T) { 239*60517a1eSAndroid Build Coastguard Worker c := Config{ 240*60517a1eSAndroid Build Coastguard Worker labelNormalization: tc.input.LabelNormalization, 241*60517a1eSAndroid Build Coastguard Worker labelConvention: tc.input.LabelConvention, 242*60517a1eSAndroid Build Coastguard Worker } 243*60517a1eSAndroid Build Coastguard Worker gotLabel := c.FormatThirdPartyDependency(tc.input.RepositoryName, tc.input.DistributionName) 244*60517a1eSAndroid Build Coastguard Worker got := gotLabel.String() 245*60517a1eSAndroid Build Coastguard Worker if tc.want != got { 246*60517a1eSAndroid Build Coastguard Worker t.Fatalf("expected %q, got %q", tc.want, got) 247*60517a1eSAndroid Build Coastguard Worker } 248*60517a1eSAndroid Build Coastguard Worker }) 249*60517a1eSAndroid Build Coastguard Worker } 250*60517a1eSAndroid Build Coastguard Worker} 251