예제 #1
0
func TestTransmissions(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
	}

	campaignID := "msys_smoke"
	tlist, res, err := client.Transmissions(&campaignID, nil)
	if err != nil {
		t.Error(err)
		return
	}
	t.Errorf("List: %d, %d entries", res.HTTP.StatusCode, len(tlist))
	for _, tr := range tlist {
		t.Errorf("%s: %s", tr.ID, tr.CampaignID)
	}

	// TODO: 404 from Transmission Create could mean either
	// Recipient List or Content wasn't found - open doc ticket
	// to make error message more specific

	T := &sp.Transmission{
		CampaignID: "msys_smoke",
		ReturnPath: "*****@*****.**",
		Recipients: []string{"*****@*****.**", "*****@*****.**"},
		// Single-recipient Transmissions are transient - Retrieve will 404
		//Recipients: []string{"*****@*****.**"},
		Content: sp.Content{
			Subject: "this is a test message",
			HTML:    "this is the <b>HTML</b> body of the test message",
			From: map[string]string{
				"name":  "Dave Gray",
				"email": "*****@*****.**",
			},
		},
		Metadata: map[string]interface{}{
			"binding": "example",
		},
	}
	err = T.Validate()
	if err != nil {
		t.Error(err)
		return
	}

	id, _, err := client.Send(T)
	if err != nil {
		t.Error(err)
		return
	}

	t.Errorf("Transmission created with id [%s]", id)

	tr, res, err := client.Transmission(id)
	if err != nil {
		t.Error(err)
		return
	}

	if res != nil {
		t.Errorf("Retrieve returned HTTP %s\n", res.HTTP.Status)
		if len(res.Errors) > 0 {
			for _, e := range res.Errors {
				json, err := e.Json()
				if err != nil {
					t.Error(err)
				}
				t.Errorf("%s\n", json)
			}
		} else {
			t.Errorf("Transmission retrieved: %s=%s\n", tr.ID, tr.State)
		}
	}

	res, err = client.TransmissionDelete(id)
	if err != nil {
		t.Error(err)
		return
	}

	t.Errorf("Delete returned HTTP %s\n%s\n", res.HTTP.Status, res.Body)

}