github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/communicator/communication/Header_test.go (about) 1 package communication 2 3 import "testing" 4 5 func TestGetDispositionFilename(t *testing.T) { 6 testData := map[string]string{} 7 8 testData["attachment; filename=testfile"] = "testfile" 9 testData["attachment; filename=\"testfile\""] = "testfile" 10 testData["attachment; filename=\"testfile"] = "\"testfile" 11 testData["attachment; filename=testfile\""] = "testfile\"" 12 testData["attachment; filename='testfile'"] = "testfile" 13 testData["attachment; filename='testfile"] = "'testfile" 14 testData["attachment; filename=testfile'"] = "testfile'" 15 16 testData["filename=testfile"] = "testfile" 17 testData["filename=\"testfile\""] = "testfile" 18 testData["filename=\"testfile"] = "\"testfile" 19 testData["filename=testfile\""] = "testfile\"" 20 testData["filename='testfile'"] = "testfile" 21 testData["filename='testfile"] = "'testfile" 22 testData["filename=testfile'"] = "testfile'" 23 24 testData["attachment; filename=testfile; x=y"] = "testfile" 25 testData["attachment; filename=\"testfile\"; x=y"] = "testfile" 26 testData["attachment; filename=\"testfile; x=y"] = "\"testfile" 27 testData["attachment; filename=testfile\"; x=y"] = "testfile\"" 28 testData["attachment; filename='testfile'; x=y"] = "testfile" 29 testData["attachment; filename='testfile; x=y"] = "'testfile" 30 testData["attachment; filename=testfile'; x=y"] = "testfile'" 31 32 testData["attachment"] = "" 33 34 testData["filename=\""] = "\"" 35 testData["filename='"] = "'" 36 37 for value, expected := range testData { 38 header, _ := NewHeader("Content-Disposition", value) 39 headers := append(Headers{}, *header) 40 if expected != headers.GetDispositionFilename() { 41 t.Fatalf("TestGetDispositionFilename : %s should yield %s", value, expected) 42 } 43 } 44 }