コード例 #1
0
ファイル: mock.go プロジェクト: 2722/lantern
// Diff gets a string describing the differences between the arguments
// and the specified objects.
//
// Returns the diff string and number of differences found.
func (args Arguments) Diff(objects []interface{}) (string, int) {

	var output string = "\n"
	var differences int

	var maxArgCount int = len(args)
	if len(objects) > maxArgCount {
		maxArgCount = len(objects)
	}

	for i := 0; i < maxArgCount; i++ {
		var actual, expected interface{}

		if len(objects) <= i {
			actual = "(Missing)"
		} else {
			actual = objects[i]
		}

		if len(args) <= i {
			expected = "(Missing)"
		} else {
			expected = args[i]
		}

		if reflect.TypeOf(expected) == reflect.TypeOf((*AnythingOfTypeArgument)(nil)).Elem() {

			// type checking
			if reflect.TypeOf(actual).Name() != string(expected.(AnythingOfTypeArgument)) && reflect.TypeOf(actual).String() != string(expected.(AnythingOfTypeArgument)) {
				// not match
				differences++
				output = fmt.Sprintf("%s\t%d: \u274C  type %s != type %s - %s\n", output, i, expected, reflect.TypeOf(actual).Name(), actual)
			}

		} else {

			// normal checking

			if assert.ObjectsAreEqual(expected, Anything) || assert.ObjectsAreEqual(actual, Anything) || assert.ObjectsAreEqual(actual, expected) {
				// match
				output = fmt.Sprintf("%s\t%d: \u2705  %s == %s\n", output, i, actual, expected)
			} else {
				// not match
				differences++
				output = fmt.Sprintf("%s\t%d: \u274C  %s != %s\n", output, i, actual, expected)
			}
		}

	}

	if differences == 0 {
		return "No differences.", differences
	}

	return output, differences

}
コード例 #2
0
ファイル: entity_test.go プロジェクト: yarbelk/ecs
func TestSortableIdentifierSlice(t *testing.T) {
	e1 := MyEntity1{}
	e1.BasicEntity = NewBasic()
	e2 := MyEntity1{}
	e2.BasicEntity = NewBasic()

	var entities IdentifierSlice = []Identifier{e2, e1}
	sort.Sort(entities)
	assert.ObjectsAreEqual(e1, entities[0])
	assert.ObjectsAreEqual(e2, entities[1])
}
コード例 #3
0
ファイル: load_test.go プロジェクト: nelsam/atomicgames
func (suite *datastoreTestSuite) TestGetModelsWithKeys() {
	srcModels := loadTestData(suite.GAEContext)

	destModels := make([]models.Model, 5)
	destTest := make([]*testModel, 5)
	var (
		key *datastore.Key
		err error
	)
	for index, _ := range destTest {
		key, err = srcModels[index].Key()
		destTest[index] = new(testModel)
		destTest[index].SetKey(key)
		destModels[index] = destTest[index]
	}

	err = GetModelsWithKeys(suite.GAEContext, destModels)
	assert.Nil(suite.T, err, "GetModelsWithKeys shouldn't error")
	for index, model := range destTest {
		assert.ObjectsAreEqual(model, srcModels[index])
		key, err = model.Key()
		assert.Nil(suite.T, err, "Models should have keys after running Get")
		assert.NotNil(suite.T, key, "Models should have keys after running Get")
	}
}
コード例 #4
0
ファイル: dns_tcp_test.go プロジェクト: jarpy/beats
// parseTcpRequestResponse parses a request then a response packet and validates
// the published result.
func parseTcpRequestResponse(t testing.TB, dns *Dns, q DnsTestMessage) {
	var private protos.ProtocolData
	packet := newPacket(forward, q.request)
	tcptuple := testTcpTuple()
	private = dns.Parse(packet, tcptuple, tcp.TcpDirectionOriginal, private)

	packet = newPacket(reverse, q.response)
	dns.Parse(packet, tcptuple, tcp.TcpDirectionReverse, private)

	assert.Empty(t, dns.transactions.Size(), "There should be no transactions.")

	m := expectResult(t, dns)
	assert.Equal(t, "tcp", mapValue(t, m, "transport"))
	assert.Equal(t, len(q.request), mapValue(t, m, "bytes_in"))
	assert.Equal(t, len(q.response), mapValue(t, m, "bytes_out"))
	assert.NotNil(t, mapValue(t, m, "responsetime"))

	if assert.ObjectsAreEqual("NOERROR", mapValue(t, m, "dns.response_code")) {
		assert.Equal(t, common.OK_STATUS, mapValue(t, m, "status"))
	} else {
		assert.Equal(t, common.ERROR_STATUS, mapValue(t, m, "status"))
	}

	assert.Nil(t, mapValue(t, m, "notes"))
	assertMapStrData(t, m, q)
}
コード例 #5
0
ファイル: varnishlog_test.go プロジェクト: AlekSi/varnishlog
func assertHasLine(t *testing.T, tr Transaction, expected Line) {
	for _, l := range tr.Lines {
		if assert.ObjectsAreEqual(expected, l) {
			return
		}
	}
	assert.Fail(t, "line not found", expected.String())
}
コード例 #6
0
func TestGetDocument(t *testing.T) {
	es := newEsTestClient(t).recreateIndex(estestIndex)
	id := "1"
	doc := map[string]interface{}{"name": id}
	es.putDocument(estestIndex, estestType, id, "", doc)
	returned := es.getDocumentMap(estestIndex, estestType, id, "")
	assert.ObjectsAreEqual(doc, returned)
}
コード例 #7
0
ファイル: config_test.go プロジェクト: ch3lo/crane
func (suite *ConfigSuite) TestMarshalRoundtrip() {
	configBytes, err := yaml.Marshal(suite.expectedConfig)
	assert.Nil(suite.T(), err)
	var config Configuration
	err = yaml.Unmarshal(configBytes, &config)
	assert.Nil(suite.T(), err)
	assert.True(suite.T(), assert.ObjectsAreEqual(config, suite.expectedConfig))
}
コード例 #8
0
ファイル: values.go プロジェクト: pgrunde/sol
// Diff returns the values in v that differ from the values in other.
// ISO 31-11: v \ other
func (v Values) Diff(other Values) Values {
	diff := Values{}
	for key, value := range v {
		if !assert.ObjectsAreEqual(value, other[key]) {
			diff[key] = value
		}
	}
	return diff
}
コード例 #9
0
ファイル: command_test.go プロジェクト: subnr01/epaxos
func TestCommandClone(t *testing.T) {
	nilCmds := Commands(nil)
	assert.Equal(t, nilCmds.Clone(), Commands(nil))
	manyCmds := Commands{
		Command("1"),
		Command("2"),
	}
	assert.True(t,
		assert.ObjectsAreEqual(manyCmds.Clone(), manyCmds),
	)
}
コード例 #10
0
ファイル: load_test.go プロジェクト: nelsam/atomicgames
func (suite *datastoreTestSuite) TestGetModel() {
	models := loadTestData(suite.GAEContext)

	src := models[0]
	key, err := src.Key()
	assert.NotNil(suite.T, key, "The src model should have its key set")

	dest := new(testModel)
	err = GetModel(suite.GAEContext, key, dest)
	assert.Nil(suite.T, err, "GetModel shouldn't return an error")
	assert.ObjectsAreEqual(src, dest)
}
コード例 #11
0
func TestMultipleEncodingDecodeEvent(t *testing.T) {
	cases := []struct {
		ev *sse
	}{
		{ev},
		{newSSEEvent("102", "DUP")},
		{newSSEEvent("103", "FUN")},
	}

	r, w := io.Pipe()

	enc := newEncoder(w)
	assert.NotNil(t, enc)

	dec := newDecoder(r)
	assert.NotNil(t, dec)

	var wg sync.WaitGroup
	wg.Add(2)

	go func() {
		defer wg.Done()
		defer w.Close()

		for _, tc := range cases {
			err := enc.Encode(tc.ev)
			assert.Nil(t, err)
		}
	}()

	go func() {
		defer wg.Done()
		defer r.Close()

		for {
			inputEv, err := dec.Decode()
			if err == io.EOF {
				break
			}

			exists := false
			for _, tc := range cases {
				exists = exists || assert.ObjectsAreEqual(tc.ev, inputEv)
			}
			assert.NoError(t, err)
			assert.True(t, exists)
		}
	}()

	wg.Wait()

}
コード例 #12
0
ファイル: tester.go プロジェクト: pgrunde/sol
// SQL tests that the given Compiles instance matches the expected string for
// the current dialect.
func (t *tester) SQL(expect string, stmt Compiles, ps ...interface{}) {
	// Get caller information in case of failure
	caller := callerInfo()

	// Start a new parameters instance
	params := Params()

	// Compile the given stmt with the tester's dialect
	actual, err := stmt.Compile(t.dialect, params)
	if err != nil {
		t.t.Errorf("%s: unexpected error from Compile(): %s", caller, err)
		return
	}

	if expect != actual {
		t.t.Errorf(
			"%s: unexpected SQL from Compile(): expect %s, got %s",
			caller,
			expect,
			actual,
		)
	}
	// Test that the parameters are equal
	if len(*params) != len(ps) {
		t.t.Errorf(
			"%s: unexpected number of parameters for %s: expect %d, got %d",
			caller,
			actual,
			len(ps),
			len(*params),
		)
		return
	}

	// Examine individual parameters for equality
	for i, param := range *params {
		if !assert.ObjectsAreEqual(ps[i], param) {
			t.t.Errorf(
				"%s: unequal parameters at index %d: expect %#v, got %#v",
				caller,
				i,
				ps[i],
				param,
			)
		}
	}
}
コード例 #13
0
ファイル: dns_udp_test.go プロジェクト: ruflin/beats
// parseUdpRequestResponse parses a request then a response packet and validates
// the published result.
func parseUDPRequestResponse(t testing.TB, dns *dnsPlugin, q dnsTestMessage) {
	packet := newPacket(forward, q.request)
	dns.ParseUDP(packet)
	packet = newPacket(reverse, q.response)
	dns.ParseUDP(packet)
	assert.Empty(t, dns.transactions.Size(), "There should be no transactions.")

	m := expectResult(t, dns)
	assert.Equal(t, "udp", mapValue(t, m, "transport"))
	assert.Equal(t, len(q.request), mapValue(t, m, "bytes_in"))
	assert.Equal(t, len(q.response), mapValue(t, m, "bytes_out"))
	assert.NotNil(t, mapValue(t, m, "responsetime"))

	if assert.ObjectsAreEqual("NOERROR", mapValue(t, m, "dns.response_code")) {
		assert.Equal(t, common.OK_STATUS, mapValue(t, m, "status"))
	} else {
		assert.Equal(t, common.ERROR_STATUS, mapValue(t, m, "status"))
	}

	assert.Nil(t, mapValue(t, m, "notes"))
	assertMapStrData(t, m, q)
}
コード例 #14
0
ファイル: dns_test.go プロジェクト: nicoder/beats
// Verify that the split lone request packet is parsed.
func TestParseTcpSplitResponse(t *testing.T) {
	dns := newDns(testing.Verbose())
	tcpQuery := elasticATcp

	q := tcpQuery.request
	r0 := tcpQuery.response[:10]
	r1 := tcpQuery.response[10:]

	tcptuple := testTcpTuple()
	private := protos.ProtocolData(new(dnsPrivateData))

	packet := newPacket(forward, q)
	private = dns.Parse(packet, tcptuple, tcp.TcpDirectionOriginal, private)
	assert.Equal(t, 1, dns.transactions.Size(), "There should be one transaction.")

	packet = newPacket(reverse, r0)
	private = dns.Parse(packet, tcptuple, tcp.TcpDirectionReverse, private)
	assert.Equal(t, 1, dns.transactions.Size(), "There should be one transaction.")

	packet = newPacket(reverse, r1)
	private = dns.Parse(packet, tcptuple, tcp.TcpDirectionReverse, private)
	assert.Empty(t, dns.transactions.Size(), "There should be no transaction.")

	m := expectResult(t, dns)
	assert.Equal(t, "tcp", mapValue(t, m, "transport"))
	assert.Equal(t, len(tcpQuery.request), mapValue(t, m, "bytes_in"))
	assert.Equal(t, len(tcpQuery.response), mapValue(t, m, "bytes_out"))
	assert.NotNil(t, mapValue(t, m, "responsetime"))

	if assert.ObjectsAreEqual("NOERROR", mapValue(t, m, "dns.response_code")) {
		assert.Equal(t, common.OK_STATUS, mapValue(t, m, "status"))
	} else {
		assert.Equal(t, common.ERROR_STATUS, mapValue(t, m, "status"))
	}

	assert.Nil(t, mapValue(t, m, "notes"))
	assertMapStrData(t, m, tcpQuery)
}
コード例 #15
0
ファイル: shodan_test.go プロジェクト: ns3777k/go-shodan
func TestNewClient_httpClient(t *testing.T) {
	transport := &http.Transport{Proxy: http.ProxyFromEnvironment}
	httpClient := &http.Client{Transport: transport}
	client := NewClient(httpClient, testClientToken)
	assert.ObjectsAreEqual(httpClient, client.Client)
}
コード例 #16
0
ファイル: config_test.go プロジェクト: ch3lo/crane
func (suite *ConfigSuite) TestParseSimple() {
	var config Configuration
	err := yaml.Unmarshal([]byte(configYaml), &config)
	assert.Nil(suite.T(), err)
	assert.True(suite.T(), assert.ObjectsAreEqual(config, suite.expectedConfig))
}
コード例 #17
0
ファイル: ability_test.go プロジェクト: jbailey/ekcore
func Test_FindAbility(t *testing.T) {
	ability, ok := FindAbility("Fireball 3")

	assert.True(t, ok, "Fireball ability should be found")
	assert.ObjectsAreEqual(&Fireball{Level: 3}, ability)
}