-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Becca Petrin
authored
Apr 16, 2019
1 parent
b3beddb
commit 791faba
Showing
4 changed files
with
181 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestGeneratePolicy(t *testing.T) { | ||
w := new(bytes.Buffer) | ||
info := &instanceInfo{ | ||
OrganizationGUID: "org-id", | ||
SpaceGUID: "space-id", | ||
ServiceInstanceGUID: "service-instance-id", | ||
} | ||
if err := GeneratePolicy(w, info); err != nil { | ||
t.Fatal(err) | ||
} | ||
result := w.String() | ||
if result != expectedWithoutAppID { | ||
t.Fatalf("received unexpected policy of %s", result) | ||
} | ||
|
||
w = new(bytes.Buffer) | ||
info.ApplicationGUID = "application-id" | ||
if err := GeneratePolicy(w, info); err != nil { | ||
t.Fatal(err) | ||
} | ||
result = w.String() | ||
if result != expectedWithAppID { | ||
t.Fatalf("received unexpected policy of %s", result) | ||
} | ||
} | ||
|
||
var expectedWithoutAppID = ` | ||
path "cf/service-instance-id" { | ||
capabilities = ["list"] | ||
} | ||
path "cf/service-instance-id/*" { | ||
capabilities = ["create", "read", "update", "delete", "list"] | ||
} | ||
path "cf/space-id" { | ||
capabilities = ["list"] | ||
} | ||
path "cf/space-id/*" { | ||
capabilities = ["create", "read", "update", "delete", "list"] | ||
} | ||
path "cf/org-id" { | ||
capabilities = ["list"] | ||
} | ||
path "cf/org-id/*" { | ||
capabilities = ["read", "list"] | ||
} | ||
` | ||
|
||
var expectedWithAppID = ` | ||
path "cf/service-instance-id" { | ||
capabilities = ["list"] | ||
} | ||
path "cf/service-instance-id/*" { | ||
capabilities = ["create", "read", "update", "delete", "list"] | ||
} | ||
path "cf/space-id" { | ||
capabilities = ["list"] | ||
} | ||
path "cf/space-id/*" { | ||
capabilities = ["create", "read", "update", "delete", "list"] | ||
} | ||
path "cf/org-id" { | ||
capabilities = ["list"] | ||
} | ||
path "cf/org-id/*" { | ||
capabilities = ["read", "list"] | ||
} | ||
path "cf/application-id" { | ||
capabilities = ["list"] | ||
} | ||
path "cf/application-id/*" { | ||
capabilities = ["create", "read", "update", "delete", "list"] | ||
} | ||
` |