|
1 | 1 | package tests |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
4 | 5 | "os" |
5 | 6 | "testing" |
6 | 7 |
|
@@ -100,3 +101,102 @@ func TestDeployKey(t *testing.T) { |
100 | 101 | } |
101 | 102 | }) |
102 | 103 | } |
| 104 | + |
| 105 | +func TestDeployKeyWithComment(t *testing.T) { |
| 106 | + user := os.Getenv("BITBUCKET_TEST_USERNAME") |
| 107 | + pass := os.Getenv("BITBUCKET_TEST_PASSWORD") |
| 108 | + owner := os.Getenv("BITBUCKET_TEST_OWNER") |
| 109 | + repo := os.Getenv("BITBUCKET_TEST_REPOSLUG") |
| 110 | + |
| 111 | + if user == "" { |
| 112 | + t.Error("BITBUCKET_TEST_USERNAME is empty.") |
| 113 | + } |
| 114 | + if pass == "" { |
| 115 | + t.Error("BITBUCKET_TEST_PASSWORD is empty.") |
| 116 | + } |
| 117 | + if owner == "" { |
| 118 | + t.Error("BITBUCKET_TEST_OWNER is empty.") |
| 119 | + } |
| 120 | + if repo == "" { |
| 121 | + t.Error("BITBUCKET_TEST_REPOSLUG is empty.") |
| 122 | + } |
| 123 | + |
| 124 | + c := bitbucket.NewBasicAuth(user, pass) |
| 125 | + |
| 126 | + var deployKeyResourceId int |
| 127 | + |
| 128 | + label := "go-bb-test" |
| 129 | + key := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAK/b1cHHDr/TEV1JGQl+WjCwStKG6Bhrv0rFpEsYlyTBm1fzN0VOJJYn4ZOPCPJwqse6fGbXntEs+BbXiptR+++HycVgl65TMR0b5ul5AgwrVdZdT7qjCOCgaSV74/9xlHDK8oqgGnfA7ZoBBU+qpVyaloSjBdJfLtPY/xqj4yHnXKYzrtn/uFc4Kp9Tb7PUg9Io3qohSTGJGVHnsVblq/rToJG7L5xIo0OxK0SJSQ5vuId93ZuFZrCNMXj8JDHZeSEtjJzpRCBEXHxpOPhAcbm4MzULgkFHhAVgp4JbkrT99/wpvZ7r9AdkTg7HGqL3rlaDrEcWfL7Lu6TnhBdq5" |
| 130 | + |
| 131 | + |
| 132 | + t.Run("create", func(t *testing.T) { |
| 133 | + opt := &bitbucket.DeployKeyOptions{ |
| 134 | + Owner: owner, |
| 135 | + RepoSlug: repo, |
| 136 | + Label: label, |
| 137 | + Key: fmt.Sprintf("%s %s", key, comment), |
| 138 | + } |
| 139 | + |
| 140 | + deployKey, err := c.Repositories.DeployKeys.Create(opt) |
| 141 | + if err != nil { |
| 142 | + t.Error(err) |
| 143 | + } |
| 144 | + |
| 145 | + if deployKey == nil { |
| 146 | + t.Error("The Deploy Key could not be created.") |
| 147 | + } |
| 148 | + |
| 149 | + if deployKey.Label != label { |
| 150 | + t.Error("The Deploy Key `label` attribute does not match the expected value.") |
| 151 | + } |
| 152 | + if deployKey.Key != key { |
| 153 | + t.Error("The Deploy Key `key` attribute does not match the expected value.") |
| 154 | + } |
| 155 | + if deployKey.Comment != comment { |
| 156 | + t.Error("The Deploy Key `comment` attribute does not match the expected value.") |
| 157 | + } |
| 158 | + |
| 159 | + deployKeyResourceId = deployKey.Id |
| 160 | + }) |
| 161 | + |
| 162 | + t.Run("get", func(t *testing.T) { |
| 163 | + opt := &bitbucket.DeployKeyOptions{ |
| 164 | + Owner: owner, |
| 165 | + RepoSlug: repo, |
| 166 | + Id: deployKeyResourceId, |
| 167 | + } |
| 168 | + deployKey, err := c.Repositories.DeployKeys.Get(opt) |
| 169 | + if err != nil { |
| 170 | + t.Error(err) |
| 171 | + } |
| 172 | + |
| 173 | + if deployKey == nil { |
| 174 | + t.Error("The Deploy Key could not be retrieved.") |
| 175 | + } |
| 176 | + |
| 177 | + if deployKey.Id != deployKeyResourceId { |
| 178 | + t.Error("The Deploy Key `label` attribute does not match the expected value.") |
| 179 | + } |
| 180 | + if deployKey.Label != label { |
| 181 | + t.Error("The Deploy Key `label` attribute does not match the expected value.") |
| 182 | + } |
| 183 | + if deployKey.Key != key { |
| 184 | + t.Error("The Deploy Key `key` attribute does not match the expected value.") |
| 185 | + } |
| 186 | + if deployKey.Comment != comment { |
| 187 | + t.Error("The Deploy Key `comment` attribute does not match the expected value.") |
| 188 | + } |
| 189 | + }) |
| 190 | + |
| 191 | + t.Run("delete", func(t *testing.T) { |
| 192 | + opt := &bitbucket.DeployKeyOptions{ |
| 193 | + Owner: owner, |
| 194 | + RepoSlug: repo, |
| 195 | + Id: deployKeyResourceId, |
| 196 | + } |
| 197 | + _, err := c.Repositories.DeployKeys.Delete(opt) |
| 198 | + if err != nil { |
| 199 | + t.Error(err) |
| 200 | + } |
| 201 | + }) |
| 202 | +} |
0 commit comments