Skip to content

Commit

Permalink
refactor code to not require flag within integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Feb 9, 2021
1 parent cacd5d8 commit 6669cb5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
28 changes: 14 additions & 14 deletions pkg/compute/compute_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestInit(t *testing.T) {
},
{
name: "unkown repository",
args: []string{"compute", "init", "--from", "https://example.com/template", "--backend-port", "80"},
args: []string{"compute", "init", "--from", "https://example.com/template"},
configFile: config.File{Token: "123"},
api: mock.API{
GetTokenSelfFn: tokenOK,
Expand All @@ -67,7 +67,7 @@ func TestInit(t *testing.T) {
},
{
name: "create service error",
args: []string{"compute", "init", "--backend-port", "80"},
args: []string{"compute", "init"},
configFile: config.File{Token: "123"},
api: mock.API{
GetTokenSelfFn: tokenOK,
Expand All @@ -78,7 +78,7 @@ func TestInit(t *testing.T) {
},
{
name: "create domain error",
args: []string{"compute", "init", "--backend-port", "80"},
args: []string{"compute", "init"},
configFile: config.File{Token: "123"},
api: mock.API{
GetTokenSelfFn: tokenOK,
Expand All @@ -91,7 +91,7 @@ func TestInit(t *testing.T) {
},
{
name: "create backend error",
args: []string{"compute", "init", "--backend-port", "80"},
args: []string{"compute", "init"},
configFile: config.File{Token: "123"},
api: mock.API{
GetTokenSelfFn: tokenOK,
Expand All @@ -106,7 +106,7 @@ func TestInit(t *testing.T) {
},
{
name: "with name",
args: []string{"compute", "init", "--name", "test", "--backend-port", "80"},
args: []string{"compute", "init", "--name", "test"},
configFile: config.File{Token: "123"},
api: mock.API{
GetTokenSelfFn: tokenOK,
Expand All @@ -124,7 +124,7 @@ func TestInit(t *testing.T) {
},
{
name: "with service",
args: []string{"compute", "init", "-s", "test", "--backend-port", "80"},
args: []string{"compute", "init", "-s", "test"},
configFile: config.File{Token: "123"},
api: mock.API{
GetTokenSelfFn: tokenOK,
Expand All @@ -144,7 +144,7 @@ func TestInit(t *testing.T) {
},
{
name: "with description",
args: []string{"compute", "init", "--description", "test", "--backend-port", "80"},
args: []string{"compute", "init", "--description", "test"},
configFile: config.File{Token: "123"},
api: mock.API{
GetTokenSelfFn: tokenOK,
Expand All @@ -162,7 +162,7 @@ func TestInit(t *testing.T) {
},
{
name: "with author",
args: []string{"compute", "init", "--author", "test@example.com", "--backend-port", "80"},
args: []string{"compute", "init", "--author", "test@example.com"},
configFile: config.File{Token: "123"},
api: mock.API{
GetTokenSelfFn: tokenOK,
Expand All @@ -180,7 +180,7 @@ func TestInit(t *testing.T) {
},
{
name: "with multiple authors",
args: []string{"compute", "init", "--author", "test1@example.com", "--author", "test2@example.com", "--backend-port", "80"},
args: []string{"compute", "init", "--author", "test1@example.com", "--author", "test2@example.com"},
configFile: config.File{Token: "123"},
api: mock.API{
GetTokenSelfFn: tokenOK,
Expand All @@ -199,7 +199,7 @@ func TestInit(t *testing.T) {

{
name: "with from repository and branch",
args: []string{"compute", "init", "--from", "https://github.com/fastly/compute-starter-kit-rust-default.git", "--branch", "main", "--backend-port", "80"},
args: []string{"compute", "init", "--from", "https://github.com/fastly/compute-starter-kit-rust-default.git", "--branch", "main"},
configFile: config.File{Token: "123"},
api: mock.API{
GetTokenSelfFn: tokenOK,
Expand All @@ -216,7 +216,7 @@ func TestInit(t *testing.T) {
},
{
name: "with existing package manifest",
args: []string{"compute", "init", "--backend-port", "80"},
args: []string{"compute", "init"},
configFile: config.File{Token: "123"},
manifest: strings.Join([]string{
"service_id = \"1234\"",
Expand All @@ -243,7 +243,7 @@ func TestInit(t *testing.T) {
},
{
name: "default",
args: []string{"compute", "init", "--backend-port", "80"},
args: []string{"compute", "init"},
configFile: config.File{
Token: "123",
Email: "test@example.com",
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestInit(t *testing.T) {
},
{
name: "with default name inferred from directory",
args: []string{"compute", "init", "--backend-port", "80"},
args: []string{"compute", "init"},
configFile: config.File{Token: "123"},
api: mock.API{
GetTokenSelfFn: tokenOK,
Expand All @@ -288,7 +288,7 @@ func TestInit(t *testing.T) {
},
{
name: "with AssemblyScript language",
args: []string{"compute", "init", "--language", "assemblyscript", "--backend-port", "80"},
args: []string{"compute", "init", "--language", "assemblyscript"},
configFile: config.File{Token: "123"},
api: mock.API{
GetTokenSelfFn: tokenOK,
Expand Down
5 changes: 2 additions & 3 deletions pkg/compute/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,15 @@ func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error) {
}

if c.backendPort == 0 {
c.backendPort = 80

input, err := text.Input(out, "Backend port number: [80] ", in)
if err != nil {
return fmt.Errorf("error reading input %w", err)
}

portnumber, err := strconv.Atoi(input)
if err != nil {
return fmt.Errorf("error converting input %w", err)
text.Warning(out, "error converting input: %v. We'll use the default port number: [80].", err)
portnumber = 80
}

c.backendPort = uint(portnumber)
Expand Down

0 comments on commit 6669cb5

Please sign in to comment.