diff --git a/internal/services/configstore/common/common.go b/internal/services/configstore/common/common.go index 25514ab..24fe2d7 100644 --- a/internal/services/configstore/common/common.go +++ b/internal/services/configstore/common/common.go @@ -91,6 +91,27 @@ func PathToTypeID(p string) (types.ConfigType, string) { return configType, path.Base(p) } +func DataToPathFunc(dataType string, id string) string { + switch types.ConfigType(dataType) { + case types.ConfigTypeUser: + return StorageUserFile(id) + case types.ConfigTypeOrg: + return StorageOrgFile(id) + case types.ConfigTypeProjectGroup: + return StorageProjectGroupFile(id) + case types.ConfigTypeProject: + return StorageProjectFile(id) + case types.ConfigTypeRemoteSource: + return StorageRemoteSourceFile(id) + case types.ConfigTypeSecret: + return StorageSecretFile(id) + case types.ConfigTypeVariable: + return StorageVariableFile(id) + } + + panic(fmt.Errorf("unknown data type %q", dataType)) +} + type RefType int const ( diff --git a/internal/services/configstore/configstore.go b/internal/services/configstore/configstore.go index f7e1749..374b995 100644 --- a/internal/services/configstore/configstore.go +++ b/internal/services/configstore/configstore.go @@ -27,6 +27,7 @@ import ( "github.com/sorintlab/agola/internal/services/config" "github.com/sorintlab/agola/internal/services/configstore/api" "github.com/sorintlab/agola/internal/services/configstore/command" + "github.com/sorintlab/agola/internal/services/configstore/common" "github.com/sorintlab/agola/internal/services/configstore/readdb" "github.com/sorintlab/agola/internal/util" "github.com/sorintlab/agola/internal/wal" @@ -72,8 +73,9 @@ func NewConfigStore(ctx context.Context, c *config.ConfigStore) (*ConfigStore, e } walConf := &wal.WalManagerConfig{ - E: e, - Lts: lts, + E: e, + Lts: lts, + DataToPathFunc: common.DataToPathFunc, } wal, err := wal.NewWalManager(ctx, logger, walConf) if err != nil { diff --git a/internal/services/configstore/configstore_test.go b/internal/services/configstore/configstore_test.go index 3465c6a..069c173 100644 --- a/internal/services/configstore/configstore_test.go +++ b/internal/services/configstore/configstore_test.go @@ -28,6 +28,7 @@ import ( "github.com/sorintlab/agola/internal/db" "github.com/sorintlab/agola/internal/services/config" + "github.com/sorintlab/agola/internal/services/configstore/command" "github.com/sorintlab/agola/internal/services/types" "github.com/sorintlab/agola/internal/testutil" "github.com/sorintlab/agola/internal/util" @@ -174,6 +175,7 @@ func TestResync(t *testing.T) { t.Fatalf("err: %v", err) } }() + t.Logf("starting cs2") go func() { if err := cs2.Run(ctx2); err != nil { t.Fatalf("err: %v", err) @@ -183,7 +185,7 @@ func TestResync(t *testing.T) { time.Sleep(1 * time.Second) for i := 0; i < 10; i++ { - if _, err := cs1.ch.CreateUser(ctx, &types.User{UserName: fmt.Sprintf("user%d", i)}); err != nil { + if _, err := cs1.ch.CreateUser(ctx, &command.CreateUserRequest{UserName: fmt.Sprintf("user%d", i)}); err != nil { t.Fatalf("err: %v", err) } time.Sleep(200 * time.Millisecond) @@ -197,7 +199,7 @@ func TestResync(t *testing.T) { // Do some more changes for i := 11; i < 20; i++ { - if _, err := cs1.ch.CreateUser(ctx, &types.User{UserName: fmt.Sprintf("user%d", i)}); err != nil { + if _, err := cs1.ch.CreateUser(ctx, &command.CreateUserRequest{UserName: fmt.Sprintf("user%d", i)}); err != nil { t.Fatalf("err: %v", err) } time.Sleep(200 * time.Millisecond) @@ -311,7 +313,7 @@ func TestUser(t *testing.T) { time.Sleep(2 * time.Second) t.Run("create user", func(t *testing.T) { - _, err := cs.ch.CreateUser(ctx, &types.User{UserName: "user01"}) + _, err := cs.ch.CreateUser(ctx, &command.CreateUserRequest{UserName: "user01"}) if err != nil { t.Fatalf("unexpected err: %v", err) } @@ -322,7 +324,7 @@ func TestUser(t *testing.T) { t.Run("create duplicated user", func(t *testing.T) { expectedErr := fmt.Sprintf("bad request: user with name %q already exists", "user01") - _, err := cs.ch.CreateUser(ctx, &types.User{UserName: "user01"}) + _, err := cs.ch.CreateUser(ctx, &command.CreateUserRequest{UserName: "user01"}) if err == nil { t.Fatalf("expected error %v, got nil err", expectedErr) } @@ -339,7 +341,7 @@ func TestUser(t *testing.T) { wg := sync.WaitGroup{} for i := 0; i < 10; i++ { wg.Add(1) - go cs.ch.CreateUser(ctx, &types.User{UserName: "user02"}) + go cs.ch.CreateUser(ctx, &command.CreateUserRequest{UserName: "user02"}) wg.Done() } wg.Wait() @@ -379,7 +381,7 @@ func TestProjectGroupsAndProjects(t *testing.T) { // TODO(sgotti) change the sleep with a real check that all is ready time.Sleep(2 * time.Second) - user, err := cs.ch.CreateUser(ctx, &types.User{UserName: "user01"}) + user, err := cs.ch.CreateUser(ctx, &command.CreateUserRequest{UserName: "user01"}) if err != nil { t.Fatalf("unexpected err: %v", err) }