Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add /orgs mockgithub api endpoint in provider test #427

Merged
merged 3 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Generate Test Fixtures
run: |
openssl req -x509 -newkey rsa:4096 -days 1 -nodes \
-subj "/C=US/ST=CA/L=San Francisco/O=HashiCorp, Inc./CN=localhost" \
-subj "/C=US/ST=CA/L=San Francisco/O=HashiCorp, Inc./CN=untrusted" \
-keyout github/test-fixtures/key.pem -out github/test-fixtures/cert.pem

- name: Acceptance Tests
Expand Down
18 changes: 15 additions & 3 deletions github/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func testAccPreCheck(t *testing.T) {
}
}

func TestProvider_individual(t *testing.T) {
func TestAccProvider_individual(t *testing.T) {

username := "hashibot"
resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestProvider_individual(t *testing.T) {
})
}

func TestProvider_anonymous(t *testing.T) {
func TestAccProvider_anonymous(t *testing.T) {

username := "hashibot"
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestProvider_anonymous(t *testing.T) {
})
}

func TestProvider_insecure(t *testing.T) {
func TestAccProvider_insecure(t *testing.T) {
// Use ephemeral port range (49152–65535)
port := fmt.Sprintf("%d", 49152+rand.Intn(16382))

Expand Down Expand Up @@ -199,6 +199,7 @@ func githubTLSApiMock(port, certFile, keyFile string, t *testing.T) (string, fun
mux.HandleFunc("/users/hashibot", testRespondJson(userResponseBody))
mux.HandleFunc("/users/hashibot/gpg_keys", testRespondJson(gpgKeysResponseBody))
mux.HandleFunc("/users/hashibot/keys", testRespondJson(keysResponseBody))
mux.HandleFunc("/orgs/"+testOrganization, testRespondJson(orgResponseBody(port)))

server := &http.Server{
Addr: ":" + port,
Expand Down Expand Up @@ -317,3 +318,14 @@ const keysResponseBody = `[
"key": "ssh-rsa AAA..."
}
]`

func orgResponseBody(port string) string {
url := fmt.Sprintf(`https://localhost:%s/orgs/%s`, port, testOrganization)
return fmt.Sprintf(`
{
"login": "%s",
"url" : "%s",
"repos_url": "%s/repos"
}
`, testOrganization, url, url)
}