-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some unit tests, mainly about configuration
- Loading branch information
Showing
8 changed files
with
388 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,4 +144,4 @@ projects: | |
|
||
- name: forward-composieux-website | ||
forward: | ||
- *composieux-fr | ||
- *composieux-fr-local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLoadSingleFile(t *testing.T) { | ||
// Given | ||
dir, _ := os.Getwd() | ||
Filepath = dir + "/../tests/config/config.yaml" | ||
MultipleFilepath = dir + "/../tests/config/config.unknown.*.yaml" | ||
|
||
// When | ||
conf, err := Load() | ||
|
||
// Then | ||
assert.IsType(t, new(Config), conf) | ||
assert.Nil(t, err) | ||
|
||
assert.Len(t, conf.Projects, 4) | ||
assert.Equal(t, conf.Watcher.Exclude, []string{ | ||
".git", | ||
"node_modules", | ||
}) | ||
} | ||
|
||
func TestLoadMultipleFiles(t *testing.T) { | ||
// Given | ||
dir, _ := os.Getwd() | ||
Filepath = dir + "/../tests/config/unknown.yaml" | ||
MultipleFilepath = dir + "/../tests/config/config.multiple.*.yaml" | ||
|
||
// Remove single config created file after test | ||
defer os.Remove(Filepath) | ||
|
||
// When | ||
conf, err := Load() | ||
|
||
// Then | ||
assert.IsType(t, new(Config), conf) | ||
assert.Nil(t, err) | ||
|
||
assert.Len(t, conf.Projects, 4) | ||
assert.Equal(t, conf.Watcher.Exclude, []string{ | ||
".git", | ||
"node_modules", | ||
"/event/an/absolute/path/in/multiple/files", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Kubernetes forwards | ||
|
||
<: &kubernetes-context preprod | ||
|
||
<: &graphql-forward | ||
name: graphql | ||
type: kubernetes | ||
values: | ||
context: *kubernetes-context | ||
namespace: backend | ||
labels: | ||
app: graphql | ||
hostname: graphql.svc.local | ||
ports: | ||
- 8080:8000 | ||
|
||
<: &grpc-api-kubernetes-remote | ||
name: grpc-api | ||
type: kubernetes-remote | ||
values: | ||
context: *kubernetes-context | ||
namespace: backend | ||
labels: | ||
app: grpc-api | ||
ports: | ||
- 8080:8080 | ||
- 8001:8001 | ||
|
||
<: &grpc-api-forward | ||
name: grpc-api | ||
type: kubernetes | ||
values: | ||
context: *kubernetes-context | ||
namespace: backend | ||
labels: | ||
app: grpc-api | ||
hostname: grpc-api.svc.local | ||
ports: | ||
- 8080:8080 | ||
|
||
<: &composieux-fr-local | ||
name: composieux-fr-local | ||
type: ssh | ||
values: | ||
remote: vincent@composieux.fr | ||
args: | ||
- "-i/Users/name/.ssh/private_key" | ||
hostname: composieux.fr.svc.local | ||
ports: | ||
- 8080:80 | ||
|
||
<: &composieux-fr-remote | ||
name: composieux-fr-remote | ||
type: ssh-remote | ||
values: | ||
remote: vincent@composieux.fr | ||
args: | ||
- "-i/Users/name/.ssh/private_key" | ||
ports: | ||
- 8080:80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Local applications | ||
|
||
<: &graphql-local | ||
name: graphql | ||
path: github.com/eko/graphql | ||
watch: true | ||
hostname: graphql.svc.local | ||
executable: go | ||
args: | ||
- run | ||
- cmd/main.go | ||
env: | ||
HTTP_PORT: 8005 | ||
setup: | ||
- go get github.com/eko/graphql | ||
- echo You can use ~/path syntax and environment variables like $GOPATH in your commands | ||
|
||
<: &grpc-api-local | ||
name: grpc-api | ||
path: github.com/eko/grpc-api | ||
watch: true | ||
hostname: grpc-api.svc.local | ||
executable: go | ||
args: | ||
- run | ||
- main.go | ||
env: | ||
GRPC_PORT: 8006 | ||
setup: | ||
- go get github.com/eko/grpc-api | ||
- echo You can use ~/path syntax and environment variables like $GOPATH in your commands | ||
|
||
<: &elasticsearch-local | ||
name: elasticsearch | ||
path: /Users/vincent/dev/docker | ||
watch: true | ||
executable: docker | ||
args: | ||
- start | ||
- -i | ||
- elastic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Settings | ||
|
||
gopath: /dev/golang | ||
|
||
watcher: # Optional | ||
exclude: | ||
- .git | ||
- node_modules | ||
- /event/an/absolute/path/in/multiple/files | ||
|
||
# Projects | ||
|
||
projects: | ||
- name: full | ||
local: | ||
- *graphql-local | ||
- *grpc-api-local | ||
- *elasticsearch-local | ||
|
||
- name: graphql | ||
local: | ||
- *graphql-local | ||
forward: | ||
- *grpc-api-forward | ||
|
||
- name: forward-only | ||
forward: | ||
- *graphql-forward | ||
- *grpc-api-forward | ||
|
||
- name: forward-composieux-website | ||
forward: | ||
- *composieux-fr-local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Settings | ||
|
||
watcher: | ||
exclude: | ||
- .git | ||
- node_modules | ||
|
||
# Kubernetes forwards | ||
|
||
<: &kubernetes-context preprod | ||
|
||
<: &graphql-forward | ||
name: graphql | ||
type: kubernetes | ||
values: | ||
context: *kubernetes-context | ||
namespace: backend | ||
labels: | ||
app: graphql | ||
hostname: graphql.svc.local # Optional | ||
ports: | ||
- 8080:8000 | ||
|
||
<: &grpc-api-kubernetes-remote | ||
name: grpc-api | ||
type: kubernetes-remote | ||
values: | ||
context: *kubernetes-context | ||
namespace: backend | ||
labels: | ||
app: grpc-api | ||
ports: | ||
- 8080:8080 | ||
- 8001:8001 | ||
|
||
<: &grpc-api-forward | ||
name: grpc-api | ||
type: kubernetes | ||
values: | ||
context: *kubernetes-context | ||
namespace: backend | ||
labels: | ||
app: grpc-api | ||
hostname: grpc-api.svc.local | ||
ports: | ||
- 8080:8080 | ||
|
||
<: &composieux-fr-local | ||
name: composieux-fr-local | ||
type: ssh | ||
values: | ||
remote: vincent@composieux.fr | ||
args: | ||
- "-i/Users/name/.ssh/private_key" | ||
hostname: composieux.fr.svc.local | ||
ports: | ||
- 8080:80 | ||
|
||
<: &composieux-fr-remote | ||
name: composieux-fr-remote | ||
type: ssh-remote | ||
values: | ||
remote: vincent@composieux.fr | ||
args: | ||
- "-i/Users/name/.ssh/private_key" | ||
ports: | ||
- 8080:80 | ||
|
||
# Local applications | ||
|
||
<: &graphql-local | ||
name: graphql | ||
path: github.com/eko/graphql | ||
watch: true | ||
hostname: graphql.svc.local | ||
executable: go | ||
args: | ||
- run | ||
- cmd/main.go | ||
env: | ||
HTTP_PORT: 8005 | ||
setup: | ||
- go get github.com/eko/graphql | ||
- echo You can use ~/path syntax and environment variables like $GOPATH in your commands | ||
|
||
<: &grpc-api-local | ||
name: grpc-api | ||
path: github.com/eko/grpc-api | ||
watch: true | ||
hostname: grpc-api.svc.local | ||
executable: go | ||
args: | ||
- run | ||
- main.go | ||
env: | ||
GRPC_PORT: 8006 | ||
setup: | ||
- go get github.com/eko/grpc-api | ||
- echo You can use ~/path syntax and environment variables like $GOPATH in your commands | ||
|
||
<: &elasticsearch-local | ||
name: elasticsearch | ||
path: /Users/vincent/dev/docker | ||
watch: true | ||
executable: docker | ||
args: | ||
- start | ||
- -i | ||
- elastic | ||
|
||
# Projects | ||
|
||
projects: | ||
- name: full | ||
local: | ||
- *graphql-local | ||
- *grpc-api-local | ||
- *elasticsearch-local | ||
|
||
- name: graphql | ||
local: | ||
- *graphql-local | ||
forward: | ||
- *grpc-api-forward | ||
|
||
- name: forward-only | ||
forward: | ||
- *graphql-forward | ||
- *grpc-api-forward | ||
|
||
- name: forward-composieux-website | ||
forward: | ||
- *composieux-fr-local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/eko/monday/internal/config" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewForwarder(t *testing.T) { | ||
// Given | ||
name := "test-forward" | ||
context := "aws-int1" | ||
namespace := "platform" | ||
ports := []string{"8080:8080"} | ||
labels := map[string]string{ | ||
"app": "my-test-app", | ||
} | ||
|
||
// When | ||
forwarder, err := NewForwarder(config.ForwarderKubernetes, name, context, namespace, ports, labels) | ||
|
||
// Then | ||
assert.IsType(t, new(Forwarder), forwarder) | ||
assert.Nil(t, err) | ||
|
||
assert.Equal(t, config.ForwarderKubernetes, forwarder.forwardType) | ||
assert.Equal(t, name, forwarder.name) | ||
assert.Equal(t, context, forwarder.context) | ||
assert.Equal(t, namespace, forwarder.namespace) | ||
assert.Equal(t, ports, forwarder.ports) | ||
|
||
assert.Len(t, forwarder.portForwarders, 0) | ||
assert.Len(t, forwarder.deployments, 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package ssh | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/eko/monday/internal/config" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewForwarder(t *testing.T) { | ||
// Given | ||
remote := "root@acme.tld" | ||
localPort := "8080" | ||
forwardPort := "8081" | ||
args := []string{"-i /tmp/my/private.key"} | ||
|
||
// forwardType, remote, localPort, forwardPort string, args []string | ||
|
||
// When | ||
forwarder, err := NewForwarder(config.ForwarderSSH, remote, localPort, forwardPort, args) | ||
|
||
// Then | ||
assert.IsType(t, new(Forwarder), forwarder) | ||
assert.Nil(t, err) | ||
|
||
assert.Equal(t, config.ForwarderSSH, forwarder.forwardType) | ||
assert.Equal(t, remote, forwarder.remote) | ||
assert.Equal(t, localPort, forwarder.localPort) | ||
assert.Equal(t, forwardPort, forwarder.forwardPort) | ||
assert.Equal(t, args, forwarder.args) | ||
|
||
assert.Nil(t, forwarder.cmd) | ||
} |