Skip to content

Commit

Permalink
fix: agent integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
exu committed Jul 31, 2024
1 parent a2229f6 commit 8ea65e1
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions pkg/repository/config/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
cfg, _ = config.Get()
)

func getRepository() (*MongoRepository, error) {
func getRepository(mongoDbName string) (*MongoRepository, error) {
db, err := storage.GetMongoDatabase(cfg.APIMongoDSN, mongoDbName, storage.TypeMongoDB, false, nil)
repository := NewMongoRepository(db)
return repository, err
Expand All @@ -34,13 +34,15 @@ func TestStorage_Integration(t *testing.T) {

assert := require.New(t)

repository, err := getRepository()
assert.NoError(err)
t.Run("GetUniqueClusterId should return same id for each call", func(t *testing.T) {
repository, err := getRepository("testkube_storage_integration_test_get_uniqiu_cluster_id")
assert.NoError(err)

err = repository.Coll.Drop(context.TODO())
assert.NoError(err)
t.Cleanup(func() {
err = repository.Coll.Drop(context.TODO())
assert.NoError(err)
})

t.Run("GetUniqueClusterId should return same id for each call", func(t *testing.T) {
t.Parallel()
// given/when
id1, err := repository.GetUniqueClusterId(context.Background())
Expand All @@ -60,9 +62,18 @@ func TestStorage_Integration(t *testing.T) {

t.Run("Upsert should insert new config entry", func(t *testing.T) {
t.Parallel()

repository, err := getRepository("testkube_storage_integration_test_insert_new_config")
assert.NoError(err)

t.Cleanup(func() {
err = repository.Coll.Drop(context.TODO())
assert.NoError(err)
})

// given,
clusterId := "uniq3"
_, err := repository.Upsert(context.Background(), testkube.Config{
_, err = repository.Upsert(context.Background(), testkube.Config{
ClusterId: clusterId,
})
assert.NoError(err)
Expand Down

0 comments on commit 8ea65e1

Please sign in to comment.