本文整理汇总了Golang中github.com/rafrombrc/gospec/src/gospec.Not函数的典型用法代码示例。如果您正苦于以下问题:Golang Not函数的具体用法?Golang Not怎么用?Golang Not使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Not函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DecodersSpec
func DecodersSpec(c gospec.Context) {
msg := getTestMessage()
c.Specify("A JsonDecoder", func() {
var fmtString = `{"type":"%s","timestamp":%s,"logger":"%s","severity":%d,"payload":"%s","fields":%s,"env_version":"%s","metlog_pid":%d,"metlog_hostname":"%s"}`
timestampJson, err := json.Marshal(msg.Timestamp)
fieldsJson, err := json.Marshal(msg.Fields)
c.Assume(err, gs.IsNil)
jsonString := fmt.Sprintf(fmtString, msg.Type,
timestampJson, msg.Logger, msg.Severity, msg.Payload,
fieldsJson, msg.Env_version, msg.Pid, msg.Hostname)
pipelinePack := getTestPipelinePack()
pipelinePack.MsgBytes = []byte(jsonString)
jsonDecoder := new(JsonDecoder)
c.Specify("can decode a JSON message", func() {
err := jsonDecoder.Decode(pipelinePack)
c.Expect(pipelinePack.Message, gs.Equals, msg)
c.Expect(err, gs.IsNil)
})
c.Specify("returns `fields` as a map", func() {
jsonDecoder.Decode(pipelinePack)
c.Expect(pipelinePack.Message.Fields["foo"], gs.Equals, "bar")
})
c.Specify("returns an error for bogus JSON", func() {
badJson := fmt.Sprint("{{", jsonString)
pipelinePack.MsgBytes = []byte(badJson)
err := jsonDecoder.Decode(pipelinePack)
c.Expect(err, gs.Not(gs.IsNil))
c.Expect(pipelinePack.Message.Timestamp.IsZero(), gs.IsTrue)
})
})
c.Specify("A MsgPackDecoder", func() {
msg := getTestMessage()
encoded, err := msgpack.Marshal(msg)
c.Assume(err, gs.IsNil)
decoder := new(MsgPackDecoder)
decoder.Init(nil)
pack := getTestPipelinePack()
c.Specify("decodes a msgpack message", func() {
pack.MsgBytes = encoded
err := decoder.Decode(pack)
c.Expect(err, gs.IsNil)
c.Expect(pack.Message, gs.Equals, msg)
})
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))
})
})
}
示例2: 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))
})
})
}
示例3: PrimitiveDecodeStrictSpec
func PrimitiveDecodeStrictSpec(c gs.Context) {
var md MetaData
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 band struct {
Started int
Albums []string
}
type classics struct {
Ranking []string
Bands map[string]Primitive
}
// Do the initial decode. Reflection is delayed on Primitive values.
var music classics
md, err = Decode(tomlBlob, &music)
c.Assume(err, gs.IsNil)
// MetaData still includes information on Primitive values.
c.Assume(md.IsDefined("bands", "Springsteen"), gs.IsTrue)
ignore_type := map[string]interface{}{"type": true}
// Decode primitive data into Go values.
for _, artist := range music.Ranking {
// A band is a primitive value, so we need to decode it to get a
// real `band` value.
primValue := music.Bands[artist]
var aBand band
err = PrimitiveDecodeStrict(primValue, &aBand, ignore_type)
if artist == "Springsteen" {
c.Assume(err, gs.Not(gs.IsNil))
c.Expect(err.Error(), gs.Equals, "Configuration contains key [not_albums] which doesn't exist in struct")
c.Assume(1973, gs.Equals, aBand.Started)
} else {
c.Expect(err, gs.IsNil)
c.Assume(1970, gs.Equals, aBand.Started)
}
}
}
示例4: UdpInputSpecFailure
func UdpInputSpecFailure(c gs.Context) {
udpInput := UdpInput{}
err := udpInput.Init(&UdpInputConfig{Net: "tcp", Address: "localhost:55565",
Decoder: "ProtobufDecoder",
ParserType: "message.proto"})
c.Assume(err, gs.Not(gs.IsNil))
c.Assume(err.Error(), gs.Equals, "ResolveUDPAddr failed: unknown network tcp\n")
}
示例5: TcpInputSpecFailure
func TcpInputSpecFailure(c gs.Context) {
tcpInput := TcpInput{}
err := tcpInput.Init(&TcpInputConfig{Net: "udp", Address: "localhost:55565",
Decoder: "ProtobufDecoder",
ParserType: "message.proto"})
c.Assume(err, gs.Not(gs.IsNil))
c.Assume(err.Error(), gs.Equals, "ListenTCP failed: unknown network udp\n")
}
示例6: UdpInputSpecFailure
func UdpInputSpecFailure(c gs.Context) {
udpInput := UdpInput{}
err := udpInput.Init(&UdpInputConfig{
Net: "tcp",
Address: "localhost:55565",
})
c.Assume(err, gs.Not(gs.IsNil))
c.Assume(err.Error(), gs.Equals, "ResolveUDPAddr failed: unknown network tcp\n")
}
示例7: TcpInputSpecFailure
func TcpInputSpecFailure(c gs.Context) {
tcpInput := TcpInput{}
err := tcpInput.Init(&TcpInputConfig{
Net: "udp",
Address: "localhost:55565",
})
c.Assume(err, gs.Not(gs.IsNil))
c.Assume(err.Error(), gs.Equals, "ResolveTCPAddress failed: unknown network udp\n")
}
示例8: MessageEqualsSpec
func MessageEqualsSpec(c gospec.Context) {
msg0 := getTestMessage()
msg1Real := *msg0
msg1 := &msg1Real
c.Specify("Messages are equal", func() {
c.Expect(msg0, gs.Equals, msg1)
})
c.Specify("Messages w/ diff int values are not equal", func() {
msg1.Severity--
c.Expect(msg0, gs.Not(gs.Equals), msg1)
})
c.Specify("Messages w/ diff string values are not equal", func() {
msg1.Payload = "Something completely different"
c.Expect(msg0, gs.Not(gs.Equals), msg1)
})
c.Specify("Messages w/ diff maps are not equal", func() {
msg1.Fields = map[string]interface{}{"sna": "foo"}
c.Expect(msg0, gs.Not(gs.Equals), msg1)
})
}
示例9: DecodeSpec
func DecodeSpec(c gs.Context) {
var val simple
md, err := Decode(testSimple, &val)
c.Assume(err, gs.IsNil)
c.Assume(md.IsDefined("Annoying", "Cats", "plato"), gs.IsTrue)
c.Assume(md.IsDefined("Cats", "Stinky"), gs.IsFalse)
var colors = [][]string{[]string{"red", "green", "blue"},
[]string{"cyan", "magenta", "yellow", "black"}}
for ridx, row := range colors {
for cidx, _ := range row {
c.Assume(val.Colors[ridx][cidx], gs.Equals, colors[ridx][cidx])
}
}
c.Assume(val, gs.Not(gs.IsNil))
}
示例10: 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))
})
})
}
示例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))
})
})
}
}
示例12: JsonPathSpec
func JsonPathSpec(c gs.Context) {
c.Specify("JsonPath can read data", func() {
var s = `{
"foo": {
"bar": [
{
"baz": "こんにちわ世界",
"noo": "aaa"
},
{
"maz": "123",
"moo": 256,
"muux": 2.10
}
],
"boo": {
"bag": true,
"bug": false
}
}
}
`
var err error
var json_path *JsonPath
var result interface{}
json_path = new(JsonPath)
err = json_path.SetJsonText(s)
c.Expect(err, gs.IsNil)
result, err = json_path.Find("$.foo.bar[0].baz")
c.Expect(err, gs.IsNil)
c.Expect(result, gs.Equals, "こんにちわ世界")
result, err = json_path.Find("$.foo.bar[0].noo")
c.Expect(err, gs.IsNil)
c.Expect(result, gs.Equals, "aaa")
result, err = json_path.Find("$.foo.bar[1].maz")
c.Expect(err, gs.IsNil)
c.Expect(result, gs.Equals, "123")
result, err = json_path.Find("$.foo.bar[1].moo")
c.Expect(err, gs.IsNil)
c.Expect(result, gs.Equals, "256")
result, err = json_path.Find("$.foo.bar[1].muux")
c.Expect(err, gs.IsNil)
c.Expect(result, gs.Equals, "2.10")
result, err = json_path.Find("$.foo.boo.bag")
c.Expect(err, gs.IsNil)
c.Expect(result, gs.Equals, "true")
result, err = json_path.Find("$.foo.boo.bug")
c.Expect(err, gs.IsNil)
c.Expect(result, gs.Equals, "false")
result, err = json_path.Find("$.foo.bar[99].baz")
c.Expect(err, gs.Not(gs.IsNil))
result, err = json_path.Find("$.badpath")
c.Expect(err, gs.Not(gs.IsNil))
result, err = json_path.Find("badpath")
c.Expect(err, gs.Not(gs.IsNil))
result, err = json_path.Find("$.foo.bar.3428")
c.Expect(err, gs.Not(gs.IsNil))
expected_data := `[{"baz":"こんにちわ世界","noo":"aaa"},{"maz":"123","moo":256,"muux":2.10}]`
result_data, err := json_path.Find("$.foo.bar")
c.Expect(err, gs.IsNil)
c.Expect(result_data, gs.Equals, expected_data)
})
c.Specify("JsonPath doesn't crash on nil data", func() {
var err error
var json_path *JsonPath
json_path = new(JsonPath)
err = json_path.SetJsonText("")
c.Expect(err, gs.Not(gs.IsNil))
// Searches should return an error
result, err := json_path.Find("$.foo.bar.3428")
c.Expect(err, gs.Not(gs.IsNil))
c.Expect(err.Error(), gs.Equals, "JSON data is nil")
c.Expect(result, gs.Equals, "")
})
c.Specify("JsonPath handles arrays at top level", func() {
var err error
var json_path *JsonPath
json_path = new(JsonPath)
err = json_path.SetJsonText(`["foo"]`)
c.Expect(err, gs.IsNil)
//.........这里部分代码省略.........
示例13: DashboardOutputSpec
func DashboardOutputSpec(c gs.Context) {
t := new(pipeline_ts.SimpleT)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
pConfig := pipeline.NewPipelineConfig(nil)
dashboardOutput := new(DashboardOutput)
dashboardOutput.pConfig = pConfig
oth := plugins_ts.NewOutputTestHelper(ctrl)
oth.MockHelper = pipelinemock.NewMockPluginHelper(ctrl)
oth.MockOutputRunner = pipelinemock.NewMockOutputRunner(ctrl)
errChan := make(chan error, 1)
startOutput := func() {
go func() {
errChan <- dashboardOutput.Run(oth.MockOutputRunner, oth.MockHelper)
}()
}
if runtime.GOOS != "windows" {
c.Specify("A DashboardOutput", func() {
tmpdir, err := ioutil.TempDir("", "dashboard_output_test")
c.Assume(err, gs.IsNil)
config := dashboardOutput.ConfigStruct().(*DashboardOutputConfig)
config.WorkingDirectory = tmpdir
c.Specify("Init halts if basedirectory is not writable", func() {
err := os.MkdirAll(tmpdir, 0400)
c.Assume(err, gs.IsNil)
defer os.RemoveAll(tmpdir)
err = dashboardOutput.Init(config)
c.Assume(err, gs.Not(gs.IsNil))
})
c.Specify("that is running", func() {
startedChan := make(chan bool, 1)
defer close(startedChan)
ts := httptest.NewUnstartedServer(nil)
dashboardOutput.starterFunc = func(hli *DashboardOutput) error {
ts.Start()
startedChan <- true
return nil
}
ticker := make(chan time.Time)
inChan := make(chan *pipeline.PipelinePack, 1)
recycleChan := make(chan *pipeline.PipelinePack, 1)
pack := pipeline.NewPipelinePack(recycleChan)
pack.Message = pipeline_ts.GetTestMessage()
oth.MockOutputRunner.EXPECT().InChan().Return(inChan)
oth.MockOutputRunner.EXPECT().Ticker().Return(ticker)
err := os.MkdirAll(tmpdir, 0700)
c.Assume(err, gs.IsNil)
defer os.RemoveAll(tmpdir)
dashboardOutput.handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Noop
})
c.Specify("sets custom http headers", func() {
config.Headers = http.Header{
"One": []string{"two", "three"},
"Four": []string{"five", "six", "seven"},
}
err = dashboardOutput.Init(config)
c.Assume(err, gs.IsNil)
ts.Config = dashboardOutput.server
startOutput()
inChan <- pack
<-startedChan
resp, err := http.Get(ts.URL)
c.Assume(err, gs.IsNil)
resp.Body.Close()
c.Assume(resp.StatusCode, gs.Equals, 200)
// Verify headers are there
eq := reflect.DeepEqual(resp.Header["One"], config.Headers["One"])
c.Expect(eq, gs.IsTrue)
eq = reflect.DeepEqual(resp.Header["Four"], config.Headers["Four"])
c.Expect(eq, gs.IsTrue)
})
close(inChan)
c.Expect(<-errChan, gs.IsNil)
ts.Close()
})
})
}
}
示例14: LogstreamerInputSpec
//.........这里部分代码省略.........
ith.MockSplitterRunner = pipelinemock.NewMockSplitterRunner(ctrl)
ith.PackSupply = make(chan *PipelinePack, 1)
c.Specify("A LogstreamerInput", func() {
lsInput := &LogstreamerInput{pConfig: pConfig}
lsiConfig := lsInput.ConfigStruct().(*LogstreamerInputConfig)
lsiConfig.LogDirectory = dirPath
lsiConfig.FileMatch = `file.log(\.?)(?P<Seq>\d+)?`
lsiConfig.Differentiator = []string{"logfile"}
lsiConfig.Priority = []string{"^Seq"}
c.Specify("w/ no translation map", func() {
err := lsInput.Init(lsiConfig)
c.Expect(err, gs.IsNil)
c.Expect(len(lsInput.plugins), gs.Equals, 1)
// Create pool of packs.
numLines := 5 // # of lines in the log file we're parsing.
packs := make([]*PipelinePack, numLines)
ith.PackSupply = make(chan *PipelinePack, numLines)
for i := 0; i < numLines; i++ {
packs[i] = NewPipelinePack(ith.PackSupply)
ith.PackSupply <- packs[i]
}
c.Specify("reads a log file", func() {
// Expect InputRunner calls to get InChan and inject outgoing msgs.
ith.MockInputRunner.EXPECT().LogError(gomock.Any()).AnyTimes()
ith.MockInputRunner.EXPECT().LogMessage(gomock.Any()).AnyTimes()
ith.MockInputRunner.EXPECT().NewDeliverer("1").Return(ith.MockDeliverer)
ith.MockInputRunner.EXPECT().NewSplitterRunner("1").Return(
ith.MockSplitterRunner)
ith.MockSplitterRunner.EXPECT().UseMsgBytes().Return(false)
ith.MockSplitterRunner.EXPECT().IncompleteFinal().Return(false)
ith.MockSplitterRunner.EXPECT().SetPackDecorator(gomock.Any())
getRecCall := ith.MockSplitterRunner.EXPECT().GetRecordFromStream(
gomock.Any()).Times(numLines)
line := "boo hoo foo foo"
getRecCall.Return(len(line), []byte(line), nil)
getRecCall = ith.MockSplitterRunner.EXPECT().GetRecordFromStream(gomock.Any())
getRecCall.Return(0, make([]byte, 0), io.EOF)
deliverChan := make(chan []byte, 1)
deliverCall := ith.MockSplitterRunner.EXPECT().DeliverRecord(gomock.Any(),
ith.MockDeliverer).Times(numLines)
deliverCall.Do(func(record []byte, del Deliverer) {
deliverChan <- record
})
ith.MockDeliverer.EXPECT().Done()
runOutChan := make(chan error, 1)
go func() {
err = lsInput.Run(ith.MockInputRunner, ith.MockHelper)
runOutChan <- err
}()
dur, _ := time.ParseDuration("5s")
timeout := time.After(dur)
timed := false
for x := 0; x < numLines; x++ {
select {
case record := <-deliverChan:
c.Expect(string(record), gs.Equals, line)
case <-timeout:
timed = true
x += numLines
}
// Free up the scheduler while we wait for the log file lines
// to be processed.
runtime.Gosched()
}
lsInput.Stop()
c.Expect(timed, gs.Equals, false)
c.Expect(<-runOutChan, gs.Equals, nil)
})
})
c.Specify("with a translation map", func() {
lsiConfig.Translation = make(ls.SubmatchTranslationMap)
lsiConfig.Translation["Seq"] = make(ls.MatchTranslationMap)
c.Specify("allows len 1 translation map for 'missing'", func() {
lsiConfig.Translation["Seq"]["missing"] = 9999
err := lsInput.Init(lsiConfig)
c.Expect(err, gs.IsNil)
})
c.Specify("doesn't allow len 1 map for other keys", func() {
lsiConfig.Translation["Seq"]["missin"] = 9999
err := lsInput.Init(lsiConfig)
c.Expect(err, gs.Not(gs.IsNil))
c.Expect(err.Error(), gs.Equals,
"A translation map with one entry ('Seq') must be specifying a "+
"'missing' key.")
})
})
})
}
示例15: OutputsSpec
//.........这里部分代码省略.........
c.Specify("when specified and timestamp ignored", func() {
fileOutput.prefix_ts = true
err := fileOutput.handleMessage(pack, &outData)
c.Expect(err, gs.IsNil)
b := []byte{30, 2, 8, uint8(proto.Size(pack.Message)), 31, 10, 16} // sanity check the header and the start of the protocol buffer
c.Expect(bytes.Equal(b, outData[:len(b)]), gs.IsTrue)
})
})
c.Specify("processes incoming messages", func() {
err := fileOutput.Init(config)
defer os.Remove(tmpFilePath)
c.Assume(err, gs.IsNil)
// Save for comparison.
payload := fmt.Sprintf("%s\n", pack.Message.GetPayload())
oth.MockOutputRunner.EXPECT().InChan().Return(inChan)
wg.Add(1)
go fileOutput.receiver(oth.MockOutputRunner, &wg)
inChan <- pack
close(inChan)
outBatch := <-fileOutput.batchChan
wg.Wait()
c.Expect(string(outBatch), gs.Equals, payload)
})
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.Path = tmpdir
err = fileOutput.Init(config)
c.Assume(err, gs.Not(gs.IsNil))
})
c.Specify("commits to a file", func() {
outStr := "Write me out to the log file"
outBytes := []byte(outStr)
c.Specify("with default settings", func() {
err := fileOutput.Init(config)
defer os.Remove(tmpFilePath)
c.Assume(err, gs.IsNil)
// Start committer loop
wg.Add(1)
go fileOutput.committer(oth.MockOutputRunner, &wg)
// Feed and close the batchChan
go func() {
fileOutput.batchChan <- outBytes
_ = <-fileOutput.backChan // clear backChan to prevent blocking
close(fileOutput.batchChan)
}()
wg.Wait()
// Wait for the file close operation to happen.
//for ; err == nil; _, err = fileOutput.file.Stat() {
//}
tmpFile, err := os.Open(tmpFilePath)
defer tmpFile.Close()
c.Assume(err, gs.IsNil)
contents, err := ioutil.ReadAll(tmpFile)
c.Assume(err, gs.IsNil)