TUN-813: Clean up cloudflared dependencies

This commit is contained in:
Areg Harutyunyan
2018-07-24 18:04:33 -05:00
parent d06fc520c7
commit 0468866626
3310 changed files with 993 additions and 1223303 deletions

View File

@@ -1,229 +0,0 @@
package text
import (
"bytes"
"io/ioutil"
"path/filepath"
"testing"
"zombiezen.com/go/capnproto2"
"zombiezen.com/go/capnproto2/internal/schema"
"zombiezen.com/go/capnproto2/schemas"
)
func readTestFile(name string) ([]byte, error) {
path := filepath.Join("testdata", name)
return ioutil.ReadFile(path)
}
func TestEncode(t *testing.T) {
tests := []struct {
constID uint64
text string
}{
{0xc0b634e19e5a9a4e, `(key = "42", value = (int32 = -123))`},
{0x967c8fe21790b0fb, `(key = "float", value = (float64 = 3.14))`},
{0xdf35cb2e1f5ea087, `(key = "bool", value = (bool = false))`},
{0xb167974479102805, `(map = [(key = "foo", value = (void = void)), (key = "bar", value = (void = void))])`},
{0x81fdbfdc91779421, `(map = [])`},
{0x8e85252144f61858, `(data = "Hi\xde\xad\xbe\xef\xca\xfe")`},
{0xc21398a8474837ba, `(voidList = [void, void])`},
{0xde82c2eeb3a4b07c, `(boolList = [true, false, true, false])`},
{0xf9e3ffc179272aa2, `(int8List = [1, -2, 3])`},
{0xfc421b96ec6ad2b6, `(int64List = [1, -2, 3])`},
{0xb3034b89d02775a5, `(uint8List = [255, 0, 1])`},
{0x9246c307e46ad03b, `(uint64List = [1, 2, 3])`},
{0xd012128a1a9cb7fc, `(float32List = [0.5, 3.14, -2])`},
{0xf16c386c66d492e2, `(textList = ["foo", "bar", "baz"])`},
{0xe14f4d42aa55de8c, `(dataList = ["\xde\xad\xbe\xef", "\xca\xfe"])`},
{0xe88c91698f7f0b73, `(cheese = gouda)`},
{0x9c51b843b337490b, `(cheeseList = [gouda, cheddar])`},
{0x81e2aadb8bfb237b, `(matrix = [[1, 2, 3], [4, 5, 6]])`},
}
data, err := readTestFile("txt.capnp.out")
if err != nil {
t.Fatal(err)
}
reg := new(schemas.Registry)
err = reg.Register(&schemas.Schema{
Bytes: data,
Nodes: []uint64{
0x8df8bc5abdc060a6,
0xd3602730c572a43b,
},
})
if err != nil {
t.Fatalf("Adding to registry: %v", err)
}
msg, err := capnp.Unmarshal(data)
if err != nil {
t.Fatal("Unmarshaling txt.capnp.out:", err)
}
req, err := schema.ReadRootCodeGeneratorRequest(msg)
if err != nil {
t.Fatal("Reading code generator request txt.capnp.out:", err)
}
nodes, err := req.Nodes()
if err != nil {
t.Fatal(err)
}
nodeMap := make(map[uint64]schema.Node, nodes.Len())
for i := 0; i < nodes.Len(); i++ {
n := nodes.At(i)
nodeMap[n.Id()] = n
}
for _, test := range tests {
c := nodeMap[test.constID]
if !c.IsValid() {
t.Errorf("Can't find node %#x; skipping", test.constID)
continue
}
dn, _ := c.DisplayName()
if c.Which() != schema.Node_Which_const {
t.Errorf("%s @%#x is a %v, not const; skipping", dn, test.constID, c.Which())
continue
}
typ, err := c.Const().Type()
if err != nil {
t.Errorf("(%s @%#x).const.type: %v", dn, test.constID, err)
continue
}
if typ.Which() != schema.Type_Which_structType {
t.Errorf("(%s @%#x).const.type is a %v; want struct", dn, test.constID, typ.Which())
continue
}
tid := typ.StructType().TypeId()
v, err := c.Const().Value()
if err != nil {
t.Errorf("(%s @%#x).const.value: %v", dn, test.constID, err)
continue
}
if v.Which() != schema.Value_Which_structValue {
t.Errorf("(%s @%#x).const.value is a %v; want struct", dn, test.constID, v.Which())
continue
}
sv, err := v.StructValuePtr()
if err != nil {
t.Errorf("(%s @%#x).const.value.struct: %v", dn, test.constID, err)
continue
}
buf := new(bytes.Buffer)
enc := NewEncoder(buf)
enc.UseRegistry(reg)
if err := enc.Encode(tid, sv.Struct()); err != nil {
t.Errorf("Encode(%#x, (%s @%#x).const.value.struct): %v", tid, dn, test.constID, err)
continue
}
if text := buf.String(); text != test.text {
t.Errorf("Encode(%#x, (%s @%#x).const.value.struct) = %q; want %q", tid, dn, test.constID, text, test.text)
continue
}
}
}
func TestEncodeList(t *testing.T) {
tests := []struct {
constID uint64
text string
}{
{0x90c9e81e6418df8e, `[(key = "foo", value = (void = void)), (key = "bar", value = (void = void))]`},
}
data, err := readTestFile("txt.capnp.out")
if err != nil {
t.Fatal(err)
}
reg := new(schemas.Registry)
err = reg.Register(&schemas.Schema{
Bytes: data,
Nodes: []uint64{
0x8df8bc5abdc060a6,
0xd3602730c572a43b,
},
})
if err != nil {
t.Fatalf("Adding to registry: %v", err)
}
msg, err := capnp.Unmarshal(data)
if err != nil {
t.Fatal("Unmarshaling txt.capnp.out:", err)
}
req, err := schema.ReadRootCodeGeneratorRequest(msg)
if err != nil {
t.Fatal("Reading code generator request txt.capnp.out:", err)
}
nodes, err := req.Nodes()
if err != nil {
t.Fatal(err)
}
nodeMap := make(map[uint64]schema.Node, nodes.Len())
for i := 0; i < nodes.Len(); i++ {
n := nodes.At(i)
nodeMap[n.Id()] = n
}
for _, test := range tests {
c := nodeMap[test.constID]
if !c.IsValid() {
t.Errorf("Can't find node %#x; skipping", test.constID)
continue
}
dn, _ := c.DisplayName()
if c.Which() != schema.Node_Which_const {
t.Errorf("%s @%#x is a %v, not const; skipping", dn, test.constID, c.Which())
continue
}
typ, err := c.Const().Type()
if err != nil {
t.Errorf("(%s @%#x).const.type: %v", dn, test.constID, err)
continue
}
if typ.Which() != schema.Type_Which_list {
t.Errorf("(%s @%#x).const.type is a %v; want list", dn, test.constID, typ.Which())
continue
}
etyp, err := typ.List().ElementType()
if err != nil {
t.Errorf("(%s @%#x).const.type.list.element_type: %v", dn, test.constID, err)
continue
}
if etyp.Which() != schema.Type_Which_structType {
t.Errorf("(%s @%#x).const.type is a %v; want struct", dn, test.constID, etyp.Which())
continue
}
tid := etyp.StructType().TypeId()
v, err := c.Const().Value()
if err != nil {
t.Errorf("(%s @%#x).const.value: %v", dn, test.constID, err)
continue
}
if v.Which() != schema.Value_Which_list {
t.Errorf("(%s @%#x).const.value is a %v; want list", dn, test.constID, v.Which())
continue
}
lv, err := v.ListPtr()
if err != nil {
t.Errorf("(%s @%#x).const.value.list: %v", dn, test.constID, err)
continue
}
buf := new(bytes.Buffer)
enc := NewEncoder(buf)
enc.UseRegistry(reg)
if err := enc.EncodeList(tid, lv.List()); err != nil {
t.Errorf("Encode(%#x, (%s @%#x).const.value.list): %v", tid, dn, test.constID, err)
continue
}
if text := buf.String(); text != test.text {
t.Errorf("Encode(%#x, (%s @%#x).const.value.list) = %q; want %q", tid, dn, test.constID, text, test.text)
continue
}
}
}

View File

@@ -1,76 +0,0 @@
@0x8ae03d633330d781;
struct KeyValue @0x8df8bc5abdc060a6 {
key @0 :Text;
value @1 :Value;
}
struct Value @0xd3602730c572a43b {
union {
void @0 :Void;
bool @1 :Bool;
int8 @2 :Int8;
int16 @3 :Int16;
int32 @4 :Int32;
int64 @5 :Int64;
uint8 @6 :UInt8;
uint16 @7 :UInt16;
uint32 @8 :UInt32;
uint64 @9 :UInt64;
float32 @10 :Float32;
float64 @11 :Float64;
text @12 :Text;
data @13 :Data;
cheese @29 :Cheese;
map @14 :List(KeyValue);
voidList @15 :List(Void);
boolList @16 :List(Bool);
int8List @17 :List(Int8);
int16List @18 :List(Int16);
int32List @19 :List(Int32);
int64List @20 :List(Int64);
uint8List @21 :List(UInt8);
uint16List @22 :List(UInt16);
uint32List @23 :List(UInt32);
uint64List @24 :List(UInt64);
float32List @25 :List(Float32);
float64List @26 :List(Float64);
textList @27 :List(Text);
dataList @28 :List(Data);
cheeseList @30 :List(Cheese);
matrix @31 :List(List(Int32));
}
}
enum Cheese {
cheddar @0;
gouda @1;
}
const kv @0xc0b634e19e5a9a4e :KeyValue = (key = "42", value = (int32 = -123));
const floatKv @0x967c8fe21790b0fb :KeyValue = (key = "float", value = (float64 = 3.14));
const boolKv @0xdf35cb2e1f5ea087 :KeyValue = (key = "bool", value = (bool = false));
const mapVal @0xb167974479102805 :Value = (map = [
(key = "foo", value = (void = void)),
(key = "bar", value = (void = void)),
]);
const data @0x8e85252144f61858 :Value = (data = 0x"4869 dead beef cafe");
const emptyMap @0x81fdbfdc91779421 :Value = (map = []);
const voidList @0xc21398a8474837ba :Value = (voidList = [void, void]);
const boolList @0xde82c2eeb3a4b07c :Value = (boolList = [true, false, true, false]);
const int8List @0xf9e3ffc179272aa2 :Value = (int8List = [1, -2, 3]);
const int64List @0xfc421b96ec6ad2b6 :Value = (int64List = [1, -2, 3]);
const uint8List @0xb3034b89d02775a5 :Value = (uint8List = [255, 0, 1]);
const uint64List @0x9246c307e46ad03b :Value = (uint64List = [1, 2, 3]);
const floatList @0xd012128a1a9cb7fc :Value = (float32List = [0.5, 3.14, -2.0]);
const textList @0xf16c386c66d492e2 :Value = (textList = ["foo", "bar", "baz"]);
const dataList @0xe14f4d42aa55de8c :Value = (dataList = [0x"deadbeef", 0x"cafe"]);
const cheese @0xe88c91698f7f0b73 :Value = (cheese = gouda);
const cheeseList @0x9c51b843b337490b :Value = (cheeseList = [gouda, cheddar]);
const matrix @0x81e2aadb8bfb237b :Value = (matrix = [[1, 2, 3], [4, 5, 6]]);
const kvList @0x90c9e81e6418df8e :List(KeyValue) = [
(key = "foo", value = (void = void)),
(key = "bar", value = (void = void)),
];