Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Replace Init with NewClient #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,12 @@ var httpClient = newTimeoutClient(connectTimeout, readWriteTimeout)

// Init initializes the Firebase client with a given root url and optional auth token.
// The initialization can also pass a mock api for testing purposes.
func (c *Client) Init(root, auth string, api Api) {
func NewClient(root, auth string, api Api) *Client {
if api == nil {
api = new(f)
}

c.api = api
c.Url = root
c.Auth = auth
return &Client{Url: root, Auth: auth, api: api, value: nil}
}

// Value returns the value of of the current Url.
Expand Down
24 changes: 8 additions & 16 deletions firebase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ var (
)

func TestValue(t *testing.T) {
client := new(Client)
client.Init(testUrl+"/tests", testAuth, nil)
client := NewClient(testUrl+"/tests", testAuth, nil)

r := client.Value()

Expand All @@ -33,8 +32,7 @@ func TestValue(t *testing.T) {
}

func TestChild(t *testing.T) {
client := new(Client)
client.Init(testUrl+"/tests", testAuth, nil)
client := NewClient(testUrl+"/tests", testAuth, nil)

r := client.Child("", nil, nil)

Expand All @@ -44,8 +42,7 @@ func TestChild(t *testing.T) {
}

func TestPush(t *testing.T) {
client := new(Client)
client.Init(testUrl+"/tests", testAuth, nil)
client := NewClient(testUrl+"/tests", testAuth, nil)

name := &Name{First: "FirstName", Last: "LastName"}

Expand All @@ -61,8 +58,7 @@ func TestPush(t *testing.T) {
}

func TestSet(t *testing.T) {
c1 := new(Client)
c1.Init(testUrl+"/tests/users", testAuth, nil)
c1 := NewClient(testUrl+"/tests/users", testAuth, nil)

name := &Name{First: "First", Last: "last"}
c2, _ := c1.Push(name, nil)
Expand All @@ -80,8 +76,7 @@ func TestSet(t *testing.T) {
}

func TestUpdate(t *testing.T) {
c1 := new(Client)
c1.Init(testUrl+"/tests/users", testAuth, nil)
c1 := NewClient(testUrl+"/tests/users", testAuth, nil)

name := &Name{First: "First", Last: "last"}
c2, _ := c1.Push(name, nil)
Expand All @@ -95,8 +90,7 @@ func TestUpdate(t *testing.T) {
}

func TestRemovet(t *testing.T) {
c1 := new(Client)
c1.Init(testUrl+"/tests/users", testAuth, nil)
c1 := NewClient(testUrl+"/tests/users", testAuth, nil)

name := &Name{First: "First", Last: "last"}
c2, _ := c1.Push(name, nil)
Expand All @@ -109,8 +103,7 @@ func TestRemovet(t *testing.T) {
}

func TestRules(t *testing.T) {
client := new(Client)
client.Init(testUrl, testAuth, nil)
client := NewClient(testUrl, testAuth, nil)

r, err := client.Rules(nil)

Expand All @@ -124,8 +117,7 @@ func TestRules(t *testing.T) {
}

func TestSetRules(t *testing.T) {
client := new(Client)
client.Init(testUrl, testAuth, nil)
client := NewClient(testUrl, testAuth, nil)

rules := &Rules{
"rules": map[string]string{
Expand Down