Documentation ¶
Overview ¶
Package database handles connection to the database
Index ¶
- type ClusterModel
- type DBConnection
- type MockDBConnection
- func (m MockDBConnection) CreateCluster(cluster *ClusterModel) error
- func (m MockDBConnection) DeleteCluster(cluster *ClusterModel) error
- func (m MockDBConnection) GetAllClusters() ([]ClusterModel, error)
- func (m MockDBConnection) GetCluster(clusterName string) (*ClusterModel, error)
- func (m MockDBConnection) UpdateCluster(cluster *ClusterModel) error
- type MockInfo
- type PGSQLConnection
- func (p PGSQLConnection) CreateCluster(cluster *ClusterModel) error
- func (p PGSQLConnection) DeleteCluster(cluster *ClusterModel) error
- func (p PGSQLConnection) GetAllClusters() ([]ClusterModel, error)
- func (p PGSQLConnection) GetCluster(clusterName string) (*ClusterModel, error)
- func (p PGSQLConnection) UpdateCluster(cluster *ClusterModel) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClusterModel ¶
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 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