当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.EventSamples方法代码示例

本文整理汇总了Golang中github.com/SparkPost/gosparkpost.Client.EventSamples方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.EventSamples方法的具体用法?Golang Client.EventSamples怎么用?Golang Client.EventSamples使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/SparkPost/gosparkpost.Client的用法示例。


在下文中一共展示了Client.EventSamples方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestAllEventsSamples

func TestAllEventsSamples(t *testing.T) {
	if true {
		// Temporarily disable test so TravisCI reports build success instead of test failure.
		return
	}

	cfgMap, err := test.LoadConfig()
	if err != nil {
		t.Error(err)
		return
	}
	cfg, err := sp.NewConfig(cfgMap)
	if err != nil {
		t.Error(err)
		return
	}

	var client sp.Client
	err = client.Init(cfg)
	if err != nil {
		t.Error(err)
		return
	}

	e, err := client.EventSamples(nil)
	if err != nil {
		t.Error(err)
		return
	}

	if len(*e) == 0 {
		t.Error("expected non-empty result")
	}

	for _, ev := range *e {
		switch event := ev.(type) {
		case *events.Click, *events.Open, *events.GenerationFailure, *events.GenerationRejection,
			*events.ListUnsubscribe, *events.LinkUnsubscribe, *events.PolicyRejection,
			*events.RelayInjection, *events.RelayRejection, *events.RelayDelivery,
			*events.RelayTempfail, *events.RelayPermfail, *events.SpamComplaint, *events.SMSStatus:
			if len(fmt.Sprintf("%v", event)) == 0 {
				t.Errorf("Empty output of %T.String()", event)
			}

		case *events.Bounce, *events.Delay, *events.Delivery, *events.Injection, *events.OutOfBand:
			if len(events.ECLog(event)) == 0 {
				t.Errorf("Empty output of %T.ECLog()", event)
			}

		case *events.Unknown:
			t.Errorf("Uknown type: %v", event)

		default:
			t.Errorf("Uknown type: %T", event)
		}
	}
}
开发者ID:SparkPost,项目名称:gosparkpost,代码行数:57,代码来源:message_events_test.go

示例2: TestMessageEvents

func TestMessageEvents(t *testing.T) {
	if true {
		// Temporarily disable test so TravisCI reports build success instead of test failure.
		return
	}

	cfgMap, err := test.LoadConfig()
	if err != nil {
		t.Error(err)
		return
	}
	cfg, err := sp.NewConfig(cfgMap)
	if err != nil {
		t.Error(err)
		return
	}

	var client sp.Client
	err = client.Init(cfg)
	if err != nil {
		t.Error(err)
		return
	}

	//types := []string{"open", "click", "bounce"}
	//e, err := client.EventSamples(&types)
	e, err := client.EventSamples(nil)
	if err != nil {
		t.Error(err)
		return
	}

	for _, ev := range *e {
		//t.Error(fmt.Errorf("%s", ev))
		switch event := ev.(type) {
		case *events.Click, *events.Open, *events.GenerationFailure, *events.GenerationRejection,
			*events.ListUnsubscribe, *events.LinkUnsubscribe, *events.PolicyRejection,
			*events.RelayInjection, *events.RelayRejection, *events.RelayDelivery,
			*events.RelayTempfail, *events.RelayPermfail, *events.SpamComplaint:
			t.Error(fmt.Errorf("%s", event))

		case *events.Bounce, *events.Delay, *events.Delivery, *events.Injection, *events.OutOfBand:
			t.Error(fmt.Errorf("%s", events.ECLog(event)))

		default:
			t.Errorf("Unsupported type [%s]", reflect.TypeOf(ev))
		}
	}
}
开发者ID:cbroglie,项目名称:gosparkpost,代码行数:49,代码来源:message_events_test.go

示例3: TestFilteredEventsSamples

func TestFilteredEventsSamples(t *testing.T) {
	if true {
		// Temporarily disable test so TravisCI reports build success instead of test failure.
		return
	}

	cfgMap, err := test.LoadConfig()
	if err != nil {
		t.Error(err)
		return
	}
	cfg, err := sp.NewConfig(cfgMap)
	if err != nil {
		t.Error(err)
		return
	}

	var client sp.Client
	err = client.Init(cfg)
	if err != nil {
		t.Error(err)
		return
	}

	types := []string{"open", "click", "bounce"}
	e, err := client.EventSamples(&types)
	if err != nil {
		t.Error(err)
		return
	}

	if len(*e) == 0 {
		t.Error("expected non-empty result")
	}

	for _, ev := range *e {
		switch event := ev.(type) {
		case *events.Click, *events.Open, *events.Bounce:
			// Expected, ok.
		default:
			t.Errorf("Unexpected type %T, should have been filtered out.", event)
		}
	}
}
开发者ID:SparkPost,项目名称:gosparkpost,代码行数:44,代码来源:message_events_test.go


注:本文中的github.com/SparkPost/gosparkpost.Client.EventSamples方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。