當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.Specify方法代碼示例

本文整理匯總了Golang中github.com/rafrombrc/gospec/src/gospec.Context.Specify方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Specify方法的具體用法?Golang Context.Specify怎麽用?Golang Context.Specify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/rafrombrc/gospec/src/gospec.Context的用法示例。


在下文中一共展示了Context.Specify方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: StatsdInputSpec

func StatsdInputSpec(c gs.Context) {
	t := &pipeline_ts.SimpleT{}
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	pConfig := NewPipelineConfig(nil)
	ith := new(plugins_ts.InputTestHelper)
	ith.Msg = pipeline_ts.GetTestMessage()
	ith.Pack = NewPipelinePack(pConfig.InputRecycleChan())
	ith.PackSupply = make(chan *PipelinePack, 1)

	// Specify localhost, but we're not really going to use the network
	ith.AddrStr = "localhost:55565"
	ith.ResolvedAddrStr = "127.0.0.1:55565"

	// set up mock helper, input runner, and stat accumulator
	ith.MockHelper = NewMockPluginHelper(ctrl)
	ith.MockInputRunner = NewMockInputRunner(ctrl)
	mockStatAccum := NewMockStatAccumulator(ctrl)

	c.Specify("A StatsdInput", func() {
		statsdInput := StatsdInput{}
		config := statsdInput.ConfigStruct().(*StatsdInputConfig)

		config.Address = ith.AddrStr
		err := statsdInput.Init(config)
		c.Assume(err, gs.IsNil)
		realListener := statsdInput.listener
		c.Expect(realListener.LocalAddr().String(), gs.Equals, ith.ResolvedAddrStr)
		realListener.Close()
		mockListener := pipeline_ts.NewMockConn(ctrl)
		statsdInput.listener = mockListener

		ith.MockHelper.EXPECT().StatAccumulator("StatAccumInput").Return(mockStatAccum, nil)
		mockListener.EXPECT().Close()
		mockListener.EXPECT().SetReadDeadline(gomock.Any())

		c.Specify("sends a Stat to the StatAccumulator", func() {
			statName := "sample.count"
			statVal := 303
			msg := fmt.Sprintf("%s:%d|c\n", statName, statVal)
			expected := Stat{statName, strconv.Itoa(statVal), "c", float32(1)}
			mockStatAccum.EXPECT().DropStat(expected).Return(true)
			readCall := mockListener.EXPECT().Read(make([]byte, 512))
			readCall.Return(len(msg), nil)
			readCall.Do(func(msgBytes []byte) {
				copy(msgBytes, []byte(msg))
				statsdInput.Stop()
			})
			var wg sync.WaitGroup
			wg.Add(1)
			go func() {
				err = statsdInput.Run(ith.MockInputRunner, ith.MockHelper)
				c.Expect(err, gs.IsNil)
				wg.Done()
			}()
			wg.Wait()
		})
	})
}
開發者ID:josedonizetti,項目名稱:heka,代碼行數:60,代碼來源:statsd_input_test.go

示例2: FilterRunnerSpec

func FilterRunnerSpec(c gs.Context) {
	c.Specify("A filterrunner", func() {
		pConfig := NewPipelineConfig(nil)
		filter := &CounterFilter{}
		commonFO := CommonFOConfig{
			Matcher: "Type == 'bogus'",
		}
		chanSize := 10
		fRunner, err := NewFORunner("counterFilter", filter, commonFO, "CounterFilter",
			chanSize)
		fRunner.h = pConfig
		c.Assume(err, gs.IsNil)

		pack := NewPipelinePack(pConfig.injectRecycleChan)
		pConfig.injectRecycleChan <- pack
		pack.Message = ts.GetTestMessage()
		c.Assume(pack.TrustMsgBytes, gs.IsFalse)
		msgEncoding, err := proto.Marshal(pack.Message)
		c.Assume(err, gs.IsNil)

		c.Specify("puts protobuf encoding into MsgBytes before delivery", func() {
			result := fRunner.Inject(pack)
			c.Expect(result, gs.IsTrue)
			recd := <-pConfig.router.inChan
			c.Expect(recd, gs.Equals, pack)
			c.Expect(recd.TrustMsgBytes, gs.IsTrue)
			c.Expect(bytes.Equal(msgEncoding, recd.MsgBytes), gs.IsTrue)
		})
	})
}
開發者ID:Nitro,項目名稱:heka,代碼行數:30,代碼來源:plugin_runners_test.go

示例3: CheckTypeSpec

func CheckTypeSpec(c gs.Context) {
	var err error

	var tomlBlob = `
ranking = ["Springsteen", "J Geils"]

[bands.Springsteen]
type = "ignore_this"
started = 1973
albums = ["Greetings", "WIESS", "Born to Run", "Darkness"]
not_albums = ["Greetings", "WIESS", "Born to Run", "Darkness"]

[bands.J Geils]
started = 1970
albums = ["The J. Geils Band", "Full House", "Blow Your Face Out"]
`

	type classics struct {
		Ranking []string
		Bands   map[string]Primitive
	}

	c.Specify("check mapping", func() {
		// Do the initial decode. Reflection is delayed on Primitive values.
		var music classics
		var md MetaData
		md, err = Decode(tomlBlob, &music)
		c.Assume(err, gs.IsNil)

		empty_ignore := map[string]interface{}{}
		err = CheckType(md.mapping, music, empty_ignore)
		c.Assume(err, gs.IsNil)
	})
}
開發者ID:wanghe4096,項目名稱:toml,代碼行數:34,代碼來源:checktype_test.go

示例4: ElasticSearchOutputSpec

func ElasticSearchOutputSpec(c gs.Context) {
	c.Specify("Should properly encode special characters in json", func() {
		buf := bytes.Buffer{}
		writeStringField(true, &buf, `hello"bar`, "world\nfoo\\")
		c.Expect(buf.String(), gs.Equals, `"hello\u0022bar":"world\u000afoo\u005c"`)
	})

	c.Specify("Should replace invalid utf8 with replacement character", func() {
		buf := bytes.Buffer{}
		writeStringField(true, &buf, "\xa3", "\xa3")
		c.Expect(buf.String(), gs.Equals, "\"\xEF\xBF\xBD\":\"\xEF\xBF\xBD\"")
	})

	c.Specify("Should properly encode message using kibana formatter", func() {
		formatter := KibanaFormatter{}
		b, _ := formatter.Format(getTestMessageWithFunnyFields())

		decoded := make(map[string]interface{})

		err := json.Unmarshal(b, &decoded)

		c.Expect(err, gs.IsNil)
		c.Expect(decoded["@fields"].(map[string]interface{})[`"foo`], gs.Equals, "bar\n")
		c.Expect(decoded["@fields"].(map[string]interface{})[`"number`], gs.Equals, 64.0)
		c.Expect(decoded["@fields"].(map[string]interface{})["\xEF\xBF\xBD"], gs.Equals, "\xEF\xBF\xBD")

		c.Expect(decoded["@uuid"], gs.Equals, "87cf1ac2-e810-4ddf-a02d-a5ce44d13a85")
		c.Expect(decoded["@timestamp"], gs.Equals, "2013-07-16T15:49:05.070Z")
		c.Expect(decoded["@type"], gs.Equals, "TEST")
		c.Expect(decoded["@logger"], gs.Equals, "GoSpec")
		c.Expect(decoded["@severity"], gs.Equals, 6.0)
		c.Expect(decoded["@message"], gs.Equals, "Test Payload")
		c.Expect(decoded["@envversion"], gs.Equals, "0.8")
		c.Expect(decoded["@pid"], gs.Equals, 14098.0)
		c.Expect(decoded["@source_host"], gs.Equals, "hostname")
	})

	c.Specify("Should properly encode message using payload formatter", func() {
		formatter := PayloadFormatter{}
		msg := getTestMessageWithFunnyFields()
		jsonPayload := `{"this": "is", "a": "test"}
{"of": "the", "payload": "formatter"}
`
		msg.SetPayload(jsonPayload)
		b, err := formatter.Format(msg)
		c.Expect(err, gs.IsNil)
		c.Expect(string(b), gs.Equals, jsonPayload)
	})

	c.Specify("Should interpolate fields and message attributes for index and type names", func() {
		interpolatedIndex := interpolateFlag(&ElasticSearchCoordinates{}, getTestMessageWithFunnyFields(), "heka-%{Pid}-%{\"foo}-%{2006.01.02}")
		interpolatedType := interpolateFlag(&ElasticSearchCoordinates{}, getTestMessageWithFunnyFields(), "%{Type}")
		t := time.Now()

		c.Expect(interpolatedIndex, gs.Equals, "heka-14098-bar\n-"+t.Format("2006.01.02"))
		c.Expect(interpolatedType, gs.Equals, "TEST")
	})

}
開發者ID:KushalP,項目名稱:heka,代碼行數:59,代碼來源:elasticsearch_test.go

示例5: HttpListenInputSpec

func HttpListenInputSpec(c gs.Context) {
	t := &pipeline_ts.SimpleT{}
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()
	pConfig := NewPipelineConfig(nil)

	httpListenInput := HttpListenInput{}
	ith := new(plugins_ts.InputTestHelper)
	ith.MockHelper = pipelinemock.NewMockPluginHelper(ctrl)
	ith.MockInputRunner = pipelinemock.NewMockInputRunner(ctrl)

	startInput := func() {
		go func() {
			httpListenInput.Run(ith.MockInputRunner, ith.MockHelper)
		}()
	}

	ith.Pack = NewPipelinePack(pConfig.InputRecycleChan())
	ith.PackSupply = make(chan *PipelinePack, 1)

	config := httpListenInput.ConfigStruct().(*HttpListenInputConfig)
	config.Address = "127.0.0.1:8325"
	config.Decoder = "PayloadJsonDecoder"

	ith.MockHelper.EXPECT().PipelineConfig().Return(pConfig)

	mockDecoderRunner := pipelinemock.NewMockDecoderRunner(ctrl)

	dRunnerInChan := make(chan *PipelinePack, 1)
	mockDecoderRunner.EXPECT().InChan().Return(dRunnerInChan).AnyTimes()

	ith.MockInputRunner.EXPECT().InChan().Return(ith.PackSupply).AnyTimes()
	ith.MockInputRunner.EXPECT().Name().Return("HttpListenInput").AnyTimes()
	ith.MockHelper.EXPECT().DecoderRunner("PayloadJsonDecoder", "HttpListenInput-PayloadJsonDecoder").Return(mockDecoderRunner, true)

	err := httpListenInput.Init(config)
	c.Assume(err, gs.IsNil)
	ith.MockInputRunner.EXPECT().LogMessage(gomock.Any())
	startInput()

	c.Specify("A HttpListenInput", func() {
		c.Specify("Adds query parameters to the message pack as fields", func() {
			ith.PackSupply <- ith.Pack
			resp, err := http.Get("http://127.0.0.1:8325/?test=Hello%20World")
			c.Assume(err, gs.IsNil)
			resp.Body.Close()
			c.Assume(resp.StatusCode, gs.Equals, 200)

			pack := <-dRunnerInChan
			fieldValue, ok := pack.Message.GetFieldValue("test")
			c.Assume(ok, gs.IsTrue)
			c.Expect(fieldValue, gs.Equals, "Hello World")
		})
		httpListenInput.Stop()
	})
}
開發者ID:RogerBai,項目名稱:heka,代碼行數:56,代碼來源:http_listen_input_test.go

示例6: GeoIpDecoderSpec

func GeoIpDecoderSpec(c gs.Context) {
	t := &ts.SimpleT{}
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()
	pConfig := NewPipelineConfig(nil)
	pConfig.Globals.ShareDir = "/foo/bar/baz"

	c.Specify("A GeoIpDecoder", func() {
		decoder := new(GeoIpDecoder)
		decoder.SetPipelineConfig(pConfig)
		rec := new(geoip.GeoIPRecord)
		conf := decoder.ConfigStruct().(*GeoIpDecoderConfig)

		c.Expect(conf.DatabaseFile, gs.Equals, "/foo/bar/baz/GeoLiteCity.dat")

		supply := make(chan *PipelinePack, 1)
		pack := NewPipelinePack(supply)

		nf, _ := message.NewField("remote_host", "74.125.142.147", "")
		pack.Message.AddField(nf)

		decoder.SourceIpField = "remote_host"
		conf.SourceIpField = "remote_host"
		decoder.Init(conf)

		rec.CountryCode = "US"
		rec.CountryCode3 = "USA"
		rec.CountryName = "United States"
		rec.Region = "CA"
		rec.City = "Mountain View"
		rec.PostalCode = "94043"
		rec.Latitude = 37.4192
		rec.Longitude = -122.0574
		rec.AreaCode = 650
		rec.CharSet = 1
		rec.ContinentCode = "NA"

		c.Specify("Test GeoIpDecoder Output", func() {
			buf := decoder.GeoBuff(rec)
			nf, _ = message.NewField("geoip", buf.Bytes(), "")
			pack.Message.AddField(nf)

			b, ok := pack.Message.GetFieldValue("geoip")
			c.Expect(ok, gs.IsTrue)

			c.Expect(string(b.([]byte)), gs.Equals, `{"latitude":37.4192008972168,"longitude":-122.0574035644531,"location":[-122.0574035644531,37.4192008972168],"coordinates":["-122.0574035644531","37.4192008972168"],"countrycode":"US","countrycode3":"USA","countryname":"United States","region":"CA","city":"Mountain View","postalcode":"94043","areacode":650,"charset":1,"continentcode":"NA"}`)
		})

	})
}
開發者ID:orangemi,項目名稱:heka,代碼行數:50,代碼來源:geoip_decoder_test.go

示例7: DashboardOutputSpec

func DashboardOutputSpec(c gs.Context) {
	t := new(ts.SimpleT)
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	c.Specify("A FileOutput", func() {
		dashboardOutput := new(DashboardOutput)

		config := dashboardOutput.ConfigStruct().(*DashboardOutputConfig)
		c.Specify("Init halts if basedirectory is not writable", func() {
			tmpdir := path.Join(os.TempDir(), "tmpdir")
			err := os.MkdirAll(tmpdir, 0400)
			c.Assume(err, gs.IsNil)
			config.WorkingDirectory = tmpdir
			err = dashboardOutput.Init(config)
			c.Assume(err, gs.Not(gs.IsNil))
		})
	})
}
開發者ID:pchojnacki,項目名稱:heka,代碼行數:19,代碼來源:dashboard_output_test.go

示例8: InputsSpec

func InputsSpec(c gs.Context) {
	t := &ts.SimpleT{}
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	msg := getTestMessage()
	pipelinePack := getTestPipelinePack()

	// Specify localhost, but we're not really going to use the network
	addrStr := "localhost:55565"
	resolvedAddrStr := "127.0.0.1:55565"

	c.Specify("A UdpInput", func() {
		udpInput := UdpInput{}
		err := udpInput.Init(&UdpInputConfig{addrStr})
		c.Assume(err, gs.IsNil)
		realListener := (udpInput.Listener).(*net.UDPConn)
		c.Expect(realListener.LocalAddr().String(), gs.Equals, resolvedAddrStr)
		realListener.Close()

		// Replace the listener object w/ a mock listener
		mockListener := ts.NewMockConn(ctrl)
		udpInput.Listener = mockListener

		msgJson, _ := json.Marshal(msg)
		putMsgJsonInBytes := func(msgBytes []byte) {
			copy(msgBytes, msgJson)
		}

		c.Specify("reads a message from its listener", func() {
			mockListener.EXPECT().SetReadDeadline(gomock.Any())
			readCall := mockListener.EXPECT().Read(pipelinePack.MsgBytes)
			readCall.Return(len(msgJson), nil)
			readCall.Do(putMsgJsonInBytes)
			second := time.Second
			err := udpInput.Read(pipelinePack, &second)
			c.Expect(err, gs.IsNil)
			c.Expect(pipelinePack.Decoded, gs.IsFalse)
			c.Expect(string(pipelinePack.MsgBytes), gs.Equals, string(msgJson))
		})
	})
}
開發者ID:pombredanne,項目名稱:heka,代碼行數:42,代碼來源:inputs_test.go

示例9: InputRunnerSpec

func InputRunnerSpec(c gs.Context) {
	t := &ts.SimpleT{}
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	globals := &GlobalConfigStruct{
		PluginChanSize: 5,
	}
	NewPipelineConfig(globals)

	mockHelper := NewMockPluginHelper(ctrl)

	c.Specify("Runner restarts a plugin on the first time only", func() {
		var pluginGlobals PluginGlobals
		pluginGlobals.Retries = RetryOptions{
			MaxDelay:   "1us",
			Delay:      "1us",
			MaxJitter:  "1us",
			MaxRetries: 1,
		}
		pc := new(PipelineConfig)
		pc.inputWrappers = make(map[string]*PluginWrapper)

		pw := &PluginWrapper{
			Name:          "stopping",
			ConfigCreator: func() interface{} { return nil },
			PluginCreator: func() interface{} { return new(StoppingInput) },
		}
		pc.inputWrappers["stopping"] = pw

		input := new(StoppingInput)
		iRunner := NewInputRunner("stopping", input, &pluginGlobals, false)
		var wg sync.WaitGroup
		cfgCall := mockHelper.EXPECT().PipelineConfig().Times(7)
		cfgCall.Return(pc)
		wg.Add(1)
		iRunner.Start(mockHelper, &wg)
		wg.Wait()
		c.Expect(stopinputTimes, gs.Equals, 2)
	})
}
開發者ID:Jimdo,項目名稱:heka,代碼行數:41,代碼來源:plugin_runners_test.go

示例10: ProtobufDecoderSpec

func ProtobufDecoderSpec(c gospec.Context) {
	t := &ts.SimpleT{}
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	msg := ts.GetTestMessage()
	config := NewPipelineConfig(nil) // Initializes globals.

	c.Specify("A ProtobufDecoder", func() {
		encoded, err := proto.Marshal(msg)
		c.Assume(err, gs.IsNil)
		pack := NewPipelinePack(config.inputRecycleChan)
		decoder := new(ProtobufDecoder)
		decoder.sampleDenominator = 1000 // Since we don't call decoder.Init().

		c.Specify("decodes a protobuf message", func() {
			pack.MsgBytes = encoded
			_, err := decoder.Decode(pack)
			c.Expect(err, gs.IsNil)
			c.Expect(pack.Message, gs.Equals, msg)
			v, ok := pack.Message.GetFieldValue("foo")
			c.Expect(ok, gs.IsTrue)
			c.Expect(v, gs.Equals, "bar")
		})

		c.Specify("returns an error for bunk encoding", func() {
			bunk := append([]byte{0, 0, 0}, encoded...)
			pack.MsgBytes = bunk
			_, err := decoder.Decode(pack)
			c.Expect(err, gs.Not(gs.IsNil))
		})
	})
}
開發者ID:Nitro,項目名稱:heka,代碼行數:33,代碼來源:protobuf_test.go

示例11: DashboardOutputSpec

func DashboardOutputSpec(c gs.Context) {
	t := new(pipeline_ts.SimpleT)
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()
	NewPipelineConfig(nil) // Needed for side effect of setting up Globals :P

	if runtime.GOOS != "windows" {
		c.Specify("A DashboardOutput", func() {
			dashboardOutput := new(DashboardOutput)

			config := dashboardOutput.ConfigStruct().(*DashboardOutputConfig)
			c.Specify("Init halts if basedirectory is not writable", func() {
				tmpdir := filepath.Join(os.TempDir(), "tmpdir")
				err := os.MkdirAll(tmpdir, 0400)
				c.Assume(err, gs.IsNil)
				config.WorkingDirectory = tmpdir
				err = dashboardOutput.Init(config)
				c.Assume(err, gs.Not(gs.IsNil))
			})
		})
	}
}
開發者ID:RogerBai,項目名稱:heka,代碼行數:22,代碼來源:dashboard_output_test.go

示例12: MessageTemplateSpec

func MessageTemplateSpec(c gs.Context) {
	c.Specify("A message template", func() {
		mt := make(MessageTemplate)
		mt["Logger"] = "test logger"
		mt["Payload"] = "test payload"
		mt["Hostname"] = "host.example.com"
		mt["Pid"] = "123.456"
		mt["Type"] = "test type"
		mt["Severity"] = "23"
		mt["tmplTest|baz"] = "bar"
		msg := ts.GetTestMessage()

		c.Specify("replaces message values", func() {
			err := mt.PopulateMessage(msg, nil)
			c.Assume(err, gs.IsNil)
			c.Expect(msg.GetLogger(), gs.Equals, mt["Logger"])
			c.Expect(msg.GetPayload(), gs.Equals, mt["Payload"])
			c.Expect(msg.GetHostname(), gs.Equals, mt["Hostname"])
			c.Expect(msg.GetPid(), gs.Equals, int32(123))
			c.Expect(msg.GetType(), gs.Equals, mt["Type"])
			c.Expect(msg.GetSeverity(), gs.Equals, int32(23))
			fields := msg.FindAllFields("tmplTest")
			c.Expect(len(fields), gs.Equals, 1)
			field := fields[0]
			value := field.GetValueString()
			c.Expect(len(value), gs.Equals, 1)
			c.Expect(value[0], gs.Equals, "bar")
			c.Expect(field.GetRepresentation(), gs.Equals, "baz")
		})

		c.Specify("honors substitutions", func() {
			mt["Payload"] = "this is %substitution%"
			mt["Hostname"] = "%host%.example.com"
			mt["Type"] = "another %substitution%"
			mt["tmplTest|baz"] = "%fieldvalue%"
			subs := make(map[string]string)
			subs["host"] = "otherhost"
			subs["substitution"] = "a test"
			subs["fieldvalue"] = "wakajawaka"
			err := mt.PopulateMessage(msg, subs)
			c.Assume(err, gs.IsNil)
			c.Expect(msg.GetLogger(), gs.Equals, mt["Logger"])
			c.Expect(msg.GetPayload(), gs.Equals, "this is a test")
			c.Expect(msg.GetHostname(), gs.Equals, "otherhost.example.com")
			c.Expect(msg.GetPid(), gs.Equals, int32(123))
			c.Expect(msg.GetType(), gs.Equals, "another a test")
			c.Expect(msg.GetSeverity(), gs.Equals, int32(23))
			fields := msg.FindAllFields("tmplTest")
			c.Expect(len(fields), gs.Equals, 1)
			field := fields[0]
			value := field.GetValueString()
			c.Expect(len(value), gs.Equals, 1)
			c.Expect(value[0], gs.Equals, subs["fieldvalue"])
			c.Expect(field.GetRepresentation(), gs.Equals, "baz")
		})
	})
}
開發者ID:orangemi,項目名稱:heka,代碼行數:57,代碼來源:message_template_test.go

示例13: WhisperRunnerSpec

func WhisperRunnerSpec(c gospec.Context) {
	tmpDir := os.TempDir()
	tmpFileName := fmt.Sprintf("heka-%d.wsp", time.Now().UTC().UnixNano())
	tmpFileName = filepath.Join(tmpDir, tmpFileName)

	interval := uint32(10)
	archiveInfo := []whisper.ArchiveInfo{
		whisper.ArchiveInfo{0, interval, 60},
		whisper.ArchiveInfo{0, 60, 8},
	}

	c.Specify("A WhisperRunner", func() {
		var wg sync.WaitGroup
		wg.Add(1)
		folderPerm := os.FileMode(0755)
		wr, err := NewWhisperRunner(tmpFileName, archiveInfo, whisper.AggregationSum,
			folderPerm, &wg)
		c.Assume(err, gs.IsNil)
		defer func() {
			os.Remove(tmpFileName)
		}()

		c.Specify("creates a whisper file of the correct size", func() {
			fi, err := os.Stat(tmpFileName)
			c.Expect(err, gs.IsNil)
			c.Expect(fi.Size(), gs.Equals, int64(856))
			close(wr.InChan())
			wg.Wait()
		})

		c.Specify("writes a data point to the whisper file", func() {
			// Send a data point through and close.
			when := time.Now().UTC()
			val := float64(6)
			pt := whisper.NewPoint(when, val)
			wr.InChan() <- &pt
			close(wr.InChan())
			wg.Wait()

			// Open db file and fetch interval including our data point.
			from := when.Add(-1 * time.Second).Unix()
			until := when.Add(1 * time.Second).Unix()
			db, err := whisper.Open(tmpFileName)
			c.Expect(err, gs.IsNil)
			_, fetched, _ := db.FetchUntil(uint32(from), uint32(until))

			// Verify that our value is stored in the most recent interval and
			// that the diff btn our timestamp and the stored time value is
			// less than the interval duration.
			fpt := fetched[len(fetched)-1]
			diff := when.Sub(fpt.Time().UTC())
			c.Expect(diff.Seconds() < float64(interval), gs.IsTrue)
			c.Expect(fpt.Value, gs.Equals, val)
		})
	})
}
開發者ID:Nitro,項目名稱:heka,代碼行數:56,代碼來源:whisper_test.go

示例14: ScribbleDecoderSpec

func ScribbleDecoderSpec(c gs.Context) {
	t := &pipeline_ts.SimpleT{}
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	c.Specify("A ScribbleDecoder", func() {
		decoder := new(ScribbleDecoder)
		config := decoder.ConfigStruct().(*ScribbleDecoderConfig)
		myType := "myType"
		myPayload := "myPayload"
		config.MessageFields = MessageTemplate{"Type": myType, "Payload": myPayload}
		supply := make(chan *PipelinePack, 1)
		pack := NewPipelinePack(supply)

		c.Specify("sets basic values correctly", func() {
			decoder.Init(config)
			packs, err := decoder.Decode(pack)
			c.Expect(err, gs.IsNil)
			c.Expect(len(packs), gs.Equals, 1)
			c.Expect(pack.Message.GetType(), gs.Equals, myType)
			c.Expect(pack.Message.GetPayload(), gs.Equals, myPayload)
		})
	})
}
開發者ID:orangemi,項目名稱:heka,代碼行數:24,代碼來源:scribble_decoder_test.go

示例15: SentryOutputSpec

func SentryOutputSpec(c gs.Context) {

	pack := getSentryPack()
	output := new(SentryOutput)
	output.Init(output.ConfigStruct())
	sentryMsg := &SentryMsg{
		dataPacket: make([]byte, 0, output.config.MaxSentryBytes),
	}
	var err error

	c.Specify("verify data_packet bytes", func() {
		err = output.prepSentryMsg(pack, sentryMsg)
		c.Expect(err, gs.Equals, nil)

		actual := string(sentryMsg.dataPacket)
		ts := int64(EPOCH_TS * 1e9)
		t := time.Unix(ts/1e9, ts%1e9)
		expected := fmt.Sprintf("Sentry sentry_timestamp=%s, "+
			"sentry_client=raven-go/1.0, sentry_version=2.0, "+
			"sentry_key=username\n\n%s", t.Format(time.RFC3339Nano), PAYLOAD)

		c.Expect(actual, gs.Equals, expected)
	})

	c.Specify("missing or invalid epoch_timestamp doesn't kill process", func() {
		f := pack.Message.FindFirstField("epoch_timestamp")
		*f.Name = "other"
		err = output.prepSentryMsg(pack, sentryMsg)
		c.Expect(err.Error(), gs.Equals, "no `epoch_timestamp` field")

		f, _ = message.NewField("epoch_timestamp", "foo", "")
		pack.Message.AddField(f)
		err = output.prepSentryMsg(pack, sentryMsg)
		c.Expect(err.Error(), gs.Equals, "`epoch_timestamp` isn't a float64")
	})

	c.Specify("missing or invalid dsn doesn't kill process", func() {
		f := pack.Message.FindFirstField("dsn")
		*f.Name = "other"
		err = output.prepSentryMsg(pack, sentryMsg)
		c.Expect(err.Error(), gs.Equals, "no `dsn` field")

		f, _ = message.NewField("dsn", 42, "")
		pack.Message.AddField(f)
		err = output.prepSentryMsg(pack, sentryMsg)
		c.Expect(err.Error(), gs.Equals, "`dsn` isn't a string")
	})

}
開發者ID:jmptrader,項目名稱:heka-mozsvc-plugins,代碼行數:49,代碼來源:sentry_test.go


注:本文中的github.com/rafrombrc/gospec/src/gospec.Context.Specify方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。