Skip to content

Commit

Permalink
Merge pull request #427 from terraform-providers/ap_426_provider_inse…
Browse files Browse the repository at this point in the history
…cure_test

add /orgs mockgithub api endpoint in provider test
  • Loading branch information
Jeremy Udit authored Apr 15, 2020
2 parents e8af748 + b5c68ef commit d9d9afd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
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)
}

0 comments on commit d9d9afd

Please sign in to comment.