mitminfo_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package fp_test
  2. import (
  3. "testing"
  4. fp "github.com/cloudflare/mitmengine/fputil"
  5. "github.com/cloudflare/mitmengine/testutil"
  6. )
  7. func TestNewMitmInfo(t *testing.T) {
  8. var tests = []struct {
  9. in string
  10. out fp.MitmInfo
  11. }{
  12. {":0:0", fp.MitmInfo{}},
  13. {"test:1:1", fp.MitmInfo{NameList: fp.StringList{"test"}, Type: fp.TypeAntivirus, Grade: fp.GradeA}},
  14. {"test1,test2:1:1", fp.MitmInfo{NameList: fp.StringList{"test1", "test2"}, Type: fp.TypeAntivirus, Grade: fp.GradeA}},
  15. }
  16. for _, test := range tests {
  17. info, err := fp.NewMitmInfo(test.in)
  18. testutil.Ok(t, err)
  19. testutil.Equals(t, test.out, info)
  20. }
  21. }
  22. func TestMitmInfoString(t *testing.T) {
  23. var tests = []struct {
  24. in fp.MitmInfo
  25. out string
  26. }{
  27. {fp.MitmInfo{}, ":0:0"},
  28. {fp.MitmInfo{NameList: fp.StringList{"test"}, Type: fp.TypeAntivirus, Grade: fp.GradeA}, "test:1:1"},
  29. {fp.MitmInfo{NameList: fp.StringList{"test1", "test2"}, Type: fp.TypeAntivirus, Grade: fp.GradeA}, "test1,test2:1:1"},
  30. }
  31. for _, test := range tests {
  32. testutil.Equals(t, test.out, test.in.String())
  33. }
  34. }
  35. func TestMitmInfoMerge(t *testing.T) {
  36. var tests = []struct {
  37. in1 fp.MitmInfo
  38. in2 fp.MitmInfo
  39. out fp.MitmInfo
  40. }{
  41. {fp.MitmInfo{}, fp.MitmInfo{}, fp.MitmInfo{}},
  42. }
  43. for _, test := range tests {
  44. testutil.Equals(t, test.out, test.in1.Merge(test.in2))
  45. }
  46. }
  47. func TestMitmInfoMatch(t *testing.T) {
  48. var tests = []struct {
  49. in1 fp.MitmInfo
  50. in2 fp.MitmInfo
  51. out fp.Match
  52. }{
  53. {fp.MitmInfo{}, fp.MitmInfo{}, fp.MatchPossible},
  54. }
  55. for _, test := range tests {
  56. testutil.Equals(t, test.out, test.in1.Match(test.in2))
  57. }
  58. }