This file contains hidden or 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
| package main | |
| import ( | |
| "text/template" | |
| "os" | |
| "log" | |
| "time" | |
| ) | |
| func main() { |
This file contains hidden or 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
| package main | |
| import ( | |
| "text/template" | |
| "os" | |
| "log" | |
| "strings" | |
| ) | |
| type Paragraph struct { |
This file contains hidden or 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
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "os" | |
| "strings" | |
| "testing" | |
| ) |
This file contains hidden or 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
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "os" | |
| ) | |
| func main() { | |
| type Employee struct { |
This file contains hidden or 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
| func TestDeleteEntry(t *testing.T) { | |
| req, err := http.NewRequest("DELETE", "/entry", nil) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| q := req.URL.Query() | |
| q.Add("id", "4") | |
| req.URL.RawQuery = q.Encode() | |
| rr := httptest.NewRecorder() | |
| handler := http.HandlerFunc(DeleteEntry) |
This file contains hidden or 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
| func TestEditEntry(t *testing.T) { | |
| var jsonStr = []byte(`{"id":4,"first_name":"xyz change","last_name":"pqr","email_address":"xyz@pqr.com","phone_number":"1234567890"}`) | |
| req, err := http.NewRequest("PUT", "/entry", bytes.NewBuffer(jsonStr)) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| req.Header.Set("Content-Type", "application/json") | |
| rr := httptest.NewRecorder() |
This file contains hidden or 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
| func TestCreateEntry(t *testing.T) { | |
| var jsonStr = []byte(`{"id":4,"first_name":"xyz","last_name":"pqr","email_address":"xyz@pqr.com","phone_number":"1234567890"}`) | |
| req, err := http.NewRequest("POST", "/entry", bytes.NewBuffer(jsonStr)) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| req.Header.Set("Content-Type", "application/json") | |
| rr := httptest.NewRecorder() |
This file contains hidden or 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
| func TestGetEntryByIDNotFound(t *testing.T) { | |
| req, err := http.NewRequest("GET", "/entry", nil) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| q := req.URL.Query() | |
| q.Add("id", "123") | |
| req.URL.RawQuery = q.Encode() | |
| rr := httptest.NewRecorder() | |
| handler := http.HandlerFunc(GetEntryByID) |
This file contains hidden or 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
| func TestGetEntryByID(t *testing.T) { | |
| req, err := http.NewRequest("GET", "/entry", nil) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| q := req.URL.Query() | |
| q.Add("id", "1") | |
| req.URL.RawQuery = q.Encode() | |
| rr := httptest.NewRecorder() |
This file contains hidden or 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
| func TestGetEntries(t *testing.T) { | |
| req, err := http.NewRequest("GET", "/entries", nil) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| rr := httptest.NewRecorder() | |
| handler := http.HandlerFunc(GetEntries) | |
| handler.ServeHTTP(rr, req) | |
| if status := rr.Code; status != http.StatusOK { | |
| t.Errorf("handler returned wrong status code: got %v want %v", |