Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions data/service/service/client_test.go

This file was deleted.

11 changes: 0 additions & 11 deletions data/service/service/service_suite_test.go

This file was deleted.

15 changes: 9 additions & 6 deletions data/service/service/standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"log"
"os"

"github.com/tidepool-org/platform/clinics"

"github.com/IBM/sarama"

eventsCommon "github.com/tidepool-org/go-common/events"

"github.com/tidepool-org/platform/application"
"github.com/tidepool-org/platform/clinics"
dataDeduplicatorDeduplicator "github.com/tidepool-org/platform/data/deduplicator/deduplicator"
dataDeduplicatorFactory "github.com/tidepool-org/platform/data/deduplicator/factory"
dataEvents "github.com/tidepool-org/platform/data/events"
Expand All @@ -34,7 +34,7 @@ import (
)

type Standard struct {
*service.DEPRECATEDService
*service.Authenticated
metricClient *metricClient.Client
permissionClient *permissionClient.Client
dataDeduplicatorFactory *dataDeduplicatorFactory.Factory
Expand All @@ -51,12 +51,15 @@ type Standard struct {

func NewStandard() *Standard {
return &Standard{
DEPRECATEDService: service.NewDEPRECATEDService(),
Authenticated: service.NewAuthenticated(),
}
}

func (s *Standard) Initialize(provider application.Provider) error {
if err := s.DEPRECATEDService.Initialize(provider); err != nil {
if err := s.Service.Initialize(provider); err != nil {
return err
}
if err := s.Authenticated.Initialize(provider); err != nil {
return err
}

Expand Down Expand Up @@ -128,7 +131,7 @@ func (s *Standard) Terminate() {
s.permissionClient = nil
s.metricClient = nil

s.DEPRECATEDService.Terminate()
s.Authenticated.Terminate()
}

func (s *Standard) Run() error {
Expand Down
95 changes: 91 additions & 4 deletions data/service/service/standard_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,95 @@
package service_test
package service

import (
. "github.com/onsi/ginkgo/v2"
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/tidepool-org/platform/application"
netTest "github.com/tidepool-org/platform/net/test"
"github.com/tidepool-org/platform/test"
)

var _ = Describe("Standard", func() {
})
func TestAuthClientIsInitialized(t *testing.T) {
tt := newStandardTest(t)
tt.Setenv("SECRET", "something secret")
tt.Setenv("SERVER_ADDRESS", "somehost")
tt.SetenvToFilePath("SERVER_TLS_CERTIFICATE_FILE", "contents")
tt.SetenvToFilePath("SERVER_TLS_KEY_FILE", "contents")
tt.Setenv("AUTH_CLIENT_ADDRESS", "something secret")
tt.Setenv("AUTH_CLIENT_EXTERNAL_ADDRESS", "something secret")
tt.Setenv("AUTH_CLIENT_SERVICE_SECRET", "something secret")
tt.Setenv("AUTH_CLIENT_EXTERNAL_SERVICE_SECRET", "something secret")
tt.Setenv("AUTH_CLIENT_SERVER_SESSION_TOKEN_SECRET", "something secret")
tt.Setenv("AUTH_CLIENT_EXTERNAL_SERVER_SESSION_TOKEN_SECRET", "something secret")
tt.Setenv("METRIC_CLIENT_ADDRESS", "something secret")
tt.Setenv("PERMISSION_CLIENT_ADDRESS", "something secret")
tt.Setenv("DEPRECATED_DATA_STORE_DATABASE", "test_data_database")
tt.Setenv("SYNC_TASK_STORE_DATABASE", "test_sync_task_database")
// These have no prefixes
t.Setenv("KAFKA_BROKERS", "somehost")
t.Setenv("KAFKA_TOPIC_PREFIX", "somehost")
t.Setenv("KAFKA_REQUIRE_SSL", "false")
t.Setenv("KAFKA_VERSION", "2.5.0")

std := NewStandard()
err := std.Initialize(tt.Provider)
if err != nil {
t.Errorf("expected successful initialization, got %s", err)
}
}

type standardTest struct {
Prefix string
Name string
Scopes []string
Provider application.Provider

t testing.TB
tempDir string
}

func newStandardTest(t *testing.T) *standardTest {
prefix := test.RandomStringFromRangeAndCharset(4, 8, test.CharsetUppercase)
name := test.RandomStringFromRangeAndCharset(4, 8, test.CharsetAlphaNumeric)
scopes := test.RandomStringArrayFromRangeAndCharset(0, 2, test.CharsetAlphaNumeric)

t.Setenv(fmt.Sprintf("%s_LOGGER_LEVEL", prefix), "error")
oldName := os.Args[0]
os.Args[0] = name
t.Cleanup(func() { os.Args[0] = oldName })

application.VersionBase = netTest.RandomSemanticVersion()
application.VersionFullCommit = test.RandomStringFromRangeAndCharset(40, 40, test.CharsetHexidecimalLowercase)
application.VersionShortCommit = application.VersionFullCommit[0:8]

provider, err := application.NewProvider(prefix, scopes...)
if err != nil {
t.Fatalf("unable to initialize provider")
}

return &standardTest{
Prefix: prefix,
Name: name,
Scopes: scopes,
Provider: provider,

t: t,
tempDir: t.TempDir(),
}
}

func (t *standardTest) Setenv(keySuffix, value string) {
baseKey := strings.Join(append([]string{t.Prefix, t.Name}, t.Scopes...), "_")
t.t.Setenv(strings.ToUpper(baseKey+"_"+keySuffix), value)
}

func (t *standardTest) SetenvToFilePath(keySuffix, contents string) {
filename := filepath.Join(t.tempDir, keySuffix)
if err := os.WriteFile(filename, []byte(contents), 0600); err != nil {
t.t.Fatalf("opening tempfile %q: %s", filename, err)
}
t.Setenv(keySuffix, filename)
}
93 changes: 0 additions & 93 deletions service/service/DEPRECATED_service.go

This file was deleted.

128 changes: 0 additions & 128 deletions service/service/DEPRECATED_service_test.go

This file was deleted.

Loading