You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: organization_store_test.go
    path of file: ./repos/pipeline/src/auth/authadapter
    
    the code of the file until where you have to start completion: // Copyright Â© 2019 Banzai Cloud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package authadapter

import (
	"context"
	"errors"
	"io/ioutil"
	"regexp"
	"testing"

	"github.com/jinzhu/gorm"

	//  SQLite driver used for integration test
	_ "github.com/jinzhu/gorm/dialects/sqlite"
	"github.com/sirupsen/logrus"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"

	"github.com/banzaicloud/pipeline/src/auth"
)

func setUpDatabase(t *testing.T) *gorm.DB {
	db, err := gorm.Open("sqlite3", "file::memory:")
	require.NoError(t, err)

	logger := logrus.New()
	logger.SetOutput(ioutil.Discard)

	err = auth.Migrate(db, logger)
	require.NoError(t, err)

	return db
}

func TestGormOrganizationStore_EnsureOrganizationExists(t *testing.T) {
	// This causes `concurrent map write` issues during tests
	// t.Parallel()

	t.Run("create", func(t *testing.T) {
		db := setUpDatabase(t)
		store := NewGormOrganizationStore(db)

		created, id, err := store.EnsureOrganizationExists(context.Background(), "example", "github")
		require.NoError(t, err)

		var organization auth.Organization

		err = db.
			Where(auth.Organization{Name: "example"}).
			First(&organization).
			Error
		require.NoError(t, err)

		assert.True(t, created)
		assert.Equal(t, organization.ID, id)

    
func TestGormOrganizationStore_ApplyUserMembership(t *testing.T) {
	// This causes `concurrent map write` issues during tests
	// t.Parallel()

	t.Run("existing", func(t *testing.T) {
		db := setUpDatabase(t)
		store := NewGormOrganizationStore(db)

		user := auth.User{
			Name:  "John Doe",
			Email: "john.doe@example.com",
			Login: "john.doe",
			Organizations: []auth.Organization{
				{
					Name:     "example",
					Provider: "github",
				},
			},
		}

		err := db.Save(&user).Error
		require.NoError(t, err)

		err = store.ApplyUserMembership(context.Background(), user.Organizations[0].ID, user.ID, auth.RoleAdmin)
		require.NoError(t, err)

		var userOrganization auth.UserOrganization

		err = db.
			Where(auth.UserOrganization{UserID: user.ID, OrganizationID: user.Organizations[0].ID}).
			First(&userOrganization).
			Error
		require.NoError(t, err)

		assert.Equal(t, userOrganization.Role, auth.RoleAdmin, "user is expected to be an admin")
	})

	t.Run("existing_no_change", func(t *testing.T) {
		db := setUpDatabase(t)
		store := NewGormOrganizationStore(db)

		user := auth.User{
			Name:  "John Doe",
			Email: "john.doe@example.com",
			Login: "john.doe",
			Organizations: []auth.Organization{
				{
					Name:     "example",
					Provider: "github",
				},
			},
		}

		err := db.Save(&user).Error
		require.NoError(t, err)

		err = store.ApplyUserMembership(context.Background(), user.Organizations[0].ID, user.ID, auth.RoleMember)
		require.NoError(t, err)

		var userOrganization auth.UserOrganization

		err = db.
			Where(auth.UserOrganization{UserID: user.ID, OrganizationID: user.Organizations[0].ID}).
			First(&userOrganization).
			Error
		require.NoError(t, err)

		assert.Equal(t, userOrganization.Role, auth.RoleMember, "user is expected to be a member")
	})

	t.Run("new", func(t *testing.T) {
		db := setUpDatabase(t)
		store := NewGormOrganizationStore(db)

		user := auth.User{
			Name:  "John Doe",
			Email: "john.doe@example.com",
			Login: "john.doe",
		}

		organization := auth.Organization{
			Name:     "example",
			Provider: "github",
		}

		err := db.Save(&user).Error
		require.NoError(t, err)

		err = db.Save(&organization).Error
		require.NoError(t, err)

		err = store.ApplyUserMembership(context.Background(), organization.ID, user.ID, auth.RoleAdmin)
		require.NoError(t, err)

		var userOrganization auth.UserOrganization

		err = db.
			Where(auth.UserOrganization{UserID: user.ID, OrganizationID: organization.ID}).
			First(&userOrganization).
			Error
		require.NoError(t, err)

		assert.Equal(t, userOrganization.Role, auth.RoleAdmin, "user is expected to be an admin")
	})
}