-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
2,258 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package database_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"opencsg.com/csghub-server/builder/store/database" | ||
"opencsg.com/csghub-server/common/tests" | ||
) | ||
|
||
func TestEventStore_Save(t *testing.T) { | ||
db := tests.InitTestDB() | ||
defer db.Close() | ||
ctx := context.TODO() | ||
|
||
store := database.NewEventStoreWithDB(db) | ||
err := store.Save(ctx, database.Event{ | ||
Module: "m1", | ||
}) | ||
require.Nil(t, err) | ||
event := &database.Event{} | ||
err = db.Core.NewSelect().Model(event).Where("module=?", "m1").Scan(ctx) | ||
require.Nil(t, err) | ||
require.Equal(t, "m1", event.Module) | ||
|
||
err = store.BatchSave(ctx, []database.Event{ | ||
{Module: "m2"}, | ||
{Module: "m3"}, | ||
}) | ||
require.Nil(t, err) | ||
err = db.Core.NewSelect().Model(event).Where("module=?", "m2").Scan(ctx) | ||
require.Nil(t, err) | ||
require.Equal(t, "m2", event.Module) | ||
err = db.Core.NewSelect().Model(event).Where("module=?", "m3").Scan(ctx) | ||
require.Nil(t, err) | ||
require.Equal(t, "m3", event.Module) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package database_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"opencsg.com/csghub-server/builder/store/database" | ||
"opencsg.com/csghub-server/common/tests" | ||
) | ||
|
||
func TestLfsLockStore_CRUD(t *testing.T) { | ||
db := tests.InitTestDB() | ||
defer db.Close() | ||
ctx := context.TODO() | ||
|
||
store := database.NewLfsLockStoreWithDB(db) | ||
_, err := store.Create(ctx, database.LfsLock{ | ||
RepositoryID: 123, | ||
Path: "foo/bar", | ||
}) | ||
require.Nil(t, err) | ||
|
||
lock := &database.LfsLock{} | ||
err = db.Core.NewSelect().Model(lock).Scan(ctx) | ||
require.Nil(t, err) | ||
require.Equal(t, "foo/bar", lock.Path) | ||
|
||
lock, err = store.FindByID(ctx, lock.ID) | ||
require.Nil(t, err) | ||
require.Equal(t, "foo/bar", lock.Path) | ||
|
||
lock, err = store.FindByPath(ctx, 123, "foo/bar") | ||
require.Nil(t, err) | ||
require.Equal(t, "foo/bar", lock.Path) | ||
|
||
ls, err := store.FindByRepoID(ctx, 123, 1, 10) | ||
require.Nil(t, err) | ||
require.Equal(t, 1, len(ls)) | ||
require.Equal(t, "foo/bar", ls[0].Path) | ||
|
||
err = store.RemoveByID(ctx, lock.ID) | ||
require.Nil(t, err) | ||
_, err = store.FindByID(ctx, lock.ID) | ||
require.NotNil(t, err) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package database_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"opencsg.com/csghub-server/builder/store/database" | ||
"opencsg.com/csghub-server/common/tests" | ||
) | ||
|
||
func TestLfsMetaStore_CRUD(t *testing.T) { | ||
db := tests.InitTestDB() | ||
defer db.Close() | ||
ctx := context.TODO() | ||
|
||
store := database.NewLfsMetaObjectStoreWithDB(db) | ||
_, err := store.Create(ctx, database.LfsMetaObject{ | ||
RepositoryID: 123, | ||
Oid: "foobar", | ||
}) | ||
require.Nil(t, err) | ||
|
||
obj := &database.LfsMetaObject{} | ||
err = db.Core.NewSelect().Model(obj).Scan(ctx) | ||
require.Nil(t, err) | ||
require.Equal(t, "foobar", obj.Oid) | ||
|
||
obj, err = store.FindByOID(ctx, 123, "foobar") | ||
require.Nil(t, err) | ||
require.Equal(t, "foobar", obj.Oid) | ||
|
||
objs, err := store.FindByRepoID(ctx, 123) | ||
require.Nil(t, err) | ||
require.Equal(t, 1, len(objs)) | ||
require.Equal(t, "foobar", objs[0].Oid) | ||
|
||
// update | ||
_, err = store.UpdateOrCreate(ctx, database.LfsMetaObject{ | ||
RepositoryID: 123, | ||
Oid: "foobar", | ||
Size: 999, | ||
}) | ||
require.Nil(t, err) | ||
obj, err = store.FindByOID(ctx, 123, "foobar") | ||
require.Nil(t, err) | ||
require.Equal(t, 999, int(obj.Size)) | ||
|
||
// create | ||
_, err = store.UpdateOrCreate(ctx, database.LfsMetaObject{ | ||
RepositoryID: 456, | ||
Oid: "bar", | ||
Size: 998, | ||
}) | ||
require.Nil(t, err) | ||
obj, err = store.FindByOID(ctx, 456, "bar") | ||
require.Nil(t, err) | ||
require.Equal(t, 998, int(obj.Size)) | ||
|
||
err = store.BulkUpdateOrCreate(ctx, []database.LfsMetaObject{ | ||
{RepositoryID: 123, Oid: "foobar", Size: 1}, | ||
{RepositoryID: 456, Oid: "bar", Size: 2}, | ||
{RepositoryID: 789, Oid: "barfoo", Size: 3}, | ||
}) | ||
require.Nil(t, err) | ||
|
||
obj, err = store.FindByOID(ctx, 123, "foobar") | ||
require.Nil(t, err) | ||
require.Equal(t, 1, int(obj.Size)) | ||
obj, err = store.FindByOID(ctx, 456, "bar") | ||
require.Nil(t, err) | ||
require.Equal(t, 2, int(obj.Size)) | ||
obj, err = store.FindByOID(ctx, 789, "barfoo") | ||
require.Nil(t, err) | ||
require.Equal(t, 3, int(obj.Size)) | ||
|
||
err = store.RemoveByOid(ctx, "foobar", 123) | ||
require.Nil(t, err) | ||
_, err = store.FindByOID(ctx, 123, "foobar") | ||
require.NotNil(t, err) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package database_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"opencsg.com/csghub-server/builder/store/database" | ||
"opencsg.com/csghub-server/common/tests" | ||
) | ||
|
||
func TestLLMConfigStore_GetOptimization(t *testing.T) { | ||
db := tests.InitTestDB() | ||
defer db.Close() | ||
ctx := context.TODO() | ||
|
||
store := database.NewLLMConfigStoreWithDB(db) | ||
_, err := db.Core.NewInsert().Model(&database.LLMConfig{ | ||
Type: 1, | ||
Enabled: true, | ||
ModelName: "c1", | ||
}).Exec(ctx) | ||
require.Nil(t, err) | ||
_, err = db.Core.NewInsert().Model(&database.LLMConfig{ | ||
Type: 2, | ||
Enabled: true, | ||
ModelName: "c2", | ||
}).Exec(ctx) | ||
require.Nil(t, err) | ||
_, err = db.Core.NewInsert().Model(&database.LLMConfig{ | ||
Type: 1, | ||
Enabled: false, | ||
ModelName: "c3", | ||
}).Exec(ctx) | ||
require.Nil(t, err) | ||
|
||
cfg, err := store.GetOptimization(ctx) | ||
require.Nil(t, err) | ||
require.Equal(t, "c1", cfg.ModelName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package database_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"opencsg.com/csghub-server/builder/store/database" | ||
"opencsg.com/csghub-server/common/tests" | ||
) | ||
|
||
func TestMemberStore_CRUD(t *testing.T) { | ||
db := tests.InitTestDB() | ||
defer db.Close() | ||
ctx := context.TODO() | ||
|
||
store := database.NewMemberStoreWithDB(db) | ||
|
||
err := store.Add(ctx, 123, 456, "foo") | ||
require.Nil(t, err) | ||
mem := &database.Member{} | ||
err = db.Core.NewSelect().Model(mem).Where("user_id=?", 456).Scan(ctx) | ||
require.Nil(t, err) | ||
require.Equal(t, "foo", mem.Role) | ||
|
||
mem, err = store.Find(ctx, 123, 456) | ||
require.Nil(t, err) | ||
require.Equal(t, "foo", mem.Role) | ||
|
||
ms, err := store.UserMembers(ctx, 456) | ||
require.Nil(t, err) | ||
require.Equal(t, 1, len(ms)) | ||
require.Equal(t, "foo", ms[0].Role) | ||
|
||
ms, count, err := store.OrganizationMembers(ctx, 123, 10, 1) | ||
require.Nil(t, err) | ||
require.Equal(t, 1, len(ms)) | ||
require.Equal(t, 1, count) | ||
require.Equal(t, "foo", ms[0].Role) | ||
|
||
err = store.Delete(ctx, 123, 456, "foo") | ||
require.Nil(t, err) | ||
_, err = store.Find(ctx, 123, 456) | ||
require.NotNil(t, err) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.