Skip to content

Commit

Permalink
added circleci config and some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sami Alajrami committed Nov 15, 2017
1 parent f2948bf commit 56245d8
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 14 deletions.
27 changes: 27 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.8

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4

#### TEMPLATE_NOTE: go expects specific checkout path representing url
#### expecting it in the form of
#### /go/src/github.com/circleci/go-tool
#### /go/src/bitbucket.org/circleci/go-tool
working_directory: /go/src/github.com/praqma/helmsman
steps:
- checkout

# specify any bash command here prefixed with `run: `
- run: go get github.com/BurntSushi/toml
- run: go get github.com/goreleaser/goreleaser
- run: go test
110 changes: 110 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package main

import (
"strings"
"testing"
)

// func Test_command_printDescription(t *testing.T) {
// type fields struct {
// Cmd string
// Args []string
// Description string
// }
// tests := []struct {
// name string
// fields fields
// }{
// // TODO: Add test cases.
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// c := command{
// Cmd: tt.fields.Cmd,
// Args: tt.fields.Args,
// Description: tt.fields.Description,
// }
// c.printDescription()
// })
// }
// }

// func Test_command_printFullCommand(t *testing.T) {
// type fields struct {
// Cmd string
// Args []string
// Description string
// }
// tests := []struct {
// name string
// fields fields
// }{
// // TODO: Add test cases.
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// c := command{
// Cmd: tt.fields.Cmd,
// Args: tt.fields.Args,
// Description: tt.fields.Description,
// }
// c.printFullCommand()
// })
// }
// }

func Test_command_exec(t *testing.T) {
type fields struct {
Cmd string
Args []string
Description string
}
type args struct {
debug bool
}
tests := []struct {
name string
fields fields
args args
want int
want1 string
}{
{
name: "echo",
fields: fields{
Cmd: "bash",
Args: []string{"-c", "echo this is fun"},
Description: "A bash command execution test with echo.",
},
args: args{debug: false},
want: 0,
want1: "this is fun",
}, {
name: "exitCode",
fields: fields{
Cmd: "bash",
Args: []string{"-c", "echo $?"},
Description: "A bash command execution test with exitCode.",
},
args: args{debug: false},
want: 0,
want1: "0",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := command{
Cmd: tt.fields.Cmd,
Args: tt.fields.Args,
Description: tt.fields.Description,
}
got, got1 := c.exec(tt.args.debug)
if got != tt.want {
t.Errorf("command.exec() got = %v, want %v", got, tt.want)
}
if strings.TrimSpace(got1) != tt.want1 {
t.Errorf("command.exec() got1 = %v, want %v", got1, tt.want1)
}
})
}
}
24 changes: 12 additions & 12 deletions example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ maintainer = "k8s-admin"
# paths to the certificate for connecting to the cluster
# You can skip this if you use Helmsman on a machine with kubectl already connected to your k8s cluster.
[certifications]
caCrt = "ca.crt" # s3 bucket path
caKey = "ca.key" # Or, a path to the file location
# caCrt = "ca.crt" # s3 bucket path
# caKey = "ca.key" # Or, a path to the file location

[settings]
kubeContext = "minikube" # will try connect to this context first, if it does not exist, it will be created using the details below
Expand Down Expand Up @@ -46,13 +46,13 @@ incubator = "http://storage.googleapis.com/kubernetes-charts-incubator"
test = true # run the tests whenever this release is installed/upgraded/rolledback


[apps.vault]
name = "vault" # should be unique across all apps
description = "vault"
env = "staging" # maps to the namespace as defined in environmetns above
enabled = true # change to false if you want to delete this app release [empty = flase]
chart = "incubator/vault" # don't change the chart name, create a new release instead
version = "0.1.0"
valuesFile = "" # leaving it empty uses the default chart values
purge = false # will only be considered when there is a delete operation
test = true # run the tests whenever this release is installed/upgraded/rolledback
# [apps.vault]
# name = "vault" # should be unique across all apps
# description = "vault"
# env = "staging" # maps to the namespace as defined in environmetns above
# enabled = true # change to false if you want to delete this app release [empty = flase]
# chart = "incubator/vault" # don't change the chart name, create a new release instead
# version = "0.1.0"
# valuesFile = "" # leaving it empty uses the default chart values
# purge = false # will only be considered when there is a delete operation
# test = true # run the tests whenever this release is installed/upgraded/rolledback
2 changes: 1 addition & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// It checks if Helm and Kubectl exist and configures: the connection to the k8s cluster, helm repos, namespaces, etc.
func init() {
//parsing command line flags
flag.StringVar(&file, "f", "", "desired state file name")
flag.StringVar(&file, "f", "example.toml", "desired state file name")
flag.BoolVar(&apply, "apply", false, "apply the plan directly")
flag.BoolVar(&debug, "debug", false, "show the execution logs")
flag.BoolVar(&help, "help", false, "show Helmsman help")
Expand Down
4 changes: 3 additions & 1 deletion plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func (p plan) execPlan() {
p.printPlan()
for _, cmd := range p.Commands {
log.Println("INFO: attempting: -- ", cmd.Description)
cmd.exec(debug)
if exitCode, _ := cmd.exec(debug); exitCode != 0 {
log.Fatal("Command returned the following non zero exit code while executing the plan: " + string(exitCode))
}
}
}

Expand Down
Loading

0 comments on commit 56245d8

Please sign in to comment.