Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/actions/setup-autoupdate-pr/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ runs:
- name: Set up go
uses: actions/setup-go@v7
with:
go-version: "1.26"
go-version: "1.27"

- name: Run go generate
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Set up go
uses: actions/setup-go@v7
with:
go-version: "1.26"
go-version: "1.27"

# This is done, because setup-action will be called from here
- uses: actions/checkout@v7
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: "1.26"
go-version: "1.27"

- name: Check out code into the Go module directory
uses: actions/checkout@v7
Expand Down
51 changes: 30 additions & 21 deletions datastore/dsmock/yaml_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@ import (

// YAMLData creates key values from a yaml object.
//
// It is expected, that the input is a constant string. So there can not be any
// error at runtime. Therefore this function does not return an error but panics
// to get the developer a fast feetback.
// panics on error.
//
// Deprecated: Use [YAMLDataErr] instead. This function could be removed in the
// future.
func YAMLData(input string) map[dskey.Key][]byte {
r, err := YAMLDataErr(input)
if err != nil {
panic(err)
}
return r
}

// YAMLDataErr creates key values from a yaml object.
func YAMLDataErr(input string) (map[dskey.Key][]byte, error) {
input = strings.ReplaceAll(input, "\t", " ")

var db map[string]any
if err := yaml.Unmarshal([]byte(input), &db); err != nil {
panic(err)
return nil, fmt.Errorf("unmarshalling yaml: %w", err)
}

data := make(map[dskey.Key][]byte)
Expand All @@ -31,91 +41,90 @@ func YAMLData(input string) map[dskey.Key][]byte {
case 1:
map1, ok := dbValue.(map[string]any)
if !ok {
panic(fmt.Errorf("invalid type in db key %s: %T", dbKey, dbValue))
return nil, fmt.Errorf("invalid type in db key %s: %T", dbKey, dbValue)
}
for rawID, rawObject := range map1 {
id, err := strconv.Atoi(rawID)
if err != nil {
panic(fmt.Errorf("invalid id type: got %T expected int", rawID))
return nil, fmt.Errorf("invalid id type: got %T expected int", rawID)
}
field, ok := rawObject.(map[string]any)
if !ok {
panic(fmt.Errorf("invalid object type: got %T, expected map[string]any", rawObject))
return nil, fmt.Errorf("invalid object type: got %T, expected map[string]any", rawObject)
}

for fieldName, fieldValue := range field {
key, err := dskey.FromParts(dbKey, id, fieldName)
if err != nil {
panic(err)
return nil, fmt.Errorf("creating key from %s, %d, %s: %w", dbKey, id, fieldName, err)
}

bs, err := json.Marshal(fieldValue)
if err != nil {
panic(fmt.Errorf("creating test db. Key %s: %w", key, err))
return nil, fmt.Errorf("creating value for key %s: %w", key, err)
}

data[key] = bs
}

idKey, err := dskey.FromParts(dbKey, id, "id")
if err != nil {
panic(err)
return nil, fmt.Errorf("creating id-key from %s, %d: %w", dbKey, id, err)
}
data[idKey] = []byte(strconv.Itoa(id))
}

case 2:
field, ok := dbValue.(map[string]any)
if !ok {
panic(fmt.Errorf("invalid object type: got %T, expected map[string]interface{}", dbValue))
return nil, fmt.Errorf("invalid object type: got %T, expected map[string]interface{}", dbValue)
}

id, err := strconv.Atoi(parts[1])
if err != nil {
panic(err)
return nil, fmt.Errorf("converting to int %s: %w", parts[1], err)
}

for fieldName, fieldValue := range field {

fqfield, err := dskey.FromParts(parts[0], id, fieldName)
if err != nil {
panic(err)
return nil, fmt.Errorf("creating key from %s, %d, %s: %w", parts[0], id, fieldName, err)
}

bs, err := json.Marshal(fieldValue)
if err != nil {
panic(fmt.Errorf("creating test db. Key %s: %w", fqfield, err))
return nil, fmt.Errorf("creating value for key %s: %w", fqfield, err)
}
data[fqfield] = bs
}

idKey, err := dskey.FromParts(parts[0], id, "id")
if err != nil {
panic(err)
return nil, fmt.Errorf("creating id-key from %s, %d: %w", parts[0], id, err)
}
data[idKey] = []byte(parts[1])

case 3:
key := dskey.MustKey(dbKey)
bs, err := json.Marshal(dbValue)
if err != nil {
panic(fmt.Errorf("creating test db. Key %s: %w", dbKey, err))
return nil, fmt.Errorf("creating test db. Key %s: %w", dbKey, err)
}

data[key] = bs

id, err := strconv.Atoi(parts[1])
if err != nil {
panic(err)
return nil, fmt.Errorf("converting to int %s: %w", parts[1], err)
}

idKey, err := dskey.FromParts(parts[0], id, "id")
if err != nil {
panic(err)
return nil, fmt.Errorf("creating id-key from %s, %d: %w", parts[0], id, err)
}
data[idKey] = []byte(parts[1])
default:
panic(fmt.Errorf("invalid db key %s", dbKey))
return nil, fmt.Errorf("invalid db key %s", dbKey)
}
}

Expand All @@ -125,5 +134,5 @@ func YAMLData(input string) map[dskey.Key][]byte {
}
}

return data
return data, nil
}
17 changes: 12 additions & 5 deletions datastore/pgtest/insert_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,15 @@ func genNMInfo(key dskey.Key, value []byte) (nmInfo, error) {
reverse = true
}

c1, f1 := splitCollectionName(cfs[0])
c2, _ := splitCollectionName(cfs[1])
c1, f1, err := splitCollectionName(cfs[0])
if err != nil {
return nmInfo{}, fmt.Errorf("split collection name %s: %w", cfs[0], err)
}
c2, _, err := splitCollectionName(cfs[1])
if err != nil {
return nmInfo{}, fmt.Errorf("split collection name %s: %w", cfs[1], err)
}

nmTableName := fmt.Sprintf("nm_%s_%s_%s_t", c1, f1, c2)

otherIDs, err := fastjson.DecodeIntList(value)
Expand All @@ -191,12 +198,12 @@ func genNMInfo(key dskey.Key, value []byte) (nmInfo, error) {
}, nil
}

func splitCollectionName(cf string) (string, string) {
func splitCollectionName(cf string) (string, string, error) {
parts := strings.Split(cf, "/")
if len(parts) != 2 {
panic(fmt.Sprintf("invalid collection name %s", cf))
return "", "", fmt.Errorf("invalid collection name %s", cf)
}
return parts[0], parts[1]
return parts[0], parts[1], nil
}

func inserNMData(ctx context.Context, tx pgx.Tx, nm nmInfo) error {
Expand Down
Loading