(t *testing.T)
| 67 | } |
| 68 | |
| 69 | func TestParseBinaryFragmentHeader(t *testing.T) { |
| 70 | tests := map[string]struct { |
| 71 | Input string |
| 72 | Output *BinaryFragment |
| 73 | Err bool |
| 74 | }{ |
| 75 | "delta": { |
| 76 | Input: "delta 1234\n", |
| 77 | Output: &BinaryFragment{ |
| 78 | Method: BinaryPatchDelta, |
| 79 | Size: 1234, |
| 80 | }, |
| 81 | }, |
| 82 | "literal": { |
| 83 | Input: "literal 1234\n", |
| 84 | Output: &BinaryFragment{ |
| 85 | Method: BinaryPatchLiteral, |
| 86 | Size: 1234, |
| 87 | }, |
| 88 | }, |
| 89 | "unknownMethod": { |
| 90 | Input: "compressed 1234\n", |
| 91 | Output: nil, |
| 92 | }, |
| 93 | "notAHeader": { |
| 94 | Input: "Binary files differ\n", |
| 95 | Output: nil, |
| 96 | }, |
| 97 | "invalidSize": { |
| 98 | Input: "delta 123abc\n", |
| 99 | Err: true, |
| 100 | }, |
| 101 | } |
| 102 | |
| 103 | for name, test := range tests { |
| 104 | t.Run(name, func(t *testing.T) { |
| 105 | p := newTestParser(test.Input, true) |
| 106 | |
| 107 | frag, err := p.ParseBinaryFragmentHeader() |
| 108 | if test.Err { |
| 109 | if err == nil || err == io.EOF { |
| 110 | t.Fatalf("expected error parsing binary header, but got %v", err) |
| 111 | } |
| 112 | return |
| 113 | } |
| 114 | if err != nil { |
| 115 | t.Fatalf("unexpected error parsing binary header: %v", err) |
| 116 | } |
| 117 | if !reflect.DeepEqual(test.Output, frag) { |
| 118 | t.Errorf("incorrect binary fragment\nexpected: %+v\n actual: %+v", test.Output, frag) |
| 119 | } |
| 120 | }) |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | func TestParseBinaryChunk(t *testing.T) { |
| 125 | tests := map[string]struct { |
nothing calls this directly
no test coverage detected