Skip to content

Commit

Permalink
Fix app name contains validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasgomide committed May 26, 2017
1 parent b03eb53 commit 968bad5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {
if *configFilePath == "" {
utils.LogError("Flag -c is required")
} else {
if *appNameContains != "" && !strings.Contains(os.Getenv("TSURU_APP_TOKEN"), *appNameContains) {
if *appNameContains != "" && !strings.Contains(os.Getenv("TSURU_APPNAME"), *appNameContains) {
utils.LogError("Tsuru App Name does not contains " + *appNameContains)
} else {
run()
Expand All @@ -45,7 +45,7 @@ func run() {
t = tsuru.TsuruAPI{
AppToken: os.Getenv("TSURU_APP_TOKEN"),
ApiHost: os.Getenv("TSURU_HOST"),
AppName: os.Getenv("TSURU_APP_NAME"),
AppName: os.Getenv("TSURU_APPNAME"),
}

hook.Execute(h, t)
Expand Down
23 changes: 22 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func setUpSuite() {
os.Setenv("TSURU_APP_TOKEN", "abc123")
os.Setenv("TSURU_HOST", "http://0.0.0.0")
os.Setenv("TSURU_APPNAME", "someapp-name")
os.Setenv("TSURU_APPNAME", "someapp-name-prd")
flag.Set("c", "testdata/config_fake_hook.yaml")
httpmock.Activate()
httpmock.RegisterResponder("GET", "http://0.0.0.0/deploys?app=&limit=1",
Expand All @@ -25,6 +25,7 @@ func tearDownSuite() {
defer httpmock.DeactivateAndReset()
os.Unsetenv("TSURU_TARGET")
os.Unsetenv("TSURU_TOKEN")
os.Unsetenv("TSURU_APPNAME")
flag.Set("app-name-contains", "")
}

Expand Down Expand Up @@ -77,3 +78,23 @@ func TestReturnsErrorWhenAppNameDoesNotContainsSomething(t *testing.T) {
t.Errorf("%#v, wanted %#v", msg, expected)
}
}

func TestRunHookExecuteWithAppNameContainsFlagFilled(t *testing.T) {
setUpSuite()
httpmock.RegisterResponder("GET", "http://0.0.0.0/deploys?app="+os.Getenv("TSURU_APPNAME")+"&limit=1",
httpmock.NewStringResponder(200, `[{}]`))
defer tearDownSuite()
appContains := "prd"
flag.Set("app-name-contains", appContains)

noExpected := "Tsuru App Name does not contains " + appContains
var buf bytes.Buffer
log.SetOutput(&buf)

main()
msg := buf.String()

if strings.Contains(msg, noExpected) {
t.Errorf("Expected no error, got %#v", noExpected)
}
}

0 comments on commit 968bad5

Please sign in to comment.