database

package
v0.0.0-...-cf79e49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package database handles connection to the database

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterModel

type ClusterModel struct {
	Name  string `db:"cluster_name"`
	Color int    `db:"color"`
}

ClusterModel represents how a cluster comes back from the database

type DBConnection

type DBConnection interface {
	GetCluster(clusterName string) (*ClusterModel, error)
	UpdateCluster(cluster *ClusterModel) error
	GetAllClusters() ([]ClusterModel, error)
	CreateCluster(cluster *ClusterModel) error
	DeleteCluster(cluster *ClusterModel) error
}

DBConnection represents a connection to a database

type MockDBConnection

type MockDBConnection struct {
	GetClusterReturnValue *ClusterModel

	GetAllClustersReturnValue []ClusterModel

	GetClusterReturnErr     bool
	UpdateClusterReturnErr  bool
	GetAllClustersReturnErr bool
	CreateClusterReturnErr  bool
	DeleteClusterReturnErr  bool
}

MockDBConnection used for mocking a DBConnection in tests

func (MockDBConnection) CreateCluster

func (m MockDBConnection) CreateCluster(cluster *ClusterModel) error

CreateCluster mocks out creating cluster. Will return an error if CreateClusterReturnErr is true.

func (MockDBConnection) DeleteCluster

func (m MockDBConnection) DeleteCluster(cluster *ClusterModel) error

DeleteCluster mocks out deleting cluster. Will return an error if DeleteClusterReturnErr is true.

func (MockDBConnection) GetAllClusters

func (m MockDBConnection) GetAllClusters() ([]ClusterModel, error)

GetAllClusters mocks out geting all clusters. Will return an error if GetAllClustersReturnErr is true.

func (MockDBConnection) GetCluster

func (m MockDBConnection) GetCluster(clusterName string) (*ClusterModel, error)

GetCluster mocks out geting a cluster. Will return an error if GetClusterReturnErr is true.

func (MockDBConnection) UpdateCluster

func (m MockDBConnection) UpdateCluster(cluster *ClusterModel) error

UpdateCluster mocks out dpdating cluster. Will return an error if UpdateClusterReturnErr is true.

type MockInfo

type MockInfo struct {
	mock.Mock
}

MockInfo is a mock struct which implements connection.Info

type PGSQLConnection

type PGSQLConnection struct {
	// contains filtered or unexported fields
}

PGSQLConnection represents a wrapper around a PostgreSQL connection

func CreateMockSQL

func CreateMockSQL(t *testing.T) (con *PGSQLConnection, mock sqlmock.Sqlmock)

CreateMockSQL creates a Test SQLConnection. Must Close con when done

func NewConnection

func NewConnection() (*PGSQLConnection, error)

NewConnection creates a new PGSQLConnection by using the URL found in the DATABASE_URL environment variable

func (PGSQLConnection) CreateCluster

func (p PGSQLConnection) CreateCluster(cluster *ClusterModel) error

CreateCluster inserts a new cluster into the database

func (PGSQLConnection) DeleteCluster

func (p PGSQLConnection) DeleteCluster(cluster *ClusterModel) error

DeleteCluster deletes the cluster from the database

func (PGSQLConnection) GetAllClusters

func (p PGSQLConnection) GetAllClusters() ([]ClusterModel, error)

GetAllClusters retrieves all clusters in database

func (PGSQLConnection) GetCluster

func (p PGSQLConnection) GetCluster(clusterName string) (*ClusterModel, error)

GetCluster retrieves the cluster associated with clusterName

func (PGSQLConnection) UpdateCluster

func (p PGSQLConnection) UpdateCluster(cluster *ClusterModel) error

UpdateCluster updates a clusters color in the database

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL