Tests: Add unit tests
This commit is contained in:
parent
19699c49c0
commit
9b3917dd00
4 changed files with 102 additions and 0 deletions
17
internal/form/form_report_test.go
Normal file
17
internal/form/form_report_test.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package form
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestReport(t *testing.T) {
|
||||
form := &SearchPhotos{}
|
||||
rows, cols := Report(form)
|
||||
assert.Contains(t, rows[5][0], "name")
|
||||
assert.Contains(t, rows[5][1], "string")
|
||||
assert.Contains(t, rows[5][2], "name:\"IMG_9831-112*\"")
|
||||
|
||||
assert.Contains(t, cols, "Examples")
|
||||
}
|
18
internal/form/json_test.go
Normal file
18
internal/form/json_test.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package form
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAsJson(t *testing.T) {
|
||||
form := &SearchAlbums{Query: "slug:album1 favorite:true", Year: "2020"}
|
||||
assert.Contains(t, AsJson(form), "{\"Query\":\"slug:album1")
|
||||
}
|
||||
|
||||
func TestAsReader(t *testing.T) {
|
||||
form := &SearchAlbums{Query: "slug:album1 favorite:true", Year: "2020"}
|
||||
assert.IsType(t, AsReader(form), &strings.Reader{})
|
||||
}
|
33
internal/form/search_sessions_test.go
Normal file
33
internal/form/search_sessions_test.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package form
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSearchSessions_GetQuery(t *testing.T) {
|
||||
form := &SearchSessions{Query: "test"}
|
||||
|
||||
assert.Equal(t, "test", form.GetQuery())
|
||||
}
|
||||
|
||||
func TestSearchSessions_SetQuery(t *testing.T) {
|
||||
form := &SearchSessions{Query: "test"}
|
||||
form.SetQuery("new query")
|
||||
|
||||
assert.Equal(t, "new query", form.GetQuery())
|
||||
}
|
||||
|
||||
func TestSearchSessions_ParseQueryString(t *testing.T) {
|
||||
form := &SearchSessions{Query: "test", Count: 3}
|
||||
|
||||
err := form.ParseQueryString()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("err should be nil")
|
||||
}
|
||||
|
||||
assert.Equal(t, 3, form.Count)
|
||||
assert.Equal(t, "test", form.Query)
|
||||
}
|
34
internal/form/search_users_test.go
Normal file
34
internal/form/search_users_test.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package form
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSearchUsers_GetQuery(t *testing.T) {
|
||||
form := &SearchUsers{Query: "John Doe"}
|
||||
|
||||
assert.Equal(t, "John Doe", form.GetQuery())
|
||||
}
|
||||
|
||||
func TestSearchUsers_SetQuery(t *testing.T) {
|
||||
form := &SearchUsers{Query: "John Doe"}
|
||||
form.SetQuery("Jane")
|
||||
|
||||
assert.Equal(t, "Jane", form.GetQuery())
|
||||
}
|
||||
|
||||
func TestSearchUsers_ParseQueryString(t *testing.T) {
|
||||
form := &SearchUsers{Query: "John Doe", Email: "john@test.com", Name: "John"}
|
||||
|
||||
err := form.ParseQueryString()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("err should be nil")
|
||||
}
|
||||
|
||||
assert.Equal(t, "john@test.com", form.Email)
|
||||
assert.Equal(t, "john doe", form.Query)
|
||||
assert.Equal(t, "John", form.Name)
|
||||
}
|
Loading…
Reference in a new issue