2015-04-01 22:46:21 +00:00
|
|
|
package github
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
logicaltest "github.com/hashicorp/vault/logical/testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBackend_basic(t *testing.T) {
|
|
|
|
logicaltest.Test(t, logicaltest.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Backend: Backend(),
|
|
|
|
Steps: []logicaltest.TestStep{
|
|
|
|
testAccStepConfig(t),
|
2015-08-28 13:28:35 +00:00
|
|
|
testAccMap(t, "default", "root"),
|
|
|
|
testAccMap(t, "oWnErs", "root"),
|
|
|
|
testAccLogin(t, []string{"root"}),
|
|
|
|
testAccStepConfigWithBaseURL(t),
|
|
|
|
testAccMap(t, "default", "root"),
|
|
|
|
testAccMap(t, "oWnErs", "root"),
|
|
|
|
testAccLogin(t, []string{"root"}),
|
2015-04-01 22:46:21 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccPreCheck(t *testing.T) {
|
|
|
|
if v := os.Getenv("GITHUB_TOKEN"); v == "" {
|
2015-05-12 05:32:09 +00:00
|
|
|
t.Fatal("GITHUB_TOKEN must be set for acceptance tests")
|
2015-04-01 22:46:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if v := os.Getenv("GITHUB_ORG"); v == "" {
|
|
|
|
t.Fatal("GITHUB_ORG must be set for acceptance tests")
|
|
|
|
}
|
2015-08-28 13:28:35 +00:00
|
|
|
|
|
|
|
if v := os.Getenv("GITHUB_BASEURL"); v == "" {
|
|
|
|
t.Fatal("GITHUB_BASEURL must be set for acceptance tests (use 'https://api.github.com' if you don't know what you're doing)")
|
|
|
|
}
|
2015-04-01 22:46:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testAccStepConfig(t *testing.T) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
|
|
|
Operation: logical.WriteOperation,
|
|
|
|
Path: "config",
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"organization": os.Getenv("GITHUB_ORG"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-28 13:28:35 +00:00
|
|
|
func testAccStepConfigWithBaseURL(t *testing.T) logicaltest.TestStep {
|
|
|
|
return logicaltest.TestStep{
|
|
|
|
Operation: logical.WriteOperation,
|
|
|
|
Path: "config",
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"organization": os.Getenv("GITHUB_ORG"),
|
|
|
|
"base_url": os.Getenv("GITHUB_BASEURL"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-11 17:24:39 +00:00
|
|
|
func testAccMap(t *testing.T, k string, v string) logicaltest.TestStep {
|
2015-04-01 22:46:21 +00:00
|
|
|
return logicaltest.TestStep{
|
|
|
|
Operation: logical.WriteOperation,
|
2015-05-11 17:24:39 +00:00
|
|
|
Path: "map/teams/" + k,
|
2015-04-01 22:46:21 +00:00
|
|
|
Data: map[string]interface{}{
|
2015-05-11 17:24:39 +00:00
|
|
|
"value": v,
|
2015-04-01 22:46:21 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2015-04-19 22:06:29 +00:00
|
|
|
|
2015-05-11 17:24:39 +00:00
|
|
|
func testAccLogin(t *testing.T, keys []string) logicaltest.TestStep {
|
2015-04-01 22:46:21 +00:00
|
|
|
return logicaltest.TestStep{
|
|
|
|
Operation: logical.WriteOperation,
|
|
|
|
Path: "login",
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"token": os.Getenv("GITHUB_TOKEN"),
|
|
|
|
},
|
|
|
|
Unauthenticated: true,
|
|
|
|
|
2015-05-11 17:24:39 +00:00
|
|
|
Check: logicaltest.TestCheckAuth(keys),
|
2015-04-01 22:46:21 +00:00
|
|
|
}
|
|
|
|
}
|