diff --git a/Makefile b/Makefile index 4e5c390..4d96c8b 100644 --- a/Makefile +++ b/Makefile @@ -98,7 +98,7 @@ test: .PHONY: generate generate: - $(GOPATH)/bin/argen --path './example/model/repository' --fixture_path "example/testutil" + $(GOPATH)/bin/argen --path './example/model/repository' --fixture_path "example/testutil/fixture" .PHONY: install install: diff --git a/example/app_test.go b/example/app_test.go index 3a920b4..ede2468 100644 --- a/example/app_test.go +++ b/example/app_test.go @@ -101,25 +101,31 @@ func Test_main(t *testing.T) { t.Errorf("Can't select reward: %s", err) } + octopusMockServer.SetFixtures([]octopus.FixtureType{rewardByCodeMocker.EmptyByKeys(ctx, "64G_androi")}) + ret, err := reward.SelectByCode(ctx, "64G_androi") - if err == nil { + if err != nil { t.Errorf("select wrong reward. Returned: %+v, expected error", ret) } - octopusMockServer.SetFixtures([]octopus.FixtureType{}) + updateFxt, _ := fixture.GetUpdateRewardFixtureByCode(ctx, "64G_android", nil) - ret, err = reward.SelectByCode(ctx, "64G_android") - if err == nil { - t.Errorf("select reward after reset fixtures return: %+v, expected error", ret) + mockFxt := []octopus.FixtureType{ + rewardByCodeMocker.ByFixtureCode(ctx, "64G_android"), + updateFxt, } - err = rew.SetPartner("part") + mockFxt = append(mockFxt) + + octopusMockServer.SetFixtures(mockFxt) + + err = rew.SetPartner("sobakamiloru") if err != nil { t.Errorf("can't set partner field: %s", err) } err = rew.Update(ctx) - if err == nil { + if err != nil { t.Errorf("update reward unexpected error: %s", err) } @@ -128,6 +134,10 @@ func Test_main(t *testing.T) { t.Errorf("delete reward unexpected error: %s", err) } + insertFxt, _ := fixture.GetInsertRewardFixtureByCode(ctx, "new_code", nil) + + octopusMockServer.SetFixtures([]octopus.FixtureType{insertFxt}) + description := "new description" newRew := reward.New(ctx) @@ -148,7 +158,7 @@ func Test_main(t *testing.T) { } err = newRew.Insert(ctx) - if err == nil { + if err != nil { t.Errorf("update reward expected error: %s", err) } } diff --git a/example/model/repository/generated/arobj/fixture.go b/example/model/repository/generated/arobj/fixture.go index ea33c0a..e8a5ef1 100644 --- a/example/model/repository/generated/arobj/fixture.go +++ b/example/model/repository/generated/arobj/fixture.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package arobj import ( diff --git a/example/model/repository/generated/arobj/mock.go b/example/model/repository/generated/arobj/mock.go index 4101b7c..8bb4477 100644 --- a/example/model/repository/generated/arobj/mock.go +++ b/example/model/repository/generated/arobj/mock.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package arobj import ( diff --git a/example/model/repository/generated/arobj/octopus.go b/example/model/repository/generated/arobj/octopus.go index f7197be..8ca31b9 100644 --- a/example/model/repository/generated/arobj/octopus.go +++ b/example/model/repository/generated/arobj/octopus.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package arobj import ( diff --git a/example/model/repository/generated/boolindexed/fixture.go b/example/model/repository/generated/boolindexed/fixture.go index 701e6c3..bed39c1 100644 --- a/example/model/repository/generated/boolindexed/fixture.go +++ b/example/model/repository/generated/boolindexed/fixture.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package boolindexed import ( diff --git a/example/model/repository/generated/boolindexed/mock.go b/example/model/repository/generated/boolindexed/mock.go index cb871a0..e71ad28 100644 --- a/example/model/repository/generated/boolindexed/mock.go +++ b/example/model/repository/generated/boolindexed/mock.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package boolindexed import ( diff --git a/example/model/repository/generated/boolindexed/octopus.go b/example/model/repository/generated/boolindexed/octopus.go index 4b2b6b7..265910a 100644 --- a/example/model/repository/generated/boolindexed/octopus.go +++ b/example/model/repository/generated/boolindexed/octopus.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package boolindexed import ( diff --git a/example/model/repository/generated/category/fixture.go b/example/model/repository/generated/category/fixture.go index 8e6c7dd..023e6fe 100644 --- a/example/model/repository/generated/category/fixture.go +++ b/example/model/repository/generated/category/fixture.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package category import ( diff --git a/example/model/repository/generated/category/mock.go b/example/model/repository/generated/category/mock.go index d69b6d6..2ba39ee 100644 --- a/example/model/repository/generated/category/mock.go +++ b/example/model/repository/generated/category/mock.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package category import ( diff --git a/example/model/repository/generated/category/octopus.go b/example/model/repository/generated/category/octopus.go index cf98bdf..e5c0481 100644 --- a/example/model/repository/generated/category/octopus.go +++ b/example/model/repository/generated/category/octopus.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package category import ( diff --git a/example/model/repository/generated/foo/fixture.go b/example/model/repository/generated/foo/fixture.go index 1e6711e..fd95bb4 100644 --- a/example/model/repository/generated/foo/fixture.go +++ b/example/model/repository/generated/foo/fixture.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package foo import ( diff --git a/example/model/repository/generated/foo/mock.go b/example/model/repository/generated/foo/mock.go index c58d886..b7b6142 100644 --- a/example/model/repository/generated/foo/mock.go +++ b/example/model/repository/generated/foo/mock.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package foo import ( diff --git a/example/model/repository/generated/foo/octopus.go b/example/model/repository/generated/foo/octopus.go index 8d72031..4df88b9 100644 --- a/example/model/repository/generated/foo/octopus.go +++ b/example/model/repository/generated/foo/octopus.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package foo import ( diff --git a/example/model/repository/generated/promoperiods/fixture.go b/example/model/repository/generated/promoperiods/fixture.go index 171625d..8ef4043 100644 --- a/example/model/repository/generated/promoperiods/fixture.go +++ b/example/model/repository/generated/promoperiods/fixture.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package promoperiods import ( diff --git a/example/model/repository/generated/promoperiods/mock.go b/example/model/repository/generated/promoperiods/mock.go index eb4bea5..212500d 100644 --- a/example/model/repository/generated/promoperiods/mock.go +++ b/example/model/repository/generated/promoperiods/mock.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package promoperiods import ( diff --git a/example/model/repository/generated/promoperiods/octopus.go b/example/model/repository/generated/promoperiods/octopus.go index eba9f08..af35589 100644 --- a/example/model/repository/generated/promoperiods/octopus.go +++ b/example/model/repository/generated/promoperiods/octopus.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package promoperiods import ( diff --git a/example/model/repository/generated/repository.go b/example/model/repository/generated/repository.go new file mode 100644 index 0000000..edc20f5 --- /dev/null +++ b/example/model/repository/generated/repository.go @@ -0,0 +1,637 @@ +// Code generated by argen. DO NOT EDIT. +// This code was generated from a template. +// +// Manual changes to this file may cause unexpected behavior in your application. +// Manual changes to this file will be overwritten if the code is regenerated. +// +// Generate info: argen@v1.8.7 (Commit: e17c811b) +package repository + +import ( + "bytes" + "context" + "fmt" + "strconv" + + "github.com/mailru/activerecord-cookbook/example/model/repository/generated/arobj" + "github.com/mailru/activerecord-cookbook/example/model/repository/generated/boolindexed" + "github.com/mailru/activerecord-cookbook/example/model/repository/generated/category" + "github.com/mailru/activerecord-cookbook/example/model/repository/generated/foo" + "github.com/mailru/activerecord-cookbook/example/model/repository/generated/promoperiods" + "github.com/mailru/activerecord-cookbook/example/model/repository/generated/reward" + "github.com/mailru/activerecord/pkg/octopus" +) + +type SpaceMeta struct { + PackageName string + Unpacker func(ctx context.Context, tuple octopus.TupleData) (any, error) + Fields []FieldMeta + PK IndexMeta + Indexes map[string]IndexMeta +} + +type IndexMeta struct { + Name string + Unpacker func(packedKeys [][][]byte) (any, error) +} + +type FieldMeta struct { + Name string + Unpacker func(packedField []byte) (any, error) +} + +type NSPackage map[string]SpaceMeta + +func (ns NSPackage) meta(n uint32) (SpaceMeta, bool) { + v, ok := ns[strconv.Itoa(int(n))] + return v, ok +} + +var NamespacePackages = NSPackage{ + "5": { + PackageName: "arobj", + Unpacker: func(ctx context.Context, tuple octopus.TupleData) (any, error) { + obj, err := arobj.TupleToStruct(ctx, tuple) + if err != nil { + return nil, fmt.Errorf("can't decode tuple: %s", err) + } + + return arobj.MarshalFixtures([]*arobj.ArObj{obj}) + }, + Fields: []FieldMeta{ + + { + Name: "ID", + Unpacker: func(packedField []byte) (any, error) { + + return arobj.UnpackID(bytes.NewReader(packedField)) + }, + }, + + { + Name: "Name", + Unpacker: func(packedField []byte) (any, error) { + + return arobj.UnpackName(bytes.NewReader(packedField)) + }, + }, + + { + Name: "AnotherID", + Unpacker: func(packedField []byte) (any, error) { + + return arobj.UnpackAnotherID(bytes.NewReader(packedField)) + }, + }, + + { + Name: "Type", + Unpacker: func(packedField []byte) (any, error) { + + return arobj.UnpackType(bytes.NewReader(packedField)) + }, + }, + + { + Name: "Flags", + Unpacker: func(packedField []byte) (any, error) { + + return arobj.UnpackFlags(bytes.NewReader(packedField)) + }, + }, + }, + Indexes: map[string]IndexMeta{ + + "0.1": { + Name: "ID", + Unpacker: func(packedKeys [][][]byte) (any, error) { return arobj.UnpackKeyIndexID(packedKeys) }, + }, + "1.1": { + Name: "Type", + Unpacker: func(packedKeys [][][]byte) (any, error) { return arobj.UnpackKeyIndexType(packedKeys) }, + }, + "2.2": { + Name: "TypeID", + Unpacker: func(packedKeys [][][]byte) (any, error) { return arobj.UnpackKeyIndexTypeID(packedKeys) }, + }, + "2.1": { + Name: "TypePart", + Unpacker: func(packedKeys [][][]byte) (any, error) { return arobj.UnpackKeyIndexTypePart(packedKeys) }, + }, + }, + PK: IndexMeta{ + + Name: "ID", + Unpacker: func(packedKeys [][][]byte) (any, error) { return arobj.UnpackKeyIndexID(packedKeys) }, + }, + }, + "25": { + PackageName: "boolindexed", + Unpacker: func(ctx context.Context, tuple octopus.TupleData) (any, error) { + obj, err := boolindexed.TupleToStruct(ctx, tuple) + if err != nil { + return nil, fmt.Errorf("can't decode tuple: %s", err) + } + + return boolindexed.MarshalFixtures([]*boolindexed.Boolindexed{obj}) + }, + Fields: []FieldMeta{ + + { + Name: "Code", + Unpacker: func(packedField []byte) (any, error) { + + return boolindexed.UnpackCode(bytes.NewReader(packedField)) + }, + }, + + { + Name: "Invisible", + Unpacker: func(packedField []byte) (any, error) { + + return boolindexed.UnpackInvisible(bytes.NewReader(packedField)) + }, + }, + }, + Indexes: map[string]IndexMeta{ + + "0.1": { + Name: "Code", + Unpacker: func(packedKeys [][][]byte) (any, error) { return boolindexed.UnpackKeyIndexCode(packedKeys) }, + }, + "1.1": { + Name: "Invisible", + Unpacker: func(packedKeys [][][]byte) (any, error) { return boolindexed.UnpackKeyIndexInvisible(packedKeys) }, + }, + }, + PK: IndexMeta{ + + Name: "Code", + Unpacker: func(packedKeys [][][]byte) (any, error) { return boolindexed.UnpackKeyIndexCode(packedKeys) }, + }, + }, + "quantityOfCategories": { + PackageName: "category", + Unpacker: func(ctx context.Context, tuple octopus.TupleData) (any, error) { + obj, err := category.TupleToStruct(ctx, tuple) + if err != nil { + return nil, fmt.Errorf("can't decode tuple: %s", err) + } + + return category.MarshalFixtures([]*category.Category{obj}) + }, + Fields: []FieldMeta{}, + Indexes: map[string]IndexMeta{}, + PK: IndexMeta{}, + }, + "foo": { + PackageName: "foo", + Unpacker: func(ctx context.Context, tuple octopus.TupleData) (any, error) { + obj, err := foo.TupleToStruct(ctx, tuple) + if err != nil { + return nil, fmt.Errorf("can't decode tuple: %s", err) + } + + return foo.MarshalFixtures([]*foo.Foo{obj}) + }, + Fields: []FieldMeta{}, + Indexes: map[string]IndexMeta{}, + PK: IndexMeta{}, + }, + "6": { + PackageName: "promoperiods", + Unpacker: func(ctx context.Context, tuple octopus.TupleData) (any, error) { + obj, err := promoperiods.TupleToStruct(ctx, tuple) + if err != nil { + return nil, fmt.Errorf("can't decode tuple: %s", err) + } + + return promoperiods.MarshalFixtures([]*promoperiods.Promoperiods{obj}) + }, + Fields: []FieldMeta{ + + { + Name: "ID", + Unpacker: func(packedField []byte) (any, error) { + + return promoperiods.UnpackID(bytes.NewReader(packedField)) + }, + }, + + { + Name: "Code", + Unpacker: func(packedField []byte) (any, error) { + + return promoperiods.UnpackCode(bytes.NewReader(packedField)) + }, + }, + + { + Name: "Email", + Unpacker: func(packedField []byte) (any, error) { + + return promoperiods.UnpackEmail(bytes.NewReader(packedField)) + }, + }, + + { + Name: "Start", + Unpacker: func(packedField []byte) (any, error) { + + return promoperiods.UnpackStart(bytes.NewReader(packedField)) + }, + }, + + { + Name: "Finish", + Unpacker: func(packedField []byte) (any, error) { + field, err := promoperiods.UnpackFinish(bytes.NewReader(packedField)) + if err != nil { + return nil, err + } + + return promoperiods.MarshalFinish(field) + }, + }, + + { + Name: "Action", + Unpacker: func(packedField []byte) (any, error) { + + return promoperiods.UnpackAction(bytes.NewReader(packedField)) + }, + }, + + { + Name: "Platform", + Unpacker: func(packedField []byte) (any, error) { + field, err := promoperiods.UnpackPlatform(bytes.NewReader(packedField)) + if err != nil { + return nil, err + } + + return promoperiods.MarshalPlatform(field) + }, + }, + + { + Name: "Promobunch", + Unpacker: func(packedField []byte) (any, error) { + + return promoperiods.UnpackPromobunch(bytes.NewReader(packedField)) + }, + }, + + { + Name: "Platforms", + Unpacker: func(packedField []byte) (any, error) { + + return promoperiods.UnpackPlatforms(bytes.NewReader(packedField)) + }, + }, + + { + Name: "PlanID", + Unpacker: func(packedField []byte) (any, error) { + + return promoperiods.UnpackPlanID(bytes.NewReader(packedField)) + }, + }, + + { + Name: "PlanType", + Unpacker: func(packedField []byte) (any, error) { + + return promoperiods.UnpackPlanType(bytes.NewReader(packedField)) + }, + }, + + { + Name: "Price", + Unpacker: func(packedField []byte) (any, error) { + field, err := promoperiods.UnpackPrice(bytes.NewReader(packedField)) + if err != nil { + return nil, err + } + + return promoperiods.MarshalPrice(field) + }, + }, + }, + Indexes: map[string]IndexMeta{ + + "0.1": { + Name: "ID", + Unpacker: func(packedKeys [][][]byte) (any, error) { return promoperiods.UnpackKeyIndexID(packedKeys) }, + }, + "1.1": { + Name: "Code", + Unpacker: func(packedKeys [][][]byte) (any, error) { return promoperiods.UnpackKeyIndexCode(packedKeys) }, + }, + "2.1": { + Name: "Email", + Unpacker: func(packedKeys [][][]byte) (any, error) { return promoperiods.UnpackKeyIndexEmail(packedKeys) }, + }, + "3.2": { + Name: "PlanTypePrice", + Unpacker: func(packedKeys [][][]byte) (any, error) { return promoperiods.UnpackKeyIndexPlanTypePrice(packedKeys) }, + }, + "4.2": { + Name: "EmailCode", + Unpacker: func(packedKeys [][][]byte) (any, error) { return promoperiods.UnpackKeyIndexEmailCode(packedKeys) }, + }, + "5.2": { + Name: "EmailAction", + Unpacker: func(packedKeys [][][]byte) (any, error) { return promoperiods.UnpackKeyIndexEmailAction(packedKeys) }, + }, + "4.1": { + Name: "EmailPart", + Unpacker: func(packedKeys [][][]byte) (any, error) { return promoperiods.UnpackKeyIndexEmailPart(packedKeys) }, + }, + }, + PK: IndexMeta{ + + Name: "ID", + Unpacker: func(packedKeys [][][]byte) (any, error) { return promoperiods.UnpackKeyIndexID(packedKeys) }, + }, + }, + "24": { + PackageName: "reward", + Unpacker: func(ctx context.Context, tuple octopus.TupleData) (any, error) { + obj, err := reward.TupleToStruct(ctx, tuple) + if err != nil { + return nil, fmt.Errorf("can't decode tuple: %s", err) + } + + return reward.MarshalFixtures([]*reward.Reward{obj}) + }, + Fields: []FieldMeta{ + + { + Name: "Code", + Unpacker: func(packedField []byte) (any, error) { + + return reward.UnpackCode(bytes.NewReader(packedField)) + }, + }, + + { + Name: "Services", + Unpacker: func(packedField []byte) (any, error) { + field, err := reward.UnpackServices(bytes.NewReader(packedField)) + if err != nil { + return nil, err + } + + return reward.MarshalServices(field) + }, + }, + + { + Name: "Partner", + Unpacker: func(packedField []byte) (any, error) { + + return reward.UnpackPartner(bytes.NewReader(packedField)) + }, + }, + + { + Name: "Extra", + Unpacker: func(packedField []byte) (any, error) { + field, err := reward.UnpackExtra(bytes.NewReader(packedField)) + if err != nil { + return nil, err + } + + return reward.MarshalExtra(field) + }, + }, + + { + Name: "Flags", + Unpacker: func(packedField []byte) (any, error) { + field, err := reward.UnpackFlags(bytes.NewReader(packedField)) + if err != nil { + return nil, err + } + + return reward.MarshalFlags(field) + }, + }, + + { + Name: "Unlocked", + Unpacker: func(packedField []byte) (any, error) { + field, err := reward.UnpackUnlocked(bytes.NewReader(packedField)) + if err != nil { + return nil, err + } + + return reward.MarshalUnlocked(field) + }, + }, + + { + Name: "Description", + Unpacker: func(packedField []byte) (any, error) { + field, err := reward.UnpackDescription(bytes.NewReader(packedField)) + if err != nil { + return nil, err + } + + return reward.MarshalDescription(field) + }, + }, + }, + Indexes: map[string]IndexMeta{ + + "0.1": { + Name: "Code", + Unpacker: func(packedKeys [][][]byte) (any, error) { return reward.UnpackKeyIndexCode(packedKeys) }, + }, + "1.1": { + Name: "Partner", + Unpacker: func(packedKeys [][][]byte) (any, error) { return reward.UnpackKeyIndexPartner(packedKeys) }, + }, + }, + PK: IndexMeta{ + + Name: "Code", + Unpacker: func(packedKeys [][][]byte) (any, error) { return reward.UnpackKeyIndexCode(packedKeys) }, + }, + }, +} + +func (n NSPackage) GetSelectDebugInfo(ns uint32, indexnum uint32, offset uint32, limit uint32, keys [][][]byte, fixture ...octopus.SelectMockFixture) string { + spacemeta, ex := n.meta(ns) + if !ex { + return fmt.Sprintf("unknown space %d, index: %d, offset: %d, limit: %d, Keys: %+v", ns, indexnum, offset, limit, keys) + } + + fmtStr := "\n" + n.formatSelectMockFixture(ns, spacemeta, indexnum, offset, limit, keys) + "\n" + fmtStr = fmt.Sprintf("%s\n--------------Installed 'Select' fixtures %s --------------\n", fmtStr, spacemeta.PackageName) + for _, f := range fixture { + fmtStr = fmtStr + "\n" + n.formatSelectMockFixture(ns, spacemeta, f.Indexnum, f.Offset, f.Limit, f.Keys) + " \n" + + for _, tuple := range f.RespTuples { + strRespObj, err := spacemeta.Unpacker(context.TODO(), tuple) + if err != nil { + return fmt.Sprintf("Space: %d (%s), tuple: %+v (err unpack: %s)", ns, spacemeta.PackageName, tuple, err) + } + + fmtStr = fmtStr + "\n" + fmt.Sprintf("%s", strRespObj) + "\n" + + } + } + + fmtStr = fmt.Sprintf("%s\n--------------End Installed 'Select' fixtures %s-----------\n\n\n\n", fmtStr, spacemeta.PackageName) + + return fmtStr +} + +func (n NSPackage) formatSelectMockFixture(ns uint32, spacemeta SpaceMeta, indexnum uint32, offset uint32, limit uint32, keys [][][]byte) string { + if len(keys) == 0 { + return fmt.Sprintf("Space: %d (%s), index: %d, offset: %d, limit: %d, Empty Key Values", ns, spacemeta.PackageName, indexnum, offset, limit) + } + + ind, ex := spacemeta.Indexes[fmt.Sprintf("%d.%d", indexnum, len(keys[0]))] + if !ex { + return fmt.Sprintf("space %d (%s), unknown index: %d (%d.%d), offset: %d, limit: %d, Keys: %+v", ns, spacemeta.PackageName, indexnum, indexnum, len(keys[0]), offset, limit, keys) + } + + unpackedKeys, err := ind.Unpacker(keys) + if err != nil { + return fmt.Sprintf("Space: %d (%s), index: %d (%s), offset: %d, limit: %d, Keys: %+v (error unpack: %s)", ns, spacemeta.PackageName, indexnum, ind.Name, offset, limit, keys, err) + } + + return fmt.Sprintf("Space: %d (%s), index: %d (%s), offset: %d, limit: %d, Keys: %+v", ns, spacemeta.PackageName, indexnum, ind.Name, offset, limit, unpackedKeys) +} + +func (n NSPackage) GetUpdateDebugInfo(ns uint32, primaryKey [][]byte, updateOps []octopus.Ops, fixture ...octopus.UpdateMockFixture) string { + spacemeta, ex := n.meta(ns) + if !ex { + return fmt.Sprintf("unknown space %d, primaryKey: %+v, updateOps: %+v", ns, primaryKey, updateOps) + } + + fmtStr := "\n" + n.formatUpdateMockFixture(ns, spacemeta, primaryKey, updateOps) + "\n" + fmtStr = fmt.Sprintf("%s\n--------------Installed 'Update' fixtures %s --------------\n", fmtStr, spacemeta.PackageName) + for _, f := range fixture { + fmtStr = fmtStr + "\n" + n.formatUpdateMockFixture(ns, spacemeta, f.PrimaryKey, f.UpdateOps) + "\n" + } + + fmtStr = fmt.Sprintf("%s\n--------------End Installed 'Update' fixtures %s-----------\n\n\n\n", fmtStr, spacemeta.PackageName) + + return fmtStr +} + +func (n NSPackage) formatUpdateMockFixture(ns uint32, spacemeta SpaceMeta, primaryKey [][]byte, updateOps []octopus.Ops) string { + unpackedKeys, err := spacemeta.PK.Unpacker([][][]byte{primaryKey}) + if err != nil { + return fmt.Sprintf("Space: %d (%s), primaryKey: %+v, updateOps: %+v (error unpack: %s)", ns, spacemeta.PackageName, primaryKey, updateOps, err) + } + + updateFields := "" + + for _, op := range updateOps { + val, err := spacemeta.Fields[op.Field].Unpacker(op.Value) + if err != nil { + val = fmt.Sprintf("% X (can't unpack: %s)", op.Value, err) + } + + updateFields += fmt.Sprintf("%s %s <= `%v`; ", octopus.GetOpCodeName(op.Op), spacemeta.Fields[op.Field].Name, val) + } + + return fmt.Sprintf("Space: %d (%s), primaryKey: %s (%+v), updateOps: %s", ns, spacemeta.PackageName, spacemeta.PK.Name, unpackedKeys, updateFields) +} + +func (n NSPackage) GetDeleteDebugInfo(ns uint32, primaryKey [][]byte, fixture ...octopus.DeleteMockFixture) string { + spacemeta, ex := n.meta(ns) + if !ex { + return fmt.Sprintf("unknown space %d, primaryKey: %+v", ns, primaryKey) + } + + fmtStr := "\n" + n.formatDeleteMockFixture(ns, spacemeta, primaryKey) + "\n" + fmtStr = fmt.Sprintf("%s\n--------------Installed 'Delete' fixtures %s --------------\n", fmtStr, spacemeta.PackageName) + for _, f := range fixture { + fmtStr = fmtStr + "\n" + n.formatDeleteMockFixture(ns, spacemeta, f.PrimaryKey) + "\n" + } + + fmtStr = fmt.Sprintf("%s\n--------------End Installed 'Delete' fixtures %s-----------\n\n\n\n", fmtStr, spacemeta.PackageName) + + return fmtStr +} + +func (n NSPackage) formatDeleteMockFixture(ns uint32, spacemeta SpaceMeta, primaryKey [][]byte) string { + unpackedKeys, err := spacemeta.PK.Unpacker([][][]byte{primaryKey}) + if err != nil { + return fmt.Sprintf("Space: %d (%s), primaryKey: %+v (error unpack: %s)", ns, spacemeta.PackageName, primaryKey, err) + } + + return fmt.Sprintf("Space: %d (%s), primaryKey: %s (%+v)", ns, spacemeta.PackageName, spacemeta.PK.Name, unpackedKeys) +} + +func (n NSPackage) GetInsertDebugInfo(ns uint32, needRetVal bool, insertMode octopus.InsertMode, tuple octopus.TupleData, fixture ...octopus.InsertMockFixture) string { + strMode := octopus.GetInsertModeName(insertMode) + + spacemeta, ex := n.meta(ns) + if !ex { + return fmt.Sprintf("unknown space %d, insertMode: %s, tuple: %+v", ns, strMode, tuple) + } + + fmtStr := "\n" + n.formatInsertMockFixture(ns, spacemeta, needRetVal, insertMode, tuple) + "\n" + fmtStr = fmt.Sprintf("%s\n--------------Installed 'Insert' fixtures %s --------------\n", fmtStr, spacemeta.PackageName) + for _, f := range fixture { + fmtStr = fmtStr + "\n" + n.formatInsertMockFixture(ns, spacemeta, f.NeedRetVal, f.InsertMode, f.Tuple) + "\n" + } + + fmtStr = fmt.Sprintf("%s\n--------------End Installed 'Insert' fixtures %s------------\n\n\n\n", fmtStr, spacemeta.PackageName) + + return fmtStr +} + +func (n NSPackage) formatInsertMockFixture(ns uint32, spacemeta SpaceMeta, needRetVal bool, insertMode octopus.InsertMode, tuple octopus.TupleData) string { + strMode := octopus.GetInsertModeName(insertMode) + + strObj, err := spacemeta.Unpacker(context.TODO(), tuple) + if err != nil { + return fmt.Sprintf("Space: %d (%s), insertMode: %s, tuple: %+v (err unpack: %s)", ns, spacemeta.PackageName, strMode, tuple, err) + } + + return fmt.Sprintf("Space: %d (%s), insertMode: %s, tuple: \n%s", ns, spacemeta.PackageName, strMode, strObj) +} + +func (n NSPackage) GetCallDebugInfo(ns string, args [][]byte, fixture ...octopus.CallMockFixture) string { + spacemeta, ex := n[ns] + if !ex { + return fmt.Sprintf("unknown procedure %s, arguments: %+v", ns, args) + } + + fmtStr := "\n" + n.formatCallMockFixture(ns, args) + "\n" + fmtStr = fmt.Sprintf("%s\n--------------Installed 'Call' fixtures %s --------------\n", fmtStr, spacemeta.PackageName) + for _, f := range fixture { + fmtStr = fmtStr + "\n" + n.formatCallMockFixture(ns, f.Args) + " \n" + + for _, tuple := range f.RespTuples { + strRespObj, err := spacemeta.Unpacker(context.TODO(), tuple) + if err != nil { + return fmt.Sprintf("Procedure: %s, tuple: %+v (err unpack: %s)", ns, tuple, err) + } + + fmtStr = fmtStr + "\n" + fmt.Sprintf("%s", strRespObj) + "\n" + } + } + + fmtStr = fmt.Sprintf("%s\n--------------End Installed 'Call' fixtures %s-----------\n\n\n\n", fmtStr, spacemeta.PackageName) + + return fmtStr +} + +func (n NSPackage) formatCallMockFixture(ns string, args [][]byte) string { + var unpackedArgs []string + + for _, arg := range args { + unpackedArgs = append(unpackedArgs, string(arg)) + } + + return fmt.Sprintf("Procedure: %s, arguments: %s", ns, unpackedArgs) +} diff --git a/example/model/repository/generated/reward/fixture.go b/example/model/repository/generated/reward/fixture.go index bb3fb13..18012ce 100644 --- a/example/model/repository/generated/reward/fixture.go +++ b/example/model/repository/generated/reward/fixture.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package reward import ( diff --git a/example/model/repository/generated/reward/mock.go b/example/model/repository/generated/reward/mock.go index cf4a298..752c3cb 100644 --- a/example/model/repository/generated/reward/mock.go +++ b/example/model/repository/generated/reward/mock.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package reward import ( diff --git a/example/model/repository/generated/reward/octopus.go b/example/model/repository/generated/reward/octopus.go index 0947537..a11701f 100644 --- a/example/model/repository/generated/reward/octopus.go +++ b/example/model/repository/generated/reward/octopus.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.8.5-1-gaa389f8 (Commit: aa389f82) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package reward import ( diff --git a/example/test/any/data/category.yaml b/example/test/any/data/category.yaml deleted file mode 100755 index e69de29..0000000 diff --git a/example/test/any/data/category_insert_replace.yaml b/example/test/any/data/category_insert_replace.yaml deleted file mode 100755 index e69de29..0000000 diff --git a/example/test/any/data/category_update.yaml b/example/test/any/data/category_update.yaml deleted file mode 100755 index e69de29..0000000 diff --git a/example/testutil/fixture/arobj_gen.go b/example/testutil/fixture/arobj_gen.go index a6beedf..58133ee 100644 --- a/example/testutil/fixture/arobj_gen.go +++ b/example/testutil/fixture/arobj_gen.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.5.3-18-g3247b15 (Commit: 3247b15e) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package fixture import ( @@ -124,6 +124,18 @@ func GetInsertReplaceArObjByID(ID int32) *arobj.ArObj { return res } +func GetDeleteArObjFixtureByPrimaryKey(ctx context.Context, pk int32, trigger func(types []octopus.FixtureType) []octopus.FixtureType) (fx octopus.FixtureType, promiseIsUsed func() bool) { + obj := arobj.New(ctx) + + if err := obj.SetID(pk); err != nil { + log.Fatalf("SetID error: %v", err) + } + + wrappedTrigger, promiseIsUsed := octopus.WrapTriggerWithOnUsePromise(trigger) + + return octopus.CreateDeleteFixture(obj.MockDelete(ctx), wrappedTrigger), promiseIsUsed +} + func GetUpdateArObjFixtureByID(ctx context.Context, ID int32, trigger func(types []octopus.FixtureType) []octopus.FixtureType) (fx octopus.FixtureType, promiseIsUsed func() bool) { obj := GetUpdateArObjByID(ID) diff --git a/example/testutil/fixture/boolindexed_gen.go b/example/testutil/fixture/boolindexed_gen.go index 3dbbdc9..444696e 100644 --- a/example/testutil/fixture/boolindexed_gen.go +++ b/example/testutil/fixture/boolindexed_gen.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.5.3-18-g3247b15 (Commit: 3247b15e) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package fixture import ( @@ -124,6 +124,18 @@ func GetInsertReplaceBoolindexedByCode(Code string) *boolindexed.Boolindexed { return res } +func GetDeleteBoolindexedFixtureByPrimaryKey(ctx context.Context, pk string, trigger func(types []octopus.FixtureType) []octopus.FixtureType) (fx octopus.FixtureType, promiseIsUsed func() bool) { + obj := boolindexed.New(ctx) + + if err := obj.SetCode(pk); err != nil { + log.Fatalf("SetCode error: %v", err) + } + + wrappedTrigger, promiseIsUsed := octopus.WrapTriggerWithOnUsePromise(trigger) + + return octopus.CreateDeleteFixture(obj.MockDelete(ctx), wrappedTrigger), promiseIsUsed +} + func GetUpdateBoolindexedFixtureByCode(ctx context.Context, Code string, trigger func(types []octopus.FixtureType) []octopus.FixtureType) (fx octopus.FixtureType, promiseIsUsed func() bool) { obj := GetUpdateBoolindexedByCode(Code) diff --git a/example/testutil/fixture/category_gen.go b/example/testutil/fixture/category_gen.go index 40bc5c9..7eccb27 100644 --- a/example/testutil/fixture/category_gen.go +++ b/example/testutil/fixture/category_gen.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.5.3-18-g3247b15 (Commit: 3247b15e) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package fixture import ( diff --git a/example/testutil/fixture/data/reward_insert_replace.yaml b/example/testutil/fixture/data/reward_insert_replace.yaml index e69de29..28781cf 100644 --- a/example/testutil/fixture/data/reward_insert_replace.yaml +++ b/example/testutil/fixture/data/reward_insert_replace.yaml @@ -0,0 +1,8 @@ +- code: new_code + description: new description + extra: + title: "" + prepaid: false + other: { } + flags: + a: b \ No newline at end of file diff --git a/example/testutil/fixture/data/reward_update.yaml b/example/testutil/fixture/data/reward_update.yaml index 39fba85..7c68144 100644 --- a/example/testutil/fixture/data/reward_update.yaml +++ b/example/testutil/fixture/data/reward_update.yaml @@ -1,11 +1,5 @@ - code: 64G_android update_options: # приоритет в порядке упоминания - - services: - set_value: - flags: - UFLAG_PAID_ACCOUNT: true - UFLAG_PAID_UPLOAD: true - quota: 2.74877906944e+11 - partner: set_value: sobakamiloru \ No newline at end of file diff --git a/example/testutil/fixture/foo_gen.go b/example/testutil/fixture/foo_gen.go index 9d134da..de1b519 100644 --- a/example/testutil/fixture/foo_gen.go +++ b/example/testutil/fixture/foo_gen.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.5.3-18-g3247b15 (Commit: 3247b15e) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package fixture import ( diff --git a/example/testutil/fixture/promoperiods_gen.go b/example/testutil/fixture/promoperiods_gen.go index 051bec5..b7e713d 100644 --- a/example/testutil/fixture/promoperiods_gen.go +++ b/example/testutil/fixture/promoperiods_gen.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.5.3-18-g3247b15 (Commit: 3247b15e) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package fixture import ( @@ -125,6 +125,18 @@ func GetInsertReplacePromoperiodsByID(ID string) *promoperiods.Promoperiods { return res } +func GetDeletePromoperiodsFixtureByPrimaryKey(ctx context.Context, pk string, trigger func(types []octopus.FixtureType) []octopus.FixtureType) (fx octopus.FixtureType, promiseIsUsed func() bool) { + obj := promoperiods.New(ctx) + + if err := obj.SetID(pk); err != nil { + log.Fatalf("SetID error: %v", err) + } + + wrappedTrigger, promiseIsUsed := octopus.WrapTriggerWithOnUsePromise(trigger) + + return octopus.CreateDeleteFixture(obj.MockDelete(ctx), wrappedTrigger), promiseIsUsed +} + func GetUpdatePromoperiodsFixtureByID(ctx context.Context, ID string, trigger func(types []octopus.FixtureType) []octopus.FixtureType) (fx octopus.FixtureType, promiseIsUsed func() bool) { obj := GetUpdatePromoperiodsByID(ID) diff --git a/example/testutil/fixture/reward_gen.go b/example/testutil/fixture/reward_gen.go index c20a556..78d8b02 100644 --- a/example/testutil/fixture/reward_gen.go +++ b/example/testutil/fixture/reward_gen.go @@ -4,7 +4,7 @@ // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // -// Generate info: argen@v1.5.3-18-g3247b15 (Commit: 3247b15e) +// Generate info: argen@v1.8.7 (Commit: e17c811b) package fixture import ( @@ -125,6 +125,18 @@ func GetInsertReplaceRewardByCode(Code string) *reward.Reward { return res } +func GetDeleteRewardFixtureByPrimaryKey(ctx context.Context, pk string, trigger func(types []octopus.FixtureType) []octopus.FixtureType) (fx octopus.FixtureType, promiseIsUsed func() bool) { + obj := reward.New(ctx) + + if err := obj.SetCode(pk); err != nil { + log.Fatalf("SetCode error: %v", err) + } + + wrappedTrigger, promiseIsUsed := octopus.WrapTriggerWithOnUsePromise(trigger) + + return octopus.CreateDeleteFixture(obj.MockDelete(ctx), wrappedTrigger), promiseIsUsed +} + func GetUpdateRewardFixtureByCode(ctx context.Context, Code string, trigger func(types []octopus.FixtureType) []octopus.FixtureType) (fx octopus.FixtureType, promiseIsUsed func() bool) { obj := GetUpdateRewardByCode(Code)