Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
Use viper.SetDefault() to set various default values for retries and db
timeouts.
  • Loading branch information
ScottGarman committed Oct 18, 2023
1 parent 026f45d commit da07904
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/lookup/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package lookup_test
import (
"context"
"testing"
"time"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"

Expand Down Expand Up @@ -86,6 +88,10 @@ func TestFetchMetadataByIDAndStore(t *testing.T) {
MetadataResponse lookup.MetadataLookupResponse
}

viper.SetDefault("crdb.max_retries", 5)
viper.SetDefault("crdb.retry_interval", 1*time.Second)
viper.SetDefault("crdb.tx_timeout", 15*time.Second)

var testCases = []testCase{
{
ID: "abc123",
Expand Down
6 changes: 6 additions & 0 deletions internal/upserter/upserter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package upserter_test
import (
"context"
"testing"
"time"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/volatiletech/null/v8"
"github.com/volatiletech/sqlboiler/v4/types"
Expand All @@ -27,6 +29,10 @@ var (
func TestUpsertMetadataAddsInstanceMetadataRow(t *testing.T) {
testDB := dbtools.DatabaseTest(t)

viper.SetDefault("crdb.max_retries", 5)
viper.SetDefault("crdb.retry_interval", 1*time.Second)
viper.SetDefault("crdb.tx_timeout", 15*time.Second)

exists, err := models.InstanceMetadatumExists(context.TODO(), testDB, instanceID)
if err != nil {
t.Fatal(err)
Expand Down
6 changes: 6 additions & 0 deletions pkg/api/v1/router_instance_ec2_metadata_lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"

"go.hollow.sh/metadataservice/internal/lookup"
Expand All @@ -18,6 +20,10 @@ func TestGetEc2MetadataLookupByIP(t *testing.T) {
serverConfig := TestServerConfig{LookupEnabled: true, LookupClient: lookupClient}
router := *testHTTPServerWithConfig(t, serverConfig)

viper.SetDefault("crdb.max_retries", 5)
viper.SetDefault("crdb.retry_interval", 1*time.Second)
viper.SetDefault("crdb.tx_timeout", 15*time.Second)

type testCase struct {
testName string
instanceIP string
Expand Down
6 changes: 6 additions & 0 deletions pkg/api/v1/router_instance_ec2_userdata_lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"

"go.hollow.sh/metadataservice/internal/lookup"
Expand All @@ -18,6 +20,10 @@ func TestGetEc2UserdataLookupByIP(t *testing.T) {
serverConfig := TestServerConfig{LookupEnabled: true, LookupClient: lookupClient}
router := *testHTTPServerWithConfig(t, serverConfig)

viper.SetDefault("crdb.max_retries", 5)
viper.SetDefault("crdb.retry_interval", 1*time.Second)
viper.SetDefault("crdb.tx_timeout", 15*time.Second)

type testCase struct {
testName string
instanceIP string
Expand Down
6 changes: 6 additions & 0 deletions pkg/api/v1/router_instance_metadata_lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"

"go.hollow.sh/metadataservice/internal/lookup"
Expand All @@ -18,6 +20,10 @@ func TestGetMetadataLookupByIP(t *testing.T) {
serverConfig := TestServerConfig{LookupEnabled: true, LookupClient: lookupClient}
router := *testHTTPServerWithConfig(t, serverConfig)

viper.SetDefault("crdb.max_retries", 5)
viper.SetDefault("crdb.retry_interval", 1*time.Second)
viper.SetDefault("crdb.tx_timeout", 15*time.Second)

type testCase struct {
testName string
instanceIP string
Expand Down
10 changes: 10 additions & 0 deletions pkg/api/v1/router_instance_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"regexp"
"testing"
"text/template"
"time"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"

"go.hollow.sh/metadataservice/internal/dbtools"
Expand Down Expand Up @@ -311,6 +313,10 @@ func TestSetMetadataIPAddressConflict(t *testing.T) {
router := *testHTTPServer(t)
testDB := dbtools.TestDB()

viper.SetDefault("crdb.max_retries", 5)
viper.SetDefault("crdb.retry_interval", 1*time.Second)
viper.SetDefault("crdb.tx_timeout", 15*time.Second)

type testCase struct {
testName string
conflictInstanceIDToIPs map[string][]string
Expand Down Expand Up @@ -418,6 +424,10 @@ func TestSetMetadataCreateMetadata(t *testing.T) {
router := *testHTTPServer(t)
testDB := dbtools.TestDB()

viper.SetDefault("crdb.max_retries", 5)
viper.SetDefault("crdb.retry_interval", 1*time.Second)
viper.SetDefault("crdb.tx_timeout", 15*time.Second)

requestBody := &v1api.UpsertMetadataRequest{
ID: "b94fa75b-1fee-45eb-9925-83011c4834b9",
Metadata: `{"some": "json for instance 'b94fa75b-1fee-45eb-9925-83011c4834b9'"}`,
Expand Down

0 comments on commit da07904

Please sign in to comment.