-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add first the and move error handling some domain
- Loading branch information
1 parent
ea34496
commit 8541a1e
Showing
3 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package service_test | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/leonlatsch/go-resolve/internal/api" | ||
"github.com/leonlatsch/go-resolve/internal/http" | ||
"github.com/leonlatsch/go-resolve/internal/models" | ||
"github.com/leonlatsch/go-resolve/internal/service" | ||
) | ||
|
||
func TestPrintDomainDetails(t *testing.T) { | ||
fakeHttpClient := http.FakeHttpClient{} | ||
|
||
service := service.GodaddyService{ | ||
GodaddyApi: api.GodaddyApi{ | ||
HttpClient: &fakeHttpClient, | ||
}, | ||
} | ||
|
||
t.Run("Get domain details does not crash with correct json response", func(t *testing.T) { | ||
fakeDomainDetail := models.DomainDetail{ | ||
Domain: "somedomain.com", | ||
ContactAdmin: models.DomainContact{ | ||
Email: "someemail@asdf.com", | ||
FirstName: "FirstName", | ||
LastName: "LastName", | ||
}, | ||
} | ||
|
||
fakeJson, _ := json.Marshal(fakeDomainDetail) | ||
fakeHttpClient.RespBody = string(fakeJson) | ||
|
||
if err := service.PrintDomainDetail(); err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
|
||
t.Run("Get domain details crash if http returns an error", func(t *testing.T) { | ||
fakeHttpClient.Error = errors.New("Some http error") | ||
|
||
if err := service.PrintDomainDetail(); err == nil { | ||
t.Fatal("Was expected to return error but did not") | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters