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

     1  package octokat
     2  
     3  import (
     4  	"encoding/json"
     5  	"github.com/bmizerany/assert"
     6  	"net/http"
     7  	"reflect"
     8  	"testing"
     9  )
    10  
    11  func TestCreateRepository(t *testing.T) {
    12  	setup()
    13  	defer tearDown()
    14  
    15  	params := RepositoryParams{}
    16  	params.Name = "Hello-World"
    17  	params.Description = "This is your first repo"
    18  	params.Homepage = "https://github.com"
    19  	params.Private = false
    20  	params.HasIssues = true
    21  	params.HasWiki = true
    22  	params.HasDownloads = true
    23  
    24  	mux.HandleFunc("/user/repos", func(w http.ResponseWriter, r *http.Request) {
    25  		var repoParams RepositoryParams
    26  		json.NewDecoder(r.Body).Decode(&repoParams)
    27  		assert.T(t, reflect.DeepEqual(repoParams, params))
    28  
    29  		testMethod(t, r, "POST")
    30  		respondWith(w, loadFixture("create_repository.json"))
    31  	})
    32  
    33  	options := Options{Params: params}
    34  	repo, _ := client.CreateRepository("", &options)
    35  
    36  	assert.Equal(t, 1296269, repo.ID)
    37  	assert.Equal(t, "Hello-World", repo.Name)
    38  	assert.Equal(t, "octocat/Hello-World", repo.FullName)
    39  	assert.Equal(t, "This is your first repo", repo.Description)
    40  	assert.T(t, !repo.Private)
    41  	assert.T(t, repo.Fork)
    42  	assert.Equal(t, "https://api.github.com/repos/octocat/Hello-World", repo.URL)
    43  	assert.Equal(t, "https://github.com/octocat/Hello-World", repo.HTMLURL)
    44  	assert.Equal(t, "https://github.com/octocat/Hello-World.git", repo.CloneURL)
    45  	assert.Equal(t, "git://github.com/octocat/Hello-World.git", repo.GitURL)
    46  	assert.Equal(t, "git@github.com:octocat/Hello-World.git", repo.SSHURL)
    47  	assert.Equal(t, "master", repo.MasterBranch)
    48  }