Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove underscore from package name and add interface for state operations #7

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Vendoring support
vendor

# binaries
ecs_state

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof
2 changes: 1 addition & 1 deletion cluster.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ecs_state
package ecsstate

// Local representation of an ECS cluster and stored by gorm
type Cluster struct {
Expand Down
2 changes: 1 addition & 1 deletion container_instance.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ecs_state
package ecsstate

// Local representation of an ECS ContainerInstance and stored by gorm.
// Notably, resources and other sub-objects have been placed into their own
Expand Down
8 changes: 4 additions & 4 deletions ecs_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// placing tasks within the ECS cluster to replicate the cluster state into a local working copy and synchronize on occassion.
//
// Author: William Thurston
package ecs_state
package ecsstate

import (
"bytes"
Expand All @@ -23,15 +23,15 @@ import (
// The State object provides methods to synchronize and query the state of the ECS cluster.
type State struct {
clusterName string
db gorm.DB
db *gorm.DB
ecs_client *ecs.ECS
log Logger
}

// Create a new State object. The clusterName is the cluster to track, ecs_client should be provided by the caller
// with proper credentials preferably scoped to read only access to ECS APIs, and the logger can use ecs_state.DefaultLogger
// for output on stdout, or the user can provide a custom logger instead.
func Initialize(clusterName string, ecs_client *ecs.ECS, logger Logger) *State {
func Initialize(clusterName string, ecs_client *ecs.ECS, logger Logger) StateOps {
logger.Info("Intializing ecs_state for cluster ", clusterName)

db, err := gorm.Open("sqlite3", ":memory:")
Expand All @@ -49,7 +49,7 @@ func Initialize(clusterName string, ecs_client *ecs.ECS, logger Logger) *State {

// Provides direct access to the database through gorm to allow more advanced queries against state.
func (state *State) DB() *gorm.DB {
return &state.db
return state.db
}

// Will parse and log any AWS errors received while contacting ECS.
Expand Down
31 changes: 31 additions & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package: github.com/jhspaybar/ecs_state
import:
- package: github.com/aws/aws-sdk-go
subpackages:
- aws
- aws/awserr
- service/ecs
- package: github.com/jinzhu/gorm
- package: github.com/mattn/go-sqlite3
2 changes: 1 addition & 1 deletion logger.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ecs_state
package ecsstate

import (
"log"
Expand Down
71 changes: 71 additions & 0 deletions mocks/StateOps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package mocks

import "github.com/jhspaybar/ecsstate"
import "github.com/stretchr/testify/mock"

import "github.com/jinzhu/gorm"

type StateOps struct {
mock.Mock
}

// FindLocationsForTaskDefinition provides a mock function with given fields: td
func (_m *StateOps) FindLocationsForTaskDefinition(td string) *[]ecsstate.ContainerInstance {
ret := _m.Called(td)

var r0 *[]ecsstate.ContainerInstance
if rf, ok := ret.Get(0).(func(string) *[]ecsstate.ContainerInstance); ok {
r0 = rf(td)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*[]ecsstate.ContainerInstance)
}
}

return r0
}

// FindTaskDefinition provides a mock function with given fields: td
func (_m *StateOps) FindTaskDefinition(td string) ecsstate.TaskDefinition {
ret := _m.Called(td)

var r0 ecsstate.TaskDefinition
if rf, ok := ret.Get(0).(func(string) ecsstate.TaskDefinition); ok {
r0 = rf(td)
} else {
r0 = ret.Get(0).(ecsstate.TaskDefinition)
}

return r0
}

// RefreshClusterState provides a mock function with given fields:
func (_m *StateOps) RefreshClusterState() {
_m.Called()
}

// RefreshContainerInstanceState provides a mock function with given fields:
func (_m *StateOps) RefreshContainerInstanceState() {
_m.Called()
}

// RefreshTaskState provides a mock function with given fields:
func (_m *StateOps) RefreshTaskState() {
_m.Called()
}

// DB provides a mock function with given fields:
func (_m *StateOps) DB() *gorm.DB {
ret := _m.Called()

var r0 *gorm.DB
if rf, ok := ret.Get(0).(func() *gorm.DB); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*gorm.DB)
}
}

return r0
}
16 changes: 16 additions & 0 deletions state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ecsstate

import (
"github.com/jinzhu/gorm"
)

// StateOps is the interface for refreshing and interacting with the local
// ECS state.
type StateOps interface {
FindLocationsForTaskDefinition(td string) *[]ContainerInstance
FindTaskDefinition(td string) TaskDefinition
RefreshClusterState()
RefreshContainerInstanceState()
RefreshTaskState()
DB() *gorm.DB
}
2 changes: 1 addition & 1 deletion task.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ecs_state
package ecsstate

// Local representation of an ECS Task and stored by gorm. A number of fields are absent
// for now as they are not needed to track and update the state of the state of the cluster typically.
Expand Down
2 changes: 1 addition & 1 deletion task_definition.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ecs_state
package ecsstate

// Local representation of an ECS TaskDefinition and stored by gorm. Resources are extracted,
// but the complete definition is ignored.
Expand Down