<commit_before>// Copyright 2014 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package base

import (
	"bytes"
	"reflect"
	"testing"
	"time"

	"golang.org/x/net/context"
)

var ctx = context.Background()

func testPacketData(t *testing.T) []*Packet {
	var ci = []struct {
		Timestamp     time.Time
		CaptureLength int
		Length        int
	}{
		{time.Unix(123, 123), 3, 3},
		{time.Unix(456, 456), 3, 3},
		{time.Unix(789, 789), 3, 3},
	}

	out := []*Packet{&Packet{[]byte{1, 2, 3}, ci[0]},
		&Packet{[]byte{4, 5, 6}, ci[1]},
		&Packet{[]byte{7, 8, 9}, ci[2]}}
	return out
}

func comparePacketChans(t *testing.T, want, got *PacketChan) {
	for {
		p1, ok1 := <-want.Receive()
		p2, ok2 := <-got.Receive()
		if !ok1 || !ok2 {
			if ok1 != ok2 {
				t.Errorf("missing packet:\nwant:%v\ngot:%v\n", p1, p2)
			}
			break
		}
		if p1 != p2 {
			t.Errorf("wrong packet\nwant:%v\ngot:%v\n", p1, p2)
		}
	}
}

func TestConcatPacketChans(t *testing.T) {
	packets := testPacketData(t)
	inputs := make(chan *PacketChan, 2)
	one := NewPacketChan(100)
	two := NewPacketChan(100)
	one.Send(packets[0])
	two.Send(packets[1])<commit_msg>Fix base_test after gopacket change.<commit_after>// Copyright 2014 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package base

import (
	"bytes"
	"reflect"
	"testing"
	"time"

	"github.com/google/gopacket"
	"golang.org/x/net/context"
)

var ctx = context.Background()

func testPacketData(t *testing.T) []*Packet {
	var ci = []gopacket.CaptureInfo{
		{Timestamp: time.Unix(123, 123), CaptureLength: 3, Length: 3},
		{Timestamp: time.Unix(456, 456), CaptureLength: 3, Length: 3},
		{Timestamp: time.Unix(789, 789), CaptureLength: 3, Length: 3},
	}

	out := []*Packet{&Packet{[]byte{1, 2, 3}, ci[0]},
		&Packet{[]byte{4, 5, 6}, ci[1]},
		&Packet{[]byte{7, 8, 9}, ci[2]}}
	return out
}

func comparePacketChans(t *testing.T, want, got *PacketChan) {
	for {
		p1, ok1 := <-want.Receive()
		p2, ok2 := <-got.Receive()
		if !ok1 || !ok2 {
			if ok1 != ok2 {
				t.Errorf("missing packet:\nwant:%v\ngot:%v\n", p1, p2)
			}
			break
		}
		if p1 != p2 {
			t.Errorf("wrong packet\nwant:%v\ngot:%v\n", p1, p2)
		}
	}
}

func TestConcatPacketChans(t *testing.T) {
	packets := testPacketData(t)
	inputs := make(chan *PacketChan, 2)
	one := NewPacketChan(100)
	two := NewPacketChan(100)
	one.Send(packets[0])
	two.Send(packets[1])
{'fraction_non_alphanumeric': 0.15947521865889214, 'fraction_numerical': 0.03906705539358601, 'mean_word_length': 3.611559139784946, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7103273', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1236, 'n_words': 373}