Skip to content

Commit 016b7ea

Browse files
committed
Adding CLI tests
1 parent 4b7323f commit 016b7ea

File tree

9 files changed

+159
-31
lines changed

9 files changed

+159
-31
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2019 WaveSoftware
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,73 @@
11
Installer for Openshift Serverless
22
==================================
33

4+
[![Build Status](https://travis-ci.com/wavesoftware/serverless-installer.svg?branch=master)](https://travis-ci.com/wavesoftware/serverless-installer)
5+
46
Installer will create a usable installation of Openshift's Serverless Platform.
57

68
## Usage
79

10+
### Interactive
11+
12+
This command invoked without any parameters will enter TUI.
13+
User is asked couple questions and then his answers are save on disk to
14+
be later used by deploy command.
15+
16+
```bash
17+
serverless-installer
18+
```
19+
20+
### Deploy
21+
22+
This command will deploy a serverless platform on currently configured Openshift cluster.
23+
824
```bash
9-
serverless-installer deploy
25+
serverless-installer deploy --answers serverless-installer-answers.yaml
1026
```
1127

12-
This command will deploy a serverless platform on currently configured cluster.
28+
Answers are expected to be produced by interactive mode.
29+
30+
## Installation
31+
32+
### Go
33+
34+
if you have usable Go `>= 1.13` installation simply invoke:
1335

1436
```bash
15-
serverless-installer script
16-
```
37+
go get -u github.com/wavesoftware/serverless-installer
38+
```
39+
40+
This will produce a binary that you can use.
41+
42+
### Precompiled binaries
43+
44+
**To be determined!**
45+
46+
Procompiled binaries can be found in GitHub's releases page:
47+
48+
* [Linux amd64](https://github.com/wavesoftware/serverless-installer/releases/latest)
49+
* [MacOSX amd64](https://github.com/wavesoftware/serverless-installer/releases/latest)
50+
* [Windows amd64](https://github.com/wavesoftware/serverless-installer/releases/latest)
51+
52+
## Development
53+
54+
To build simply invoke (it will check & test the code as well):
55+
56+
```bash
57+
make
58+
```
59+
60+
Go `>= 1.13` is required to build.
61+
62+
Contributions are welcome!
63+
64+
To contribute, follow the standard [git flow](http://danielkummer.github.io/git-flow-cheatsheet/) of:
65+
66+
1. Fork it
67+
1. Create your feature branch (`git checkout -b feature/my-new-feature`)
68+
1. Commit your changes (`git commit -am 'Add some feature'`)
69+
1. Push to the branch (`git push origin feature/my-new-feature`)
70+
1. Create new Pull Request
71+
72+
Even if you can't contribute code, if you have an idea for an improvement
73+
please open an [issue](https://github.com/wavesoftware/serverless-installer/issues).

cmd/installer/main_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ func TestMain(t *testing.T) {
2626

2727
assert.Equal(t, 0, exitcode)
2828
}
29+
30+
func TestExit(t *testing.T) {
31+
exit(0)
32+
}

internal/cli/deploy.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@ type deployT struct {
1212
Logging
1313
}
1414

15-
var deploy = &cli.Command{
16-
Name: "deploy",
17-
Desc: "Deploys a Serverless onto Openshift cluster using ansers file",
18-
Argv: func() interface{} { return new(deployT) },
19-
Fn: func(ctx *cli.Context) error {
20-
argv := ctx.Argv().(*deployT)
21-
log.SetOutput(ctx.Writer())
22-
log.SetLevel(argv.Logging.Level.value)
15+
func deploy() *cli.Command {
16+
return &cli.Command{
17+
Name: "deploy",
18+
Desc: "Deploys a Serverless onto Openshift cluster using ansers file",
19+
Argv: func() interface{} { return new(deployT) },
20+
Fn: func(ctx *cli.Context) error {
21+
argv := ctx.Argv().(*deployT)
22+
log.SetOutput(ctx.Writer())
23+
log.SetLevel(argv.Logging.Level.value)
2324

24-
ctx.String("Hello, from deploy command. Answers file is %s\n", argv.Answers)
25-
log.
26-
WithField("answers-file", argv.Answers).
27-
Info("Hello, from deploy command.")
28-
return nil
29-
},
25+
log.
26+
WithField("answers-file", argv.Answers).
27+
Info("Hello, from deploy command.")
28+
return nil
29+
},
30+
}
3031
}

internal/cli/interactive.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ type interactiveT struct {
1616
Logging
1717
}
1818

19-
var interactive = &cli.Command{
20-
Desc: `Installer for Openshift Serverless
21-
19+
func interactive() *cli.Command {
20+
return &cli.Command{
21+
Desc: `Installer for Openshift Serverless
22+
2223
Run without any options to enter interactive shell that will guide you
2324
through installation process and produce an answers file. That answers
2425
file can by applied on current Openshift cluster with deploy command.`,
2526

26-
Argv: func() interface{} { return new(interactiveT) },
27-
Fn: operate,
27+
Argv: func() interface{} { return new(interactiveT) },
28+
Fn: operate,
29+
}
2830
}
2931

3032
func operate(ctx *cli.Context) error {
@@ -56,7 +58,7 @@ func save(answers contract.LocationAwareAnswers) error {
5658
err := saver.Save(*answers.Answers, answers.Path)
5759
if err == nil {
5860
log.
59-
WithField("Answers file", answers.Path).
61+
WithField("Location", answers.Path).
6062
Info("Answers file has been saved.")
6163
}
6264
return err
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package interactive
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/wavesoftware/serverless-installer/internal/domain/contract"
8+
)
9+
10+
func TestCreate(t *testing.T) {
11+
// given
12+
answers := contract.LocationAwareAnswers{}
13+
14+
// when
15+
screen := Create(&answers)
16+
17+
// then
18+
assert.NotNil(t, screen)
19+
}

internal/cli/runner.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package cli
22

33
import (
4-
"fmt"
54
"os"
65

76
"github.com/mkideal/cli"
87
"github.com/sirupsen/logrus"
98
)
109

11-
var help = cli.HelpCommand("display help information")
10+
func help() *cli.Command {
11+
return cli.HelpCommand("display help information")
12+
}
1213

1314
type runner struct {
1415
args []string
@@ -37,11 +38,11 @@ func (r runner) Run() int {
3738
TimestampFormat: "15:04:05.000",
3839
})
3940
if err := cli.Root(
40-
interactive,
41-
cli.Tree(help),
42-
cli.Tree(deploy),
41+
interactive(),
42+
cli.Tree(help()),
43+
cli.Tree(deploy()),
4344
).Run(r.args[1:]); err != nil {
44-
fmt.Fprintln(os.Stderr, err)
45+
logrus.Error(err)
4546
return 1
4647
}
4748
return 0

internal/cli/runner_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cli
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestBasicRunnerFactory(t *testing.T) {
10+
// when
11+
runner := NewRunner()
12+
13+
// then
14+
assert.NotNil(t, runner)
15+
}
16+
17+
func TestHelpRun(t *testing.T) {
18+
// given
19+
args := []string{"cmd", "--help"}
20+
runner := NewRunnerWithArgs(args)
21+
22+
// when
23+
retcode := runner.Run()
24+
25+
// then
26+
assert.Equal(t, 0, retcode)
27+
}
28+
29+
func TestInvalidRun(t *testing.T) {
30+
// given
31+
args := []string{"cmd", "invalid_command"}
32+
runner := NewRunnerWithArgs(args)
33+
34+
// when
35+
retcode := runner.Run()
36+
37+
// then
38+
assert.Equal(t, 1, retcode)
39+
}

internal/domain/contract/answers_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ func TestStruct(t *testing.T) {
1313
// then
1414
assert.NotNil(t, answers)
1515
}
16+
17+
func TestFilename(t *testing.T) {
18+
// then
19+
assert.NotEmpty(t, AnswersFilename)
20+
}

0 commit comments

Comments
 (0)