Skip to content

Commit 1282241

Browse files
committed
cmd/token_test.go: Remove test code
GitLab only allows administrators to create tokens via the API. This is strange given that users can create tokens in the WebUI without any issues. Remove some of the test code. Hopefully one day this commit can be reverted and the test code can be executed. Signed-off-by: Prarit Bhargava <prarit@redhat.com>
1 parent 5cc777b commit 1282241

File tree

1 file changed

+5
-42
lines changed

1 file changed

+5
-42
lines changed

cmd/token_test.go

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,19 @@
11
package cmd
22

33
import (
4-
"fmt"
54
"os/exec"
65
"testing"
7-
"time"
86

97
"github.com/stretchr/testify/require"
108
)
119

1210
func Test_token(t *testing.T) {
1311
repo := copyTestRepo(t)
1412

15-
now := time.Now()
16-
expiryString := fmt.Sprintf("%d-%d-%d", now.Year(), now.Month(), now.Day() + 1)
17-
18-
t.Run("create", func(t *testing.T) {
19-
cmd := exec.Command(labBinaryPath, "token", "create", "--name", now.String(), "--expiresat", expiryString, "--scopes", "read_api")
20-
cmd.Dir = repo
21-
22-
cmdOut, err := cmd.CombinedOutput()
23-
if err != nil {
24-
t.Log(string(cmdOut))
25-
t.Fatal(err)
26-
}
27-
require.Contains(t, string(cmdOut), now.String())
28-
})
29-
13+
// As of 16.1, token creation is limited to administrators. Without
14+
// creating a token it is difficult to test the creation and revoking
15+
// of a token. If GitLab changes the permissions on creating tokens
16+
// then the commit that introduced this message can be reverted.
3017
t.Run("list", func(t *testing.T) {
3118
cmd2 := exec.Command(labBinaryPath, "token", "list")
3219
cmd2.Dir = repo
@@ -36,30 +23,6 @@ func Test_token(t *testing.T) {
3623
t.Log(string(cmd2Out))
3724
t.Fatal(err)
3825
}
39-
require.Contains(t, string(cmd2Out), now.String())
40-
})
41-
42-
t.Run("revoke", func(t *testing.T) {
43-
cmd3 := exec.Command(labBinaryPath, "token", "revoke", now.String())
44-
cmd3.Dir = repo
45-
46-
cmd3Out, err := cmd3.CombinedOutput()
47-
if err != nil {
48-
t.Log(string(cmd3Out))
49-
t.Fatal(err)
50-
}
51-
require.Contains(t, string(cmd3Out), now.String())
52-
})
53-
54-
t.Run("list after revoke", func(t *testing.T) {
55-
cmd4 := exec.Command(labBinaryPath, "token", "list")
56-
cmd4.Dir = repo
57-
58-
cmd4Out, err := cmd4.CombinedOutput()
59-
if err != nil {
60-
t.Log(string(cmd4Out))
61-
t.Fatal(err)
62-
}
63-
require.NotContains(t, string(cmd4Out), now.String())
26+
require.NotEmpty(t, string(cmd2Out))
6427
})
6528
}

0 commit comments

Comments
 (0)