コード例 #1
0
ファイル: overrides_test.go プロジェクト: luizbafilho/fusis
// overrideFromLayer performs the sequential override and low-level checks.
//
// First assignment is made on layer l for path firstPath with value firstValue,
// the second one on the override layer (i.e., with the Set() function)
// for path secondPath with value secondValue.
//
// firstPath and secondPath can include an arbitrary number of dots to indicate
// a nested element.
//
// After each assignment, the value is checked, retrieved both by its full path
// and by its key sequence (successive maps).
func overrideFromLayer(l layer, assert *assert.Assertions, firstPath string, firstValue interface{}, secondPath string, secondValue interface{}) *Viper {
	v := New()
	firstKeys := strings.Split(firstPath, v.keyDelim)
	if assert == nil ||
		len(firstKeys) == 0 || len(firstKeys[0]) == 0 {
		return v
	}

	// Set and check first value
	switch l {
	case defaultLayer:
		v.SetDefault(firstPath, firstValue)
	case overrideLayer:
		v.Set(firstPath, firstValue)
	default:
		return v
	}
	assert.Equal(firstValue, v.Get(firstPath))
	deepCheckValue(assert, v, l, firstKeys, firstValue)

	// Override and check new value
	secondKeys := strings.Split(secondPath, v.keyDelim)
	if len(secondKeys) == 0 || len(secondKeys[0]) == 0 {
		return v
	}
	v.Set(secondPath, secondValue)
	assert.Equal(secondValue, v.Get(secondPath))
	deepCheckValue(assert, v, overrideLayer, secondKeys, secondValue)

	return v
}
コード例 #2
0
ファイル: api_test.go プロジェクト: gurre/nordnet
// Assert Order type
func assertOrder(assert *assert.Assertions, order *OrderReply) {
	assert.EqualValues(123, order.OrderId)
	assert.Equal("test", order.ResultCode)
	assert.Equal("test", order.OrderState)
	assert.Equal("test", order.ActionState)
	assert.Equal("test", order.Message)
}
コード例 #3
0
ファイル: router_test.go プロジェクト: smancke/guble
func assertChannelContainsMessage(a *assert.Assertions, c <-chan *protocol.Message, msg []byte) {
	select {
	case m := <-c:
		a.Equal(string(msg), string(m.Body))
	case <-time.After(time.Millisecond * 5):
		a.Fail("No message received")
	}
}
コード例 #4
0
ファイル: router_test.go プロジェクト: mley/guble
func assertChannelContainsMessage(a *assert.Assertions, c chan MsgAndRoute, msg []byte) {
	//log.Println("DEBUG: start assertChannelContainsMessage-> select")
	select {
	case msgBack := <-c:
		a.Equal(string(msg), string(msgBack.Message.Body))
	case <-time.After(time.Millisecond):
		a.Fail("No message received")
	}
}
コード例 #5
0
func messagePartitionReader(name string, a *assert.Assertions, store *MessagePartition, n int, done chan bool) {
	lastReadMessage := 0
	for lastReadMessage < n {

		msgC := make(chan MessageAndId)
		errorC := make(chan error)

		log.WithFields(log.Fields{
			"module":      "testing",
			"name":        name,
			"lastReadMsg": lastReadMessage + 1,
		}).Debug("Start fetching at")

		store.Fetch(FetchRequest{
			Partition:     "myMessages",
			StartId:       uint64(lastReadMessage + 1),
			Direction:     1,
			Count:         math.MaxInt32,
			MessageC:      msgC,
			ErrorCallback: errorC,
			StartCallback: make(chan int, 1),
		})

	fetch:

		for {
			select {
			case msgAndId, open := <-msgC:
				if !open {

					log.WithFields(log.Fields{
						"module":      "testing",
						"name":        name,
						"lastReadMsg": lastReadMessage,
					}).Debug("Stop fetching at")

					break fetch
				}
				a.Equal(lastReadMessage+1, int(msgAndId.Id))
				lastReadMessage = int(msgAndId.Id)
			case err := <-errorC:
				a.Fail("received error", err.Error())
				<-done
				return
			}
		}

	}
	log.WithFields(log.Fields{
		"module":      "testing",
		"name":        name,
		"lastReadMsg": lastReadMessage,
	}).Debug("Ready got id")

	done <- true
}
コード例 #6
0
ファイル: receiver_test.go プロジェクト: tkrille/guble
func expectMessages(a *assert.Assertions, msgChannel chan []byte, message ...string) {
	for _, m := range message {
		select {
		case msg := <-msgChannel:
			a.Equal(m, string(msg))
		case <-time.After(time.Millisecond * 100):
			a.Fail("timeout: " + m)
		}
	}
}
コード例 #7
0
func messagePartitionReader(name string, a *assert.Assertions, mStore *messagePartition, n int, done chan bool) {
	lastReadMessage := 0

	for lastReadMessage < n {
		msgC := make(chan *store.FetchedMessage, 10)
		errorC := make(chan error)

		log.WithFields(log.Fields{
			"module":      "testing",
			"name":        name,
			"lastReadMsg": lastReadMessage + 1,
		}).Debug("Start fetching")

		mStore.Fetch(&store.FetchRequest{
			Partition: "myMessages",
			StartID:   uint64(lastReadMessage + 1),
			Direction: 1,
			Count:     math.MaxInt32,
			MessageC:  msgC,
			ErrorC:    errorC,
			StartC:    make(chan int, 1),
		})

	FETCH:
		for {
			select {
			case msgAndID, open := <-msgC:
				if !open {
					log.WithFields(log.Fields{
						"module":      "testing",
						"name":        name,
						"lastReadMsg": lastReadMessage,
					}).Debug("Stop fetching")
					break FETCH
				}
				a.Equal(lastReadMessage+1, int(msgAndID.ID), "Reader: "+name)
				lastReadMessage = int(msgAndID.ID)
			case err := <-errorC:
				a.Fail("received error", err.Error())
				<-done
				return
			}
		}
	}

	log.WithFields(log.Fields{
		"module":      "testing",
		"name":        name,
		"lastReadMsg": lastReadMessage,
	}).Debug("Ready got id")

	done <- true
}
コード例 #8
0
ファイル: client_test.go プロジェクト: ClusterHQ/flocker-go
func mockGetStateNodes(assert *assert.Assertions, data []byte) *Client {

	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		assert.Equal("GET", r.Method)
		assert.Equal("/v1/state/nodes", r.URL.Path)
		w.Write(data)
	}))

	host, port, err := getHostAndPortFromTestServer(ts)
	assert.NoError(err)

	c := newFlockerTestClient(host, port)

	return c
}
コード例 #9
0
ファイル: api_test.go プロジェクト: gurre/nordnet
// Assert Indicator type
func assertIndicator(assert *assert.Assertions, indicator *Indicator) {
	assert.Equal("test", indicator.Name)
	assert.Equal("test", indicator.Src)
	assert.Equal("test", indicator.Identifier)
	assert.EqualValues(123, indicator.Delayed)
	assert.Equal(true, indicator.OnlyEod)
	assert.Equal("test", indicator.Open)
	assert.Equal("test", indicator.Close)
	assert.Equal("test", indicator.Country)
	assert.Equal("test", indicator.Type)
	assert.Equal("test", indicator.Region)
	assert.EqualValues(123, indicator.InstrumentId)
}
コード例 #10
0
func checkRelationship(assert *assert.Assertions, contentID string, platformVersion string) {
	countQuery := `Match (t:Thing {uuid: {contentID}})-[r {lifecycle: {lifecycle}}]-(x) return count(r) as c`

	results := []struct {
		Count int `json:"c"`
	}{}

	qs := &neoism.CypherQuery{
		Statement:  countQuery,
		Parameters: neoism.Props{"contentID": contentID, "lifecycle": "annotations-" + platformVersion},
		Result:     &results,
	}

	err := annotationsDriver.conn.CypherBatch([]*neoism.CypherQuery{qs})
	assert.NoError(err)
	assert.Equal(1, len(results), "More results found than expected!")
	assert.Equal(1, results[0].Count, "No Relationship with Lifecycle found!")
}
コード例 #11
0
ファイル: map_test.go プロジェクト: arv/noms-old
func testMapOrder(assert *assert.Assertions, keyType, valueType Type, tuples []Value, expectOrdering []Value) {
	mapTr := MakeCompoundType(MapKind, keyType, valueType)
	m := NewTypedMap(mapTr, tuples...)
	i := 0
	m.IterAll(func(key, value Value) {
		assert.Equal(expectOrdering[i].Ref().String(), key.Ref().String())
		i++
	})
}
コード例 #12
0
ファイル: compound_blob_test.go プロジェクト: arv/noms-old
func testByteRange(assert *assert.Assertions, offset, length int64, expect io.ReadSeeker, actual io.ReadSeeker) {
	n, err := expect.Seek(offset, 0)
	assert.Equal(offset, n)
	assert.NoError(err)

	b1 := &bytes.Buffer{}
	n, err = io.CopyN(b1, expect, length)
	assert.Equal(length, n)
	assert.NoError(err)

	n, err = actual.Seek(offset, 0)
	assert.Equal(offset, n)
	assert.NoError(err)

	b2 := &bytes.Buffer{}
	n, err = io.CopyN(b2, actual, length)
	assert.Equal(length, n)
	assert.NoError(err)

	assert.Equal(b1.Bytes(), b2.Bytes())
}
コード例 #13
0
ファイル: common_test.go プロジェクト: cosminrentea/guble
func asserChannelContainsEntries(a *assert.Assertions, entryC chan [2]string, expectedEntries ...[2]string) {
	allEntries := make([][2]string, 0)

loop:
	for {
		select {
		case entry, ok := <-entryC:
			if !ok {
				break loop
			}
			allEntries = append(allEntries, entry)
		case <-time.After(time.Second):
			a.Fail("timeout")
		}
	}

	a.Equal(len(expectedEntries), len(allEntries))
	for _, expected := range expectedEntries {
		a.Contains(allEntries, expected)
	}
}
コード例 #14
0
ファイル: common_test.go プロジェクト: smancke/guble
func assertChannelContains(a *assert.Assertions, entryC chan string, expectedEntries ...string) {
	var allEntries []string

WAITLOOP:
	for {
		select {
		case entry, ok := <-entryC:
			if !ok {
				break WAITLOOP
			}
			allEntries = append(allEntries, entry)
		case <-time.After(time.Second):
			a.Fail("timeout")
		}
	}

	a.Equal(len(expectedEntries), len(allEntries))
	for _, expected := range expectedEntries {
		a.Contains(allEntries, expected)
	}
}
コード例 #15
0
func messagePartitionReader(name string, a *assert.Assertions, store *MessagePartition, n int, done chan bool) {
	lastReadMessage := 0
	for lastReadMessage < n {

		msgC := make(chan MessageAndId)
		errorC := make(chan error)

		guble.Debug("[%v] start fetching at: %v", name, lastReadMessage+1)
		store.Fetch(FetchRequest{
			Partition:     "myMessages",
			StartId:       uint64(lastReadMessage + 1),
			Direction:     1,
			Count:         math.MaxInt32,
			MessageC:      msgC,
			ErrorCallback: errorC,
			StartCallback: make(chan int, 1),
		})

	fetch:

		for {
			select {
			case msgAndId, open := <-msgC:
				if !open {
					guble.Debug("[%v] stop fetching at %v", name, lastReadMessage)
					break fetch
				}
				a.Equal(lastReadMessage+1, int(msgAndId.Id))
				lastReadMessage = int(msgAndId.Id)
			case err := <-errorC:
				a.Fail("received error", err.Error())
				<-done
				return
			}
		}

	}
	guble.Debug("[%v] ready, got %v", name, lastReadMessage)
	done <- true
}
コード例 #16
0
ファイル: overrides_test.go プロジェクト: luizbafilho/fusis
// deepCheckValue checks that all given keys correspond to a valid path in the
// configuration map of the given layer, and that the final value equals the one given
func deepCheckValue(assert *assert.Assertions, v *Viper, l layer, keys []string, value interface{}) {
	if assert == nil || v == nil ||
		len(keys) == 0 || len(keys[0]) == 0 {
		return
	}

	// init
	var val interface{}
	var ms string
	switch l {
	case defaultLayer:
		val = v.defaults
		ms = "v.defaults"
	case overrideLayer:
		val = v.override
		ms = "v.override"
	}

	// loop through map
	var m map[string]interface{}
	err := false
	for _, k := range keys {
		if val == nil {
			assert.Fail(fmt.Sprintf("%s is not a map[string]interface{}", ms))
			return
		}

		// deep scan of the map to get the final value
		switch val.(type) {
		case map[interface{}]interface{}:
			m = cast.ToStringMap(val)
		case map[string]interface{}:
			m = val.(map[string]interface{})
		default:
			assert.Fail(fmt.Sprintf("%s is not a map[string]interface{}", ms))
			return
		}
		ms = ms + "[\"" + k + "\"]"
		val = m[k]
	}
	if !err {
		assert.Equal(value, val)
	}
}
コード例 #17
0
ファイル: compliance_test.go プロジェクト: CNDonny/scope
func runTestCase(assert *assert.Assertions, given interface{}, testcase TestCase, filename string) {
	lexer := NewLexer()
	var err error
	_, err = lexer.tokenize(testcase.Expression)
	if err != nil {
		errMsg := fmt.Sprintf("(%s) Could not lex expression: %s -- %s", filename, testcase.Expression, err.Error())
		assert.Fail(errMsg)
		return
	}
	parser := NewParser()
	_, err = parser.Parse(testcase.Expression)
	if err != nil {
		errMsg := fmt.Sprintf("(%s) Could not parse expression: %s -- %s", filename, testcase.Expression, err.Error())
		assert.Fail(errMsg)
		return
	}
	actual, err := Search(testcase.Expression, given)
	if assert.Nil(err, fmt.Sprintf("Expression: %s", testcase.Expression)) {
		assert.Equal(testcase.Result, actual, fmt.Sprintf("Expression: %s", testcase.Expression))
	}
}
コード例 #18
0
ファイル: test_utils.go プロジェクト: arv/noms-old
func assertInputInStore(input string, ref ref.Ref, s ChunkStore, assert *assert.Assertions) {
	chunk := s.Get(ref)
	assert.False(chunk.IsEmpty(), "Shouldn't get empty chunk for %s", ref.String())
	assert.Equal(input, string(chunk.Data()))
}
コード例 #19
0
ファイル: hash_test.go プロジェクト: evalphobia/wizard
func testAssertInt64(a *assert.Assertions, v interface{}) {
	a.Equal(int64(99), getInt64(v))
}
コード例 #20
0
ファイル: fcm_integration_test.go プロジェクト: smancke/guble
func assertMetrics(a *assert.Assertions, s *service.Service, expected expectedValues) {
	httpClient := &http.Client{}
	u := fmt.Sprintf("http://%s%s", s.WebServer().GetAddr(), defaultMetricsEndpoint)
	request, err := http.NewRequest(http.MethodGet, u, nil)
	a.NoError(err)

	response, err := httpClient.Do(request)
	a.NoError(err)
	defer response.Body.Close()

	a.Equal(http.StatusOK, response.StatusCode)
	bodyBytes, err := ioutil.ReadAll(response.Body)
	a.NoError(err)
	logger.WithField("body", string(bodyBytes)).Debug("metrics response")

	mFCM := &fcmMetrics{}
	err = json.Unmarshal(bodyBytes, mFCM)
	a.NoError(err)

	a.Equal(0, mFCM.TotalSentMessageErrors)
	a.Equal(expected.MessageCount, mFCM.TotalSentMessages)

	a.Equal(0, mFCM.Minute.CurrentErrorsCount)
	a.Equal(expected.MessageCount, mFCM.Minute.CurrentMessagesCount)
	a.Equal(0, mFCM.Minute.CurrentErrorsTotalLatencies)
	a.Equal(expected.ZeroLatencies, mFCM.Minute.CurrentMessagesTotalLatencies == 0)

	a.Equal(0, mFCM.Hour.CurrentErrorsCount)
	a.Equal(expected.MessageCount, mFCM.Hour.CurrentMessagesCount)
	a.Equal(0, mFCM.Hour.CurrentErrorsTotalLatencies)
	a.Equal(expected.ZeroLatencies, mFCM.Hour.CurrentMessagesTotalLatencies == 0)

	a.Equal(0, mFCM.Day.CurrentErrorsCount)
	a.Equal(expected.MessageCount, mFCM.Day.CurrentMessagesCount)
	a.Equal(0, mFCM.Day.CurrentErrorsTotalLatencies)
	a.Equal(expected.ZeroLatencies, mFCM.Day.CurrentMessagesTotalLatencies == 0)

	mRouter := &routerMetrics{}
	err = json.Unmarshal(bodyBytes, mRouter)
	a.NoError(err)

	a.Equal(expected.CurrentRoutes, mRouter.CurrentRoutes)
	a.Equal(expected.CurrentSubscriptions, mRouter.CurrentSubscriptions)
}
コード例 #21
0
ファイル: common_test.go プロジェクト: cosminrentea/guble
func assertGet(a *assert.Assertions, s KVStore, schema string, key string, expectedValue []byte) {
	val, exist, err := s.Get(schema, key)
	a.NoError(err)
	a.True(exist)
	a.Equal(expectedValue, val)
}
コード例 #22
0
ファイル: gubled_test.go プロジェクト: mley/guble
func assertArguments(a *assert.Assertions, args Args) {
	a.Equal("listen", args.Listen)
	a.Equal(true, args.LogInfo)
	a.Equal(true, args.LogDebug)
	a.Equal("kv-backend", args.KVBackend)
	a.Equal("storage-path", args.StoragePath)
	a.Equal("ms-backend", args.MSBackend)
	a.Equal("gcm-api-key", args.GcmApiKey)
	a.Equal(true, args.GcmEnable)
}
コード例 #23
0
ファイル: api_test.go プロジェクト: gurre/nordnet
// Assert Instrument type
func assertInstrument(assert *assert.Assertions, instrument *Instrument) {
	assert.EqualValues(123, instrument.InstrumentId)

	assert.NotEmpty(instrument.Tradables)
	tradable := instrument.Tradables[0]

	assert.EqualValues(123, tradable.MarketId)
	assert.Equal("test", tradable.Identifier)
	assert.EqualValues(123, tradable.TickSizeId)
	assert.Equal(1.1, tradable.LotSize)
	assert.EqualValues(123, tradable.DisplayOrder)

	assert.Equal("test", instrument.Currency)
	assert.Equal("test", instrument.InstrumentGroupType)
	assert.Equal("test", instrument.InstrumentType)
	assert.Equal(1.1, instrument.Multiplier)
	assert.Equal("test", instrument.Symbol)
	assert.Equal("test", instrument.IsinCode)
	assert.Equal("test", instrument.MarketView)
	assert.Equal(1.1, instrument.StrikePrice)
	assert.Equal(1.1, instrument.NumberOfSecurities)
	assert.Equal("test", instrument.ProspectusUrl)
	assert.Equal("test", instrument.ExpirationDate)
	assert.Equal("test", instrument.Name)
	assert.Equal("test", instrument.Sector)
	assert.Equal("test", instrument.SectorGroup)

	assert.NotEmpty(instrument.Underlyings)
	underlying := instrument.Underlyings[0]

	assert.EqualValues(123, underlying.InstrumentId)
	assert.Equal("test", underlying.Symbol)
	assert.Equal("test", underlying.IsinCode)
}
コード例 #24
0
ファイル: board_test.go プロジェクト: rjhacks/Atlantis
func VerifyDeserializedBoard(b *Board, assert *assert.Assertions) {
	assert.Equal(4, len(b.Segments))
	assert.Equal(4*7, len(b.Points))

	pos := Position{X: 6, Y: 6}
	assert.Equal(pos, b.Points[pos].Position)
	assert.Equal(false, b.Points[pos].IsDead)
	assert.Equal(0, b.Points[pos].Tower.Player)
	assert.Equal(1, b.Points[pos].Tower.Height)
	assert.Equal(false, b.Points[pos].Tower.IsGrowingPoint)

	pos = Position{X: 7, Y: 7}
	assert.Equal(pos, b.Points[pos].Position)
	assert.Equal(false, b.Points[pos].IsDead)
	assert.Equal(0, b.Points[pos].Tower.Player)
	assert.Equal(2, b.Points[pos].Tower.Height)
	assert.Equal(true, b.Points[pos].Tower.IsGrowingPoint)

	pos = Position{X: 10, Y: 5}
	assert.Equal(pos, b.Points[pos].Position)
	assert.Equal(false, b.Points[pos].IsDead)
	assert.Equal(1, b.Points[pos].Tower.Player)
	assert.Equal(1, b.Points[pos].Tower.Height)
	assert.Equal(false, b.Points[pos].Tower.IsGrowingPoint)

	pos = Position{X: 11, Y: 6}
	assert.Equal(pos, b.Points[pos].Position)
	assert.Equal(false, b.Points[pos].IsDead)
	assert.Equal(1, b.Points[pos].Tower.Player)
	assert.Equal(2, b.Points[pos].Tower.Height)
	assert.Equal(true, b.Points[pos].Tower.IsGrowingPoint)

	pos = Position{X: 8, Y: 5}
	assert.Equal(pos, b.Points[pos].Position)
	assert.Equal(true, b.Points[pos].IsDead)

	pos = Position{X: 10, Y: 8}
	assert.Equal(pos, b.Points[pos].Position)
	assert.Equal(true, b.Points[pos].IsDead)

	assert.NotEqual("", b.DebugString())
}