forked from stellar/go
-
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.
stellar#4222: backfilling tests on filters
- Loading branch information
Showing
6 changed files
with
165 additions
and
23 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
89 changes: 89 additions & 0 deletions
89
services/horizon/internal/db2/history/filter_rules_test.go
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,89 @@ | ||
package history | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stellar/go/services/horizon/internal/test" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
fc1 = FilterConfig{ | ||
Rules: "{}", | ||
Name: "test data", | ||
Enabled: false, | ||
} | ||
) | ||
|
||
func TestInsertConfig(t *testing.T) { | ||
tt := test.Start(t) | ||
defer tt.Finish() | ||
test.ResetHorizonDB(t, tt.HorizonDB) | ||
q := &Q{tt.HorizonSession()} | ||
|
||
err := q.UpsertFilterConfig(tt.Ctx, fc1) | ||
assert.NoError(t, err) | ||
fc1, err = q.GetFilterByName(tt.Ctx, "test data") | ||
assert.NoError(t, err) | ||
tt.Assert.True(fc1.LastModified > 0) | ||
tt.Assert.Equal(fc1.Name, "test data") | ||
tt.Assert.Equal(fc1.Enabled, false) | ||
tt.Assert.Equal(fc1.Rules, "{}") | ||
} | ||
|
||
func TestGetAll(t *testing.T) { | ||
tt := test.Start(t) | ||
defer tt.Finish() | ||
test.ResetHorizonDB(t, tt.HorizonDB) | ||
q := &Q{tt.HorizonSession()} | ||
|
||
err := q.UpsertFilterConfig(tt.Ctx, fc1) | ||
assert.NoError(t, err) | ||
results, err := q.GetAllFilters(tt.Ctx) | ||
assert.NoError(t, err) | ||
tt.Assert.Len(results, 1) | ||
|
||
tt.Assert.Equal(results[0].Name, "test data") | ||
} | ||
func TestRemoveFilterConfig(t *testing.T) { | ||
tt := test.Start(t) | ||
defer tt.Finish() | ||
test.ResetHorizonDB(t, tt.HorizonDB) | ||
q := &Q{tt.HorizonSession()} | ||
|
||
err := q.UpsertFilterConfig(tt.Ctx, fc1) | ||
assert.NoError(t, err) | ||
|
||
err = q.DeleteFilterByName(tt.Ctx, "not found") | ||
assert.Error(t, err) | ||
|
||
err = q.DeleteFilterByName(tt.Ctx, "test data") | ||
assert.NoError(t, err) | ||
|
||
fc1, err = q.GetFilterByName(tt.Ctx, "test data") | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestUpdateExisting(t *testing.T) { | ||
tt := test.Start(t) | ||
defer tt.Finish() | ||
test.ResetHorizonDB(t, tt.HorizonDB) | ||
q := &Q{tt.HorizonSession()} | ||
|
||
err := q.UpsertFilterConfig(tt.Ctx, fc1) | ||
assert.NoError(t, err) | ||
fc1, err = q.GetFilterByName(tt.Ctx, "test data") | ||
assert.NoError(t, err) | ||
tt.Assert.Equal(fc1.Enabled, false) | ||
tt.Assert.Equal(fc1.Rules, "{}") | ||
|
||
fc1.Enabled = true | ||
fc1.Rules = `{"abc": "123"}` | ||
err = q.UpsertFilterConfig(tt.Ctx, fc1) | ||
assert.NoError(t, err) | ||
fc1, err = q.GetFilterByName(tt.Ctx, "test data") | ||
assert.NoError(t, err) | ||
tt.Assert.Equal(fc1.Name, "test data") | ||
tt.Assert.Equal(fc1.Enabled, true) | ||
tt.Assert.Equal(fc1.Rules, `{"abc": "123"}`) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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