get.porter.sh/porter@v1.3.0/pkg/storage/plugins/mongodb/mongodb_test.go (about)

     1  package mongodb
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"get.porter.sh/porter/pkg/portercontext"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestParseDatabase(t *testing.T) {
    12  	ctx := context.Background()
    13  
    14  	tc := portercontext.NewTestContext(t)
    15  	t.Run("db specified", func(t *testing.T) {
    16  		mongo := NewStore(tc.Context, PluginConfig{URL: "mongodb://localhost:27017/test/"})
    17  		if err := mongo.Connect(ctx); err != nil {
    18  			t.Fatal(err)
    19  		}
    20  		defer mongo.Close()
    21  		assert.Equal(t, "test", mongo.database)
    22  	})
    23  
    24  	t.Run("default db", func(t *testing.T) {
    25  		mongo := NewStore(tc.Context, PluginConfig{URL: "mongodb://localhost:27017"})
    26  		if err := mongo.Connect(ctx); err != nil {
    27  			t.Fatal(err)
    28  		}
    29  		defer mongo.Close()
    30  		assert.Equal(t, "porter", mongo.database)
    31  	})
    32  }