Example #1
0
func NewAPI(opts APIOptions) *API {
	c := client.NewClient(client.ClientOptions(opts))
	return &API{
		Account: &api.Account{c},
		Book:    &api.Book{c},
		Books:   &api.Books{c},
		User:    &api.User{c},
	}
}
Example #2
0
func TestLeaks(t *testing.T) {
	// Get current count
	c1 := openDescriptors()

	// Call in isolated function
	func() {
		wg := &sync.WaitGroup{}

		// Create one client
		c := client.NewClient(client.ClientOptions{
			Host:     "http://localhost:5000/api/",
			Username: "******",
			Password: "******",
		})

		// Do some work
		for i := 0; i < 10; i++ {
			go func() {
				wg.Add(1)
				c2 := c.Fork(client.ClientOptions{})
				b := Book{c2}

				_, err := b.Get("james/test")
				if err != nil {
					t.Error(err)
				}

				wg.Done()
			}()

			t.Log(c1, "...", openDescriptors())
		}

		wg.Wait()

		time.Sleep(time.Second)
	}()

	// Close pooled connections in net/http
	if transport, ok := http.DefaultTransport.(*http.Transport); ok {
		transport.CloseIdleConnections()
	} else {
		t.Errorf("Failed to get default transport")
	}

	// See how many files are open now
	c2 := openDescriptors()

	t.Log(c1, "=>", c2)

	// Check for leak
	if c2 > c1 {
		t.Errorf("Leak: %d to %d descriptors", c1, c2)
	}
}
Example #3
0
func TestBasic(t *testing.T) {
	c := client.NewClient(client.ClientOptions{
		Host:     "http://localhost:5000",
		Username: "******",
		Password: "******",
	})
	b := Book{c}

	if err := b.Publish("aaronomullan/some-paid-book", "6.6.6", "/Users/aaron/git/jsbook"); err != nil {
		t.Error(err)
	}
}
Example #4
0
func TestBasic(t *testing.T) {
	c := client.NewClient(client.ClientOptions{
		Host:     "http://localhost:5000/api/",
		Username: "******",
		Password: "******",
	})
	b := Book{c}

	_, err := b.Get("james/test")
	if err != nil {
		t.Error(err)
	}
}
Example #5
0
func TestAccount(t *testing.T) {
	c := client.NewClient(client.ClientOptions{
		Host:     "http://localhost:5000/api/",
		Username: "******",
		Password: "******",
	})
	a := Account{c}

	_, err := a.Get()
	if err != nil {
		t.Error(err)
	}
}
Example #6
0
func TestBuildsCreate(t *testing.T) {
	c := client.NewClient(client.ClientOptions{
		Host:     "stupid_host",
		Username: "******",
		Password: "******",
	})
	b := Builds{c}

	err := b.BuildGit("james/test", "master", "/Users/aaron/git/documentation", "master", BuildOptions{
		Branch: "master",
	})
	if err != nil {
		t.Error(err)
	}
}
Example #7
0
func TestBooksList(t *testing.T) {
	c := client.NewClient(client.ClientOptions{
		Host:     "http://localhost:5000/api/",
		Username: "******",
		Password: "******",
	})
	b := Books{c}

	books, err := b.List()
	if err != nil {
		t.Error(err)
	}

	if len(books) < 1 {
		t.Errorf("Should have at least one book, found %d instead", len(books))
	}
}
Example #8
0
func NewAPI(opts APIOptions) *API {
	c := client.NewClient(client.ClientOptions(opts))
	return NewAPIFromClient(c)
}