Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iagapie committed Jul 4, 2023
1 parent e64e10c commit 508a26c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
3 changes: 2 additions & 1 deletion environment_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package et_test

import (
"context"
et "github.com/gowool/extends-template"
"github.com/stretchr/testify/assert"
"html/template"
Expand Down Expand Up @@ -54,7 +55,7 @@ func TestEnvironment_Load(t *testing.T) {

for _, s := range scenarios {
for range []struct{}{{}, {}} {
w, err := env.Load(nil, s.view)
w, err := env.Load(context.TODO(), s.view)
if s.isError {
assert.Nil(t, w)
assert.Error(t, err)
Expand Down
6 changes: 3 additions & 3 deletions loader_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestChainLoader_Get(t *testing.T) {
}

for _, s := range scenarios {
source, err := loader.Get(nil, s.view)
source, err := loader.Get(context.TODO(), s.view)

if s.isError {
assert.Nil(t, source)
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestChainLoader_IsFresh(t *testing.T) {
}

for _, s := range scenarios {
isFresh, _ := loader.IsFresh(nil, s.view, 0)
isFresh, _ := loader.IsFresh(context.TODO(), s.view, 0)

assert.Equal(t, s.expected, isFresh)
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestChainLoader_Exists(t *testing.T) {
}

for _, s := range scenarios {
isFresh, _ := loader.Exists(nil, s.view)
isFresh, _ := loader.Exists(context.TODO(), s.view)

assert.Equal(t, s.expected, isFresh)
}
Expand Down
7 changes: 4 additions & 3 deletions loader_filesystem_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package et_test

import (
"context"
et "github.com/gowool/extends-template"
"github.com/stretchr/testify/assert"
"os"
Expand Down Expand Up @@ -89,7 +90,7 @@ func TestFilesystemLoader_Get(t *testing.T) {
}

for _, s := range scenarios {
source, err := loader.Get(nil, s.view)
source, err := loader.Get(context.TODO(), s.view)

if s.isError {
assert.Nil(t, source)
Expand Down Expand Up @@ -122,7 +123,7 @@ func TestFilesystemLoader_Exists(t *testing.T) {
}

for _, s := range scenarios {
exists, err := loader.Exists(nil, s.view)
exists, err := loader.Exists(context.TODO(), s.view)

assert.Equal(t, s.expected, exists)
if s.isError {
Expand Down Expand Up @@ -164,7 +165,7 @@ func TestFilesystemLoader_IsFresh(t *testing.T) {
}

for _, s := range scenarios {
isFresh, err := loader.IsFresh(nil, s.view, s.t)
isFresh, err := loader.IsFresh(context.TODO(), s.view, s.t)

assert.Equal(t, s.expected, isFresh)
if s.isError {
Expand Down
7 changes: 4 additions & 3 deletions loader_memory_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package et_test

import (
"context"
et "github.com/gowool/extends-template"
"github.com/stretchr/testify/assert"
"testing"
Expand Down Expand Up @@ -29,7 +30,7 @@ func TestMemoryLoader_Get(t *testing.T) {
}

for _, s := range scenarios {
source, err := loader.Get(nil, s.view)
source, err := loader.Get(context.TODO(), s.view)

if s.isError {
assert.Nil(t, source)
Expand Down Expand Up @@ -72,7 +73,7 @@ func TestMemoryLoader_IsFresh(t *testing.T) {
}

for _, s := range scenarios {
isFresh, err := loader.IsFresh(nil, s.view, s.t)
isFresh, err := loader.IsFresh(context.TODO(), s.view, s.t)

assert.Equal(t, s.expected, isFresh)
if s.isError {
Expand Down Expand Up @@ -104,7 +105,7 @@ func TestMemoryLoader_Exists(t *testing.T) {
}

for _, s := range scenarios {
exists, err := loader.Exists(nil, s.view)
exists, err := loader.Exists(context.TODO(), s.view)

assert.Equal(t, s.expected, exists)
if s.isError {
Expand Down
12 changes: 6 additions & 6 deletions template_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ type wrapLoader struct {
t int64
}

func (l wrapLoader) Get(_ context.Context, name string) (*et.Source, error) {
if ok, _ := l.Exists(nil, name); ok {
func (l wrapLoader) Get(ctx context.Context, name string) (*et.Source, error) {
if ok, _ := l.Exists(ctx, name); ok {
return &et.Source{Name: name, Code: htmlViews[name]}, nil
}
return nil, fmt.Errorf("template %s not found", name)
}

func (l wrapLoader) IsFresh(_ context.Context, name string, t int64) (bool, error) {
ok, _ := l.Exists(nil, name)
func (l wrapLoader) IsFresh(ctx context.Context, name string, t int64) (bool, error) {
ok, _ := l.Exists(ctx, name)
return ok && l.t < t, nil
}

Expand Down Expand Up @@ -70,7 +70,7 @@ func TestTemplateWrapper_IsFresh(t *testing.T) {
et.ReExtends("{{", "}}"),
et.ReTemplate("{{", "}}"))

isFresh := wrapper.IsFresh(nil)
isFresh := wrapper.IsFresh(context.TODO())

assert.Equal(t, s.expected, isFresh)
}
Expand All @@ -85,7 +85,7 @@ func TestTemplateWrapper_Parse(t *testing.T) {
et.ReTemplate("{{", "}}"))

for range []struct{}{{}, {}} {
if err := wrapper.Parse(nil); assert.NoError(t, err) && assert.NotNil(t, wrapper.HTML) {
if err := wrapper.Parse(context.TODO()); assert.NoError(t, err) && assert.NotNil(t, wrapper.HTML) {
var out bytes.Buffer
if err = wrapper.HTML.ExecuteTemplate(&out, name, nil); assert.NoError(t, err) {
assert.Equal(t, htmlResult, out.String())
Expand Down

0 comments on commit 508a26c

Please sign in to comment.