github.com/crosbymichael/octokat@v0.0.0-20160826194511-076a32289ed5/statuses_test.go (about)

     1  package octokat
     2  
     3  import (
     4  	"net/http"
     5  	"testing"
     6  
     7  	"github.com/bmizerany/assert"
     8  )
     9  
    10  func TestStatuses(t *testing.T) {
    11  	setup()
    12  	defer tearDown()
    13  
    14  	mux.HandleFunc("/repos/jingweno/gh/statuses/740211b9c6cd8e526a7124fe2b33115602fbc637", func(w http.ResponseWriter, r *http.Request) {
    15  		testMethod(t, r, "GET")
    16  		respondWith(w, loadFixture("statuses.json"))
    17  	})
    18  
    19  	repo := Repo{UserName: "jingweno", Name: "gh"}
    20  	sha := "740211b9c6cd8e526a7124fe2b33115602fbc637"
    21  	statuses, _ := client.Statuses(repo, sha, nil)
    22  	assert.Equal(t, 2, len(statuses))
    23  
    24  	firstStatus := statuses[0]
    25  	assert.Equal(t, "pending", firstStatus.State)
    26  	assert.Equal(t, "The Travis CI build is in progress", firstStatus.Description)
    27  	assert.Equal(t, "https://travis-ci.org/jingweno/gh/builds/11911500", firstStatus.TargetURL)
    28  }
    29  
    30  func TestCombinedStatus(t *testing.T) {
    31  	setup()
    32  	defer tearDown()
    33  
    34  	mux.HandleFunc("/repos/jingweno/gh/commits/740211b9c6cd8e526a7124fe2b33115602fbc637/status", func(w http.ResponseWriter, r *http.Request) {
    35  		testMethod(t, r, "GET")
    36  		respondWith(w, loadFixture("combined_status.json"))
    37  	})
    38  
    39  	repo := Repo{UserName: "jingweno", Name: "gh"}
    40  	sha := "740211b9c6cd8e526a7124fe2b33115602fbc637"
    41  	combinedStatus, _ := client.CombinedStatus(repo, sha, nil)
    42  	assert.Equal(t, "pending", combinedStatus.State)
    43  	assert.Equal(t, 2, combinedStatus.TotalCount)
    44  	assert.Equal(t, 2, len(combinedStatus.Statuses))
    45  
    46  	firstStatus := combinedStatus.Statuses[0]
    47  	assert.Equal(t, "pending", firstStatus.State)
    48  	assert.Equal(t, "The Travis CI build is in progress", firstStatus.Description)
    49  	assert.Equal(t, "https://travis-ci.org/jingweno/gh/builds/11911500", firstStatus.TargetURL)
    50  }
    51  
    52  func TestSetStatus(t *testing.T) {
    53  	setup()
    54  	defer tearDown()
    55  
    56  	mux.HandleFunc("/repos/erikh/test/statuses/5456e827a6b4930a3b1d727b7bd407b0b499c08f", func(w http.ResponseWriter, r *http.Request) {
    57  		testMethod(t, r, "POST")
    58  		respondWith(w, loadFixture("status_response.json"))
    59  	})
    60  
    61  	repo := Repo{UserName: "erikh", Name: "test"}
    62  	sha := "5456e827a6b4930a3b1d727b7bd407b0b499c08f"
    63  
    64  	opts := &StatusOptions{
    65  		State:       "success",
    66  		Description: "this is only a test",
    67  		URL:         "http://google.com",
    68  		Context:     "docci",
    69  	}
    70  
    71  	status, err := client.SetStatus(repo, sha, opts)
    72  
    73  	if err != nil {
    74  		t.Fatal(err)
    75  	}
    76  
    77  	assert.Equal(t, "this is only a test", status.Description)
    78  	assert.Equal(t, "success", status.State)
    79  }