mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-12 17:28:29 +03:00
29 lines
561 B
Go
29 lines
561 B
Go
package base64
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestDecodeFormats(t *testing.T) {
|
|
compressed, err := Encode([]byte("x"), true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, tc := range []struct {
|
|
name, value, want string
|
|
}{
|
|
{"unprefixed", "eA==", "x"},
|
|
{"base64", Prefix + "eA==", "x"},
|
|
{"gzip", compressed, "x"},
|
|
{"empty", Prefix, ""},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
data, err := Decode(tc.value)
|
|
if err != nil || !bytes.Equal(data, []byte(tc.want)) {
|
|
t.Fatalf("Decode = %q, %v; want %q", data, err, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|