Skip to content

Commit

Permalink
userdata: add an interface
Browse files Browse the repository at this point in the history
Makes testing much easier.
  • Loading branch information
vaijab committed Jun 7, 2017
1 parent d891f98 commit 0cd9d93
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 18 additions & 10 deletions pkg/userdata/userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ import (
"github.com/UKHomeOffice/keto/pkg/constants"
)

// UserData defines a user data struct
type UserData struct {
// UserDater is an abstract interface for UserData, mainly for testing.
type UserDater interface {
RenderMasterCloudConfig(string, string, string, map[string]string) ([]byte, error)
RenderComputeCloudConfig(string, string, string) ([]byte, error)
}

// UserData defines a user data struct.
type UserData struct{}

// Compile-time check whether UserData type value implements UserDater interface.
var _ UserDater = (*UserData)(nil)

// New returns a new UserData struct
func New() *UserData {
return &UserData{}
Expand Down Expand Up @@ -452,15 +460,15 @@ write_files:
`

data := struct {
ClusterName string
KubeVersion string
CloudProviderName string
KetoK8Image string
ClusterName string
KubeVersion string
CloudProviderName string
KetoK8Image string
}{
ClusterName: clusterName,
KubeVersion: kubeVersion,
CloudProviderName: cloudProviderName,
KetoK8Image: constants.DefaultKetoK8Image,
ClusterName: clusterName,
KubeVersion: kubeVersion,
CloudProviderName: cloudProviderName,
KetoK8Image: constants.DefaultKetoK8Image,
}

t := template.Must(template.New("compute-cloud-config").Parse(computeTemplate))
Expand Down
2 changes: 2 additions & 0 deletions pkg/userdata/userdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//go:generate mockery -dir $GOPATH/src/github.com/UKHomeOffice/keto/pkg/userdata -name=UserDater

package userdata

import (
Expand Down

0 comments on commit 0cd9d93

Please sign in to comment.