Skip to content

Commit

Permalink
test: add loader_test
Browse files Browse the repository at this point in the history
  • Loading branch information
SharkEzz committed Jul 9, 2022
1 parent d8043fb commit d088fe3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
18 changes: 6 additions & 12 deletions pkg/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type Executor struct {
func NewExecutor(dpl *deployment.Deployment, cfg *Config, logChannel chan string) (*Executor, error) {
if cfg == nil {
cfg = &Config{
JobTimeout: 3600,
DeploymentTimeout: 86400,
JobTimeout: 3600, // 1 hour
DeploymentTimeout: 86400, // 1 day
AllowFailure: false,
}
}
Expand All @@ -43,7 +43,6 @@ func NewExecutor(dpl *deployment.Deployment, cfg *Config, logChannel chan string
}

filePath := fmt.Sprintf("logs/deployments/%s.log", randId.String())

file, err := os.OpenFile(filePath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0660)
if err != nil {
return nil, err
Expand Down Expand Up @@ -85,7 +84,7 @@ func (e *Executor) ExecuteJobs() error {

for _, job := range e.Deployment.Jobs {
select {
// Prevent the deployment gorouting from running other jobs if deployment is cancelled
// Prevent the deployment goroutine from running other jobs if deployment is cancelled
case <-deploymentContext.Done():
return
default:
Expand All @@ -98,15 +97,10 @@ func (e *Executor) ExecuteJobs() error {
if host == "localhost" {
client = remote.ConnectToLocalhost()
} else {
hostStr, ok := host.(string)
if !ok {
errorChannel <- fmt.Errorf("error: host '%s' is not a string", host)
continue
}
c, ok := clients[hostStr]
c, ok := clients[host.(string)]
if !ok {
errorChannel <- fmt.Errorf("error: host '%s' does not exist", hostStr)
continue
errorChannel <- fmt.Errorf("error: host %#v does not exist", host)
return
}
client = c
}
Expand Down
31 changes: 31 additions & 0 deletions pkg/loader/loader_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package loader_test

import (
"testing"

loaders "github.com/SharkEzz/provisiond/internal/loader"
"github.com/SharkEzz/provisiond/pkg/loader"
)

func TestLoader(t *testing.T) {
ld := loader.GetLoader(`name: Test
jobs:
- name: Test1
hosts: [localhost]
shell: echo oui > test.txt`)

if _, ok := ld.(loaders.StringLoader); !ok {
t.Errorf("expected StringLoader")
}

ld = loader.GetLoader("name: Test\n")

if _, ok := ld.(loaders.StringLoader); !ok {
t.Errorf("expected StringLoader")
}

ld = loader.GetLoader("./test.yaml")
if _, ok := ld.(loaders.FileLoader); !ok {
t.Errorf("expected FileLoader")
}
}

0 comments on commit d088fe3

Please sign in to comment.