Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
updated unit test
  • Loading branch information
adranwit committed Apr 17, 2018
1 parent 88296eb commit e01054b
Show file tree
Hide file tree
Showing 32 changed files with 85 additions and 110 deletions.
5 changes: 0 additions & 5 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ type Manager interface {
Run(context *Context, request interface{}) (interface{}, error)
}



//Service represents an endly service
type Service interface {
//service id
Expand All @@ -54,9 +52,6 @@ type Service interface {
Actions() []string
}




//Validator represents generic validator
type Validator interface {
Validate() error
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func normalizeArgument(value string) interface{} {
value = strings.Trim(value, " \"'")
if strings.HasPrefix(value, "#") || strings.HasPrefix(value, "@") {
resource := url.NewResource(string(value[1:]))
var dataStructure= map[string]interface{}{}
var dataStructure = map[string]interface{}{}
if err := resource.Decode(&dataStructure); err == nil {
return dataStructure
}
Expand Down
2 changes: 1 addition & 1 deletion gen/static/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func init() {
var memStorage = storage.NewMemoryService();
var memStorage = storage.NewMemoryService()
{
err := memStorage.Upload("mem://github.com/viant/endly/asset/index.html", bytes.NewReader([]byte(`<!DOCTYPE html>
<html lang="en">
Expand Down
40 changes: 20 additions & 20 deletions gen/static/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func init() {
var memStorage = storage.NewMemoryService();
var memStorage = storage.NewMemoryService()
{
err := memStorage.Upload("mem://github.com/viant/endly/template/app/go/web/meta.yaml", bytes.NewReader([]byte(`name: go/web
description: "golang: web hello world"
Expand Down Expand Up @@ -1877,25 +1877,25 @@ CMD ["/$app"$args]`)))
}
}
{
err := memStorage.Upload("mem://github.com/viant/endly/template/regression/regression.csv", bytes.NewReader([]byte(`Workflow,,,Name,Description,Tasks,,,Init,,
,,,regression,$app app regresion test,%Tasks,,, @var/init,,
[]Tasks,,,Name,Description,Actions,,,,,
,,,prepare,prepare data for test use cases,%Prepare,,,,,
[]Prepare,,Service,Action,Description,Request,,,,,
,,workflow,run,init selenium,@req/selenium_init,,,,,
,,workflow,run,init test data,@req/data,,,,,
[]Tasks,,,Name,Description,Actions,,,,,
,,,test,Defines test requests,%Test,,,,,
[]Test{1..002},Subpath,Service,Action,Description,Request,Skip,When,Init,/Data.db.[]setup,TagDescription
,use_cases/${index}*,,nop,skip this group if skip.txt is present,{},$HasResource(${subPath}/skip.txt):true,, @var/test_init,,@use_case.txt
,use_cases/${index}*,,nop,push test data,{},,$HasResource(${subPath}/setup_data.json):true,, @setup_data,
,use_cases/${index}*,selenium,run,run selenium test, @selenium_test,,,,,
,use_cases/${index}*,http/runner,send,run HTTP test, @http_test,,,,,
,use_cases/${index}*,rest/runner,send,run REST test, @rest_test,,,,,
[]Tasks,,,Name,Description,Actions,,,,,
,,,clean,stop test services,%Clean,,,,,
[]Clean,,Service,Action,Description,Request,SleepTimeMs,,,,
,,,nop,sleep for easy debuging,{},1000,,,,
err := memStorage.Upload("mem://github.com/viant/endly/template/regression/regression.csv", bytes.NewReader([]byte(`Workflow,,,Name,Description,Tasks,,,Init,,
,,,regression,$app app regresion test,%Tasks,,, @var/init,,
[]Tasks,,,Name,Description,Actions,,,,,
,,,prepare,prepare data for test use cases,%Prepare,,,,,
[]Prepare,,Service,Action,Description,Request,,,,,
,,workflow,run,init selenium,@req/selenium_init,,,,,
,,workflow,run,init test data,@req/data,,,,,
[]Tasks,,,Name,Description,Actions,,,,,
,,,test,Defines test requests,%Test,,,,,
[]Test{1..002},Subpath,Service,Action,Description,Request,Skip,When,Init,/Data.db.[]setup,TagDescription
,use_cases/${index}*,,nop,skip this group if skip.txt is present,{},$HasResource(${subPath}/skip.txt):true,, @var/test_init,,@use_case.txt
,use_cases/${index}*,,nop,push test data,{},,$HasResource(${subPath}/setup_data.json):true,, @setup_data,
,use_cases/${index}*,selenium,run,run selenium test, @selenium_test,,,,,
,use_cases/${index}*,http/runner,send,run HTTP test, @http_test,,,,,
,use_cases/${index}*,rest/runner,send,run REST test, @rest_test,,,,,
[]Tasks,,,Name,Description,Actions,,,,,
,,,clean,stop test services,%Clean,,,,,
[]Clean,,Service,Action,Description,Request,SleepTimeMs,,,,
,,,nop,sleep for easy debuging,{},1000,,,,
,,,run,close and stop seleniun,@req/selenium_destroy,,,,,`)))
if err != nil {
log.Printf("failed to upload: mem://github.com/viant/endly/template/regression/regression.csv %v", err)
Expand Down
11 changes: 3 additions & 8 deletions gen/web/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (b *builder) getBuildDownloadMap(meta *AppMeta) Map {
var result = NewMap()
if meta.hasAppDirectory {
result.Put("${buildPath}/app/${app}", "$releasePath")
} else {
} else {
result.Put("${buildPath}/${app}", "$releasePath")
}
if len(meta.Assets) == 0 {
Expand All @@ -190,7 +190,7 @@ func (b *builder) getBuildDownloadMap(meta *AppMeta) Map {
}

func hasKeyPrefix(keyPrefix string, assets map[string]string) bool {
for candidate:= range assets {
for candidate := range assets {
if strings.HasPrefix(candidate, keyPrefix) {
return true
}
Expand Down Expand Up @@ -232,12 +232,10 @@ func (b *builder) buildApp(meta *AppMeta, sdkMeta *SdkMeta, request *RunRequest,
appDirectory = "\n - cd ${buildPath}app"
}


state.Put("dependency", dependency)
state.Put("originURL", fmt.Sprintf(`"%v"`, originURL))
state.Put("appDirectory", appDirectory)


if buildRequest.Docker {
state.Put("args", args)
appFile = "docker/app.yaml"
Expand All @@ -256,11 +254,8 @@ func (b *builder) buildApp(meta *AppMeta, sdkMeta *SdkMeta, request *RunRequest,
appMap.SubMap("pipeline.deploy").Put("upload", b.getDeployUploadMap(meta))
}


appMap.SubMap("pipeline.build").Put("download", b.getBuildDownloadMap(meta))



if app, err = toolbox.AsYamlText(appMap); err != nil {
return err
}
Expand Down Expand Up @@ -608,7 +603,7 @@ func (b *builder) addRegression(appMeta *AppMeta, request *RunRequest) error {
regression = removeMatchedLines(regression, "HTTP test")
}

if request.Testing.REST && len(appMeta.REST) > 0{
if request.Testing.REST && len(appMeta.REST) > 0 {
b.buildRESTTestAssets(appMeta, request)
} else {
regression = removeMatchedLines(regression, "REST test")
Expand Down
12 changes: 5 additions & 7 deletions runner/http/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,24 +175,22 @@ func replaceResponseBodyIfNeeded(sendHTTPRequest *Request, responseBody string)
return responseBody
}


func (s *service) applyDefaultTimeoutIfNeeded(options []*toolbox.HttpOptions) []*toolbox.HttpOptions {
func (s *service) applyDefaultTimeoutIfNeeded(options []*toolbox.HttpOptions) []*toolbox.HttpOptions {
if len(options) > 0 {
return options
}
return []*toolbox.HttpOptions{
{
Key:"RequestTimeoutMs",
Value:120000,
Key: "RequestTimeoutMs",
Value: 120000,
},
{
Key:"TimeoutMs",
Value:120000,
Key: "TimeoutMs",
Value: 120000,
},
}
}


func (s *service) send(context *endly.Context, request *SendRequest) (*SendResponse, error) {
client, err := toolbox.NewHttpClient(s.applyDefaultTimeoutIfNeeded(request.Options)...)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions system/docker/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ func (s *service) composeUp(context *endly.Context, request *ComposeRequestUp) (
response := &ComposeResponse{Containers: make([]*ContainerInfo, 0)}
compose, err := mapToComposeStructureFromURL(request.Source.URL)
if compose.Services != nil {
for k, _ := range compose.Services {
for k := range compose.Services {
if statusResponse, err := s.checkContainerProcess(context, &ContainerStatusRequest{Target: request.Target, Names: k}); err == nil && statusResponse != nil {
response.Containers = append(response.Containers, statusResponse)
}
Expand All @@ -703,7 +703,7 @@ func (s *service) composeDown(context *endly.Context, request *ComposeRequestDow
}

//Build & execute command
command := "docker-compose -f " + composePath.URL + " down"
command := "docker-compose -f " + composePath.ParsedURL.Path + " down"
_, e := s.executeSecureDockerCommand(true, request.Credentials, context, target, dockerErrors, command)
if e != nil {
return nil, NewComposeError(err.Error(), request.Source)
Expand All @@ -712,7 +712,7 @@ func (s *service) composeDown(context *endly.Context, request *ComposeRequestDow
response := &ComposeResponse{Containers: make([]*ContainerInfo, 0)}
compose, err := mapToComposeStructureFromURL(request.Source.URL)
if compose.Services != nil {
for k, _ := range compose.Services {
for k := range compose.Services {
if statusResponse, err := s.checkContainerProcess(context, &ContainerStatusRequest{Target: request.Target, Names: k}); err == nil && statusResponse != nil {
response.Containers = append(response.Containers, statusResponse)
}
Expand Down
1 change: 1 addition & 0 deletions system/docker/service_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ func (r *ComposeRequest) Validate() error {
}
return nil
}

func mapToComposeStructureFromURL(URL string) (*Compose, error) {
compose := &Compose{}
resource := url.NewResource(URL)
Expand Down
48 changes: 20 additions & 28 deletions system/docker/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import (

func TestDockerService_ComposeUp(t *testing.T) {

//var credentialFile, err = util.GetDummyCredential()
//assert.Nil(t, err)
credentialFile := "localhost"
var credentialFile, err = util.GetDummyCredential()
assert.Nil(t, err)

var target = url.NewResource("scp://127.0.0.1:22/", credentialFile) //
manager := endly.New()
Expand All @@ -40,19 +39,24 @@ func TestDockerService_ComposeUp(t *testing.T) {
target: target,
baseDir: "test/compose/up/darwin",
request: &docker.ComposeRequestUp{&docker.ComposeRequest{Target: target, Source: url.NewResource("test/compose/up/docker-compose.yaml")}, true},
expected: &docker.ComposeResponse{Containers: []*docker.ContainerInfo{
{
Status: "up",
Names: "redis",
},
},
},
expected: `{
"Containers": [
{
"ContainerID":"5280cb455e33",
"Image": "redis",
"Command": "docker-entrypoint.s…",
"Status": "up",
"Port": "6379/tcp",
"Names": "redis"
}
]
}
`,
},
}

for _, useCase := range useCases {
context, err := exec.NewSSHRecodingContext(manager, target, useCase.baseDir)
defer context.Close()
context, err := exec.NewSSHReplayContext(manager, target, useCase.baseDir)
if !assert.Nil(t, err) {
log.Fatal(err)
}
Expand All @@ -67,18 +71,14 @@ func TestDockerService_ComposeUp(t *testing.T) {
t.Log(err.Error())
continue
}

toolbox.Dump(response)
assertly.AssertValues(t, useCase.expected, response, useCase.description)
}

}

func TestDockerService_ComposeDown(t *testing.T) {

//var credentialFile, err = util.GetDummyCredential()
//assert.Nil(t, err)
credentialFile := "localhost"
var credentialFile, err = util.GetDummyCredential()
assert.Nil(t, err)

var target = url.NewResource("scp://127.0.0.1:22/", credentialFile) //
manager := endly.New()
Expand All @@ -97,18 +97,12 @@ func TestDockerService_ComposeDown(t *testing.T) {
target: target,
baseDir: "test/compose/down/darwin",
request: &docker.ComposeRequestDown{&docker.ComposeRequest{Target: target, Source: url.NewResource("test/compose/up/docker-compose.yaml")}},
expected: &docker.ComposeResponse{Containers: []*docker.ContainerInfo{
{
Status: "down",
Names: "redis",
},
},
},
expected: `{"Containers":[]}`,
},
}

for _, useCase := range useCases {
context, err := exec.NewSSHRecodingContext(manager, target, useCase.baseDir)
context, err := exec.NewSSHReplayContext(manager, target, useCase.baseDir)
defer context.Close()
if !assert.Nil(t, err) {
log.Fatal(err)
Expand All @@ -124,8 +118,6 @@ func TestDockerService_ComposeDown(t *testing.T) {
t.Log(err.Error())
continue
}

toolbox.Dump(response)
assertly.AssertValues(t, useCase.expected, response, useCase.description)
}

Expand Down
2 changes: 1 addition & 1 deletion system/docker/test/compose/down/darwin/001_000.stdin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PS1="1523932212874016000\$"
PS1="1523936312807245000\$"
1 change: 0 additions & 1 deletion system/docker/test/compose/down/darwin/001_001.stdout
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
1523932212874016000$
2 changes: 1 addition & 1 deletion system/docker/test/compose/down/darwin/002_001.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Darwin
[?1034hbash-3.2$
6 changes: 3 additions & 3 deletions system/docker/test/compose/down/darwin/004_001.stdout
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ProductName: Mac OS X
ProductVersion: 10.13.2
BuildVersion: 17C205
ProductName: Mac OS X
ProductVersion: 10.13.3
BuildVersion: 17D102
2 changes: 1 addition & 1 deletion system/docker/test/compose/down/darwin/006_001.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/usr/bin:/bin:/usr/sbin:/sbin
/usr/local/apache-maven-3.2.5/bin:/usr/local/opt/libpcap/bin:/usr/libexec/:/Projects/go/workspace/bin:/usr/local/apache-maven-3.2.5/bin:/usr/local/opt/libpcap/bin:/usr/libexec/:/Projects/go/workspace/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/oracle/instantclient_12_1/bin:/opt/oracle/instantclient_12_1/bin
2 changes: 1 addition & 1 deletion system/docker/test/compose/down/darwin/007_001.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sdharmaraj
awitas
2 changes: 1 addition & 1 deletion system/docker/test/compose/down/darwin/008_000.stdin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export PATH='/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'
export PATH='/usr/local/bin:/usr/local/apache-maven-3.2.5/bin:/usr/local/opt/libpcap/bin:/usr/libexec/:/Projects/go/workspace/bin:/usr/local/apache-maven-3.2.5/bin:/usr/local/opt/libpcap/bin:/usr/libexec/:/Projects/go/workspace/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/oracle/instantclient_12_1/bin:/opt/oracle/instantclient_12_1/bin'
2 changes: 1 addition & 1 deletion system/docker/test/compose/down/darwin/009_000.stdin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sudo docker-compose -f file:///Projects/golang/src/github.com/viant/endly/system/docker/test/compose/up/docker-compose.yaml down
sudo docker-compose -f /Projects/go/workspace/src/github.com/viant/endly/system/docker/test/compose/up/docker-compose.yaml down
2 changes: 1 addition & 1 deletion system/docker/test/compose/down/darwin/010_000.stdin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
...
***
4 changes: 3 additions & 1 deletion system/docker/test/compose/down/darwin/010_001.stdout
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
ERROR: .IOError: [Errno 2] No such file or directory: u'./file:///Projects/golang/src/github.com/viant/endly/system/docker/test/compose/up/docker-compose.yaml'
Stopping redis ...
Stopping redis ... doneRemoving redis ...
Removing redis ... doneRemoving network up_default
8 changes: 3 additions & 5 deletions system/docker/test/compose/down/darwin/011_001.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e3d9cdd4f47a redis "docker-entrypoint.s…" 12 minutes ago Up 2 minutes 6379/tcp redis
9950affd8733 us.gcr.io/tech-ops-poc/etly-service:1.6.15 "./etly-service -t f…" 3 days ago Up 8 hours 0.0.0.0:8084->8084/tcp, 0.0.0.0:9001->9000/tcp bids_gbq_transfer
5c1c2c7b7a04 us.gcr.io/tech-ops-poc/etly-service:1.6.15 "./etly-service -c f…" 3 days ago Up 8 hours 0.0.0.0:8085->8085/tcp, 0.0.0.0:9002->9000/tcp bids_etly_worker
cce27307f6ee us.gcr.io/tech-ops-poc/etly-service:1.6.15 "./etly-service -t f…" 3 days ago Up 8 hours 0.0.0.0:8083->8083/tcp, 0.0.0.0:9000->9000/tcp bids_file_transfer
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
98cbdad653df mysql:latest "docker-entrypoint.s…" 2 hours ago Up 2 hours 0.0.0.0:3306->3306/tcp endly_db1
383513fa9015 rastasheep/ubuntu-sshd:14.04 "/usr/sbin/sshd -D" 2 weeks ago Up 3 hours 0.0.0.0:7722->22/tcp go_build
2 changes: 1 addition & 1 deletion system/docker/test/compose/up/darwin/001_000.stdin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PS1="1523932340098327000\$"
PS1="1523935948396284000\$"
1 change: 0 additions & 1 deletion system/docker/test/compose/up/darwin/001_001.stdout
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
1523932340098327000$
2 changes: 1 addition & 1 deletion system/docker/test/compose/up/darwin/002_001.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Darwin
[?1034hbash-3.2$
6 changes: 3 additions & 3 deletions system/docker/test/compose/up/darwin/004_001.stdout
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ProductName: Mac OS X
ProductVersion: 10.13.2
BuildVersion: 17C205
ProductName: Mac OS X
ProductVersion: 10.13.3
BuildVersion: 17D102
2 changes: 1 addition & 1 deletion system/docker/test/compose/up/darwin/006_001.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/usr/bin:/bin:/usr/sbin:/sbin
/usr/local/apache-maven-3.2.5/bin:/usr/local/opt/libpcap/bin:/usr/libexec/:/Projects/go/workspace/bin:/usr/local/apache-maven-3.2.5/bin:/usr/local/opt/libpcap/bin:/usr/libexec/:/Projects/go/workspace/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/oracle/instantclient_12_1/bin:/opt/oracle/instantclient_12_1/bin
2 changes: 1 addition & 1 deletion system/docker/test/compose/up/darwin/007_001.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sdharmaraj
awitas
2 changes: 1 addition & 1 deletion system/docker/test/compose/up/darwin/008_000.stdin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export PATH='/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'
export PATH='/usr/local/bin:/usr/local/apache-maven-3.2.5/bin:/usr/local/opt/libpcap/bin:/usr/libexec/:/Projects/go/workspace/bin:/usr/local/apache-maven-3.2.5/bin:/usr/local/opt/libpcap/bin:/usr/libexec/:/Projects/go/workspace/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/oracle/instantclient_12_1/bin:/opt/oracle/instantclient_12_1/bin'
2 changes: 1 addition & 1 deletion system/docker/test/compose/up/darwin/009_000.stdin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sudo docker-compose -f /Projects/golang/src/github.com/viant/endly/system/docker/test/compose/up/docker-compose.yaml up -d
sudo docker-compose -f /Projects/go/workspace/src/github.com/viant/endly/system/docker/test/compose/up/docker-compose.yaml up -d
Loading

0 comments on commit e01054b

Please sign in to comment.