This fix migrates some secret create tests to api tests,
and remove redundant TestConfigCreate.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
| ... | ... |
@@ -12,45 +12,6 @@ import ( |
| 12 | 12 |
"github.com/go-check/check" |
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 |
-func (s *DockerSwarmSuite) TestSecretCreate(c *check.C) {
|
|
| 16 |
- d := s.AddDaemon(c, true, true) |
|
| 17 |
- |
|
| 18 |
- testName := "test_secret" |
|
| 19 |
- id := d.CreateSecret(c, swarm.SecretSpec{
|
|
| 20 |
- Annotations: swarm.Annotations{
|
|
| 21 |
- Name: testName, |
|
| 22 |
- }, |
|
| 23 |
- Data: []byte("TESTINGDATA"),
|
|
| 24 |
- }) |
|
| 25 |
- c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
| 26 |
- |
|
| 27 |
- secret := d.GetSecret(c, id) |
|
| 28 |
- c.Assert(secret.Spec.Name, checker.Equals, testName) |
|
| 29 |
-} |
|
| 30 |
- |
|
| 31 |
-func (s *DockerSwarmSuite) TestSecretCreateWithLabels(c *check.C) {
|
|
| 32 |
- d := s.AddDaemon(c, true, true) |
|
| 33 |
- |
|
| 34 |
- testName := "test_secret" |
|
| 35 |
- id := d.CreateSecret(c, swarm.SecretSpec{
|
|
| 36 |
- Annotations: swarm.Annotations{
|
|
| 37 |
- Name: testName, |
|
| 38 |
- Labels: map[string]string{
|
|
| 39 |
- "key1": "value1", |
|
| 40 |
- "key2": "value2", |
|
| 41 |
- }, |
|
| 42 |
- }, |
|
| 43 |
- Data: []byte("TESTINGDATA"),
|
|
| 44 |
- }) |
|
| 45 |
- c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
|
|
| 46 |
- |
|
| 47 |
- secret := d.GetSecret(c, id) |
|
| 48 |
- c.Assert(secret.Spec.Name, checker.Equals, testName) |
|
| 49 |
- c.Assert(len(secret.Spec.Labels), checker.Equals, 2) |
|
| 50 |
- c.Assert(secret.Spec.Labels["key1"], checker.Equals, "value1") |
|
| 51 |
- c.Assert(secret.Spec.Labels["key2"], checker.Equals, "value2") |
|
| 52 |
-} |
|
| 53 |
- |
|
| 54 | 15 |
// Test case for 28884 |
| 55 | 16 |
func (s *DockerSwarmSuite) TestSecretCreateResolve(c *check.C) {
|
| 56 | 17 |
d := s.AddDaemon(c, true, true) |
| ... | ... |
@@ -129,7 +129,7 @@ func createSecret(ctx context.Context, t *testing.T, client client.APIClient, na |
| 129 | 129 |
return secret.ID |
| 130 | 130 |
} |
| 131 | 131 |
|
| 132 |
-func TestSecretsCreate(t *testing.T) {
|
|
| 132 |
+func TestSecretsCreateAndDelete(t *testing.T) {
|
|
| 133 | 133 |
skip.If(t, testEnv.DaemonInfo.OSType != "linux") |
| 134 | 134 |
|
| 135 | 135 |
defer setupTest(t)() |
| ... | ... |
@@ -141,8 +141,7 @@ func TestSecretsCreate(t *testing.T) {
|
| 141 | 141 |
ctx := context.Background() |
| 142 | 142 |
|
| 143 | 143 |
testName := "test_secret" |
| 144 |
- createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), nil)
|
|
| 145 |
- require.NoError(t, err) |
|
| 144 |
+ secretID := createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), nil)
|
|
| 146 | 145 |
|
| 147 | 146 |
// create an already existin secret, daemon should return a status code of 409 |
| 148 | 147 |
_, err = client.SecretCreate(ctx, swarmtypes.SecretSpec{
|
| ... | ... |
@@ -152,27 +151,8 @@ func TestSecretsCreate(t *testing.T) {
|
| 152 | 152 |
Data: []byte("TESTINGDATA"),
|
| 153 | 153 |
}) |
| 154 | 154 |
testutil.ErrorContains(t, err, "already exists") |
| 155 |
-} |
|
| 156 |
- |
|
| 157 |
-func TestSecretsDelete(t *testing.T) {
|
|
| 158 |
- skip.If(t, testEnv.DaemonInfo.OSType != "linux") |
|
| 159 |
- |
|
| 160 |
- defer setupTest(t)() |
|
| 161 |
- d := swarm.NewSwarm(t, testEnv) |
|
| 162 |
- defer d.Stop(t) |
|
| 163 |
- client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) |
|
| 164 |
- require.NoError(t, err) |
|
| 165 |
- |
|
| 166 |
- ctx := context.Background() |
|
| 167 |
- |
|
| 168 |
- testName := "test_secret" |
|
| 169 |
- secretID := createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), nil)
|
|
| 170 |
- require.NoError(t, err) |
|
| 171 |
- |
|
| 172 |
- insp, _, err := client.SecretInspectWithRaw(ctx, secretID) |
|
| 173 |
- require.NoError(t, err) |
|
| 174 |
- assert.Equal(t, insp.ID, secretID) |
|
| 175 | 155 |
|
| 156 |
+ // Ported from original TestSecretsDelete |
|
| 176 | 157 |
err = client.SecretRemove(ctx, secretID) |
| 177 | 158 |
require.NoError(t, err) |
| 178 | 159 |
|
| ... | ... |
@@ -181,6 +161,20 @@ func TestSecretsDelete(t *testing.T) {
|
| 181 | 181 |
|
| 182 | 182 |
err = client.SecretRemove(ctx, "non-existin") |
| 183 | 183 |
testutil.ErrorContains(t, err, "No such secret: non-existin") |
| 184 |
+ |
|
| 185 |
+ // Ported from original TestSecretsCreteaWithLabels |
|
| 186 |
+ testName = "test_secret_with_labels" |
|
| 187 |
+ secretID = createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), map[string]string{
|
|
| 188 |
+ "key1": "value1", |
|
| 189 |
+ "key2": "value2", |
|
| 190 |
+ }) |
|
| 191 |
+ |
|
| 192 |
+ insp, _, err := client.SecretInspectWithRaw(ctx, secretID) |
|
| 193 |
+ require.NoError(t, err) |
|
| 194 |
+ assert.Equal(t, insp.Spec.Name, testName) |
|
| 195 |
+ assert.Equal(t, len(insp.Spec.Labels), 2) |
|
| 196 |
+ assert.Equal(t, insp.Spec.Labels["key1"], "value1") |
|
| 197 |
+ assert.Equal(t, insp.Spec.Labels["key2"], "value2") |
|
| 184 | 198 |
} |
| 185 | 199 |
|
| 186 | 200 |
func TestSecretsUpdate(t *testing.T) {
|