Skip to content

Commit 4b2c6d4

Browse files
Keerthan MalaKeerthan Reddy Mala
authored andcommitted
fix(scale):dont call controller if there is no valid scale pattern
1 parent aec1656 commit 4b2c6d4

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

cmd/ps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func PsScale(appID string, targets []string) error {
5353
return err
5454
}
5555
} else {
56-
fmt.Printf("'%s' does not match the pattern 'type=num', ex: web=2\n", target)
56+
return fmt.Errorf("'%s' does not match the pattern 'type=num', ex: web=2\n", target)
5757
}
5858
}
5959

cmd/ps_test.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
package cmd
22

3-
import "testing"
3+
import (
4+
"github.com/deis/workflow-cli/settings"
5+
"io/ioutil"
6+
"os"
7+
"testing"
8+
)
9+
10+
func TestScaleFail(t *testing.T) {
11+
tmpDir, err := ioutil.TempDir("", "tmpdir")
12+
if err != nil {
13+
t.Fatalf("error creating temp directory (%s)", err)
14+
}
15+
err = os.Mkdir(tmpDir+"/.deis", 0666)
16+
if err != nil {
17+
t.Fatalf("error creating temp directory (%s)", err)
18+
}
19+
os.Setenv("DEIS_PROFILE", "testing")
20+
settings.SetHome(tmpDir)
21+
data := []byte(`{"username":"test","ssl_verify":false,"controller":"http://deis.127.0.0.1.nip.io","token":"test","response_limit":0}`)
22+
if err := ioutil.WriteFile(tmpDir+"/.deis/testing.json", data, 0644); err != nil {
23+
t.Fatalf("error creating %s/.deis/testing.json (%s)", tmpDir, err)
24+
}
25+
defer func() {
26+
if err := os.RemoveAll(tmpDir); err != nil {
27+
t.Fatalf("failed to remove creds file from %s (%s)", tmpDir, err)
28+
}
29+
}()
30+
31+
expected := "'web=-1' does not match the pattern 'type=num', ex: web=2\n"
32+
actual := PsScale("testApp", []string{"web=-1"})
33+
if actual.Error() != expected {
34+
t.Errorf("Expected %s, Got %s", expected, actual)
35+
}
36+
}
437

538
func TestParseType(t *testing.T) {
639
t.Parallel()
@@ -21,7 +54,6 @@ func TestParseType(t *testing.T) {
2154
t.Errorf("type was not cmd (got %s) or psName was not %s (got %s)", psType, deployPod, psName)
2255
}
2356

24-
2557
// test type by itself
2658
psType, psName = parseType("cmd", "fake")
2759
if psType != "cmd" || psName != "" {

0 commit comments

Comments
 (0)