(t *testing.T)
| 120 | } |
| 121 | |
| 122 | func TestDecompress(t *testing.T) { |
| 123 | t.Run("plain text passthrough", func(t *testing.T) { |
| 124 | data := []byte("hello world") |
| 125 | got := decompress(data, "") |
| 126 | if string(got) != "hello world" { |
| 127 | t.Errorf("got %q", got) |
| 128 | } |
| 129 | }) |
| 130 | |
| 131 | t.Run("gzip with header", func(t *testing.T) { |
| 132 | var buf bytes.Buffer |
| 133 | w := gzip.NewWriter(&buf) |
| 134 | w.Write([]byte("compressed")) |
| 135 | w.Close() |
| 136 | |
| 137 | got := decompress(buf.Bytes(), "gzip") |
| 138 | if string(got) != "compressed" { |
| 139 | t.Errorf("got %q, want %q", got, "compressed") |
| 140 | } |
| 141 | }) |
| 142 | |
| 143 | t.Run("gzip auto-detect by magic bytes", func(t *testing.T) { |
| 144 | var buf bytes.Buffer |
| 145 | w := gzip.NewWriter(&buf) |
| 146 | w.Write([]byte("auto-detected")) |
| 147 | w.Close() |
| 148 | |
| 149 | got := decompress(buf.Bytes(), "") |
| 150 | if string(got) != "auto-detected" { |
| 151 | t.Errorf("got %q, want %q", got, "auto-detected") |
| 152 | } |
| 153 | }) |
| 154 | |
| 155 | t.Run("empty data", func(t *testing.T) { |
| 156 | got := decompress([]byte{}, "gzip") |
| 157 | if len(got) != 0 { |
| 158 | t.Errorf("expected empty, got %q", got) |
| 159 | } |
| 160 | }) |
| 161 | } |
| 162 | |
| 163 | func TestExtractProject(t *testing.T) { |
| 164 | tests := []struct { |
nothing calls this directly
no test coverage detected