@@ -14,11 +14,9 @@ import (
1414)
1515
1616func TestAccGithubUserSshSigningKey (t * testing.T ) {
17-
18- randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
19- testKey := newTestSigningKey ()
20-
21- t .Run ("creates and destroys a user SSH key without error" , func (t * testing.T ) {
17+ t .Run ("creates and destroys a user SSH signing key without error" , func (t * testing.T ) {
18+ randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
19+ testKey := newTestSigningKey ()
2220
2321 config := fmt .Sprintf (`
2422 resource "github_user_ssh_signing_key" "test" {
@@ -29,43 +27,32 @@ func TestAccGithubUserSshSigningKey(t *testing.T) {
2927
3028 check := resource .ComposeTestCheckFunc (
3129 resource .TestMatchResourceAttr (
32- "github_user_ssh_signing_key.test" , "title" ,
30+ "github_user_ssh_signing_key.test" ,
31+ "title" ,
3332 regexp .MustCompile (randomID ),
3433 ),
3534 resource .TestMatchResourceAttr (
36- "github_user_ssh_signing_key.test" , "key" ,
35+ "github_user_ssh_signing_key.test" ,
36+ "key" ,
3737 regexp .MustCompile ("^ssh-rsa " ),
3838 ),
3939 )
4040
41- testCase := func (t * testing.T , mode string ) {
42- resource .Test (t , resource.TestCase {
43- PreCheck : func () { skipUnlessMode (t , mode ) },
44- Providers : testAccProviders ,
45- Steps : []resource.TestStep {
46- {
47- Config : config ,
48- Check : check ,
49- },
41+ resource .Test (t , resource.TestCase {
42+ PreCheck : func () { skipUnauthenticated (t ) },
43+ ProviderFactories : providerFactories ,
44+ Steps : []resource.TestStep {
45+ {
46+ Config : config ,
47+ Check : check ,
5048 },
51- })
52- }
53-
54- t .Run ("with an anonymous account" , func (t * testing.T ) {
55- t .Skip ("anonymous account not supported for this operation" )
56- })
57-
58- t .Run ("with an individual account" , func (t * testing.T ) {
59- testCase (t , individual )
60- })
61-
62- t .Run ("with an organization account" , func (t * testing.T ) {
63- testCase (t , organization )
49+ },
6450 })
65-
6651 })
6752
68- t .Run ("imports an individual account SSH key without error" , func (t * testing.T ) {
53+ t .Run ("imports an individual account SSH signing key without error" , func (t * testing.T ) {
54+ randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
55+ testKey := newTestSigningKey ()
6956
7057 config := fmt .Sprintf (`
7158 resource "github_user_ssh_signing_key" "test" {
@@ -79,42 +66,26 @@ func TestAccGithubUserSshSigningKey(t *testing.T) {
7966 resource .TestCheckResourceAttrSet ("github_user_ssh_signing_key.test" , "key" ),
8067 )
8168
82- testCase := func (t * testing.T , mode string ) {
83- resource .Test (t , resource.TestCase {
84- PreCheck : func () { skipUnlessMode (t , mode ) },
85- Providers : testAccProviders ,
86- Steps : []resource.TestStep {
87- {
88- Config : config ,
89- Check : check ,
90- },
91- {
92- ResourceName : "github_user_ssh_signing_key.test" ,
93- ImportState : true ,
94- ImportStateVerify : true ,
95- },
69+ resource .Test (t , resource.TestCase {
70+ PreCheck : func () { skipUnauthenticated (t ) },
71+ ProviderFactories : providerFactories ,
72+ Steps : []resource.TestStep {
73+ {
74+ Config : config ,
75+ Check : check ,
9676 },
97- })
98- }
99-
100- t .Run ("with an anonymous account" , func (t * testing.T ) {
101- t .Skip ("anonymous account not supported for this operation" )
102- })
103-
104- t .Run ("with an individual account" , func (t * testing.T ) {
105- testCase (t , individual )
106- })
107-
108- t .Run ("with an organization account" , func (t * testing.T ) {
109- testCase (t , organization )
77+ {
78+ ResourceName : "github_user_ssh_signing_key.test" ,
79+ ImportState : true ,
80+ ImportStateVerify : true ,
81+ },
82+ },
11083 })
111-
11284 })
11385}
11486
11587func newTestSigningKey () string {
11688 privateKey , _ := rsa .GenerateKey (rand .Reader , 1024 )
11789 publicKey , _ := ssh .NewPublicKey (& privateKey .PublicKey )
118- testKey := strings .TrimRight (string (ssh .MarshalAuthorizedKey (publicKey )), "\n " )
119- return testKey
90+ return strings .TrimRight (string (ssh .MarshalAuthorizedKey (publicKey )), "\n " )
12091}
0 commit comments