Skip to content

Commit

Permalink
cmd/token_test.go: Remove test code
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
prarit committed Jul 14, 2023
1 parent 5cc777b commit 1282241
Showing 1 changed file with 5 additions and 42 deletions.
47 changes: 5 additions & 42 deletions cmd/token_test.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
package cmd

import (
"fmt"
"os/exec"
"testing"
"time"

"github.com/stretchr/testify/require"
)

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

now := time.Now()
expiryString := fmt.Sprintf("%d-%d-%d", now.Year(), now.Month(), now.Day() + 1)

t.Run("create", func(t *testing.T) {
cmd := exec.Command(labBinaryPath, "token", "create", "--name", now.String(), "--expiresat", expiryString, "--scopes", "read_api")
cmd.Dir = repo

cmdOut, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(cmdOut))
t.Fatal(err)
}
require.Contains(t, string(cmdOut), now.String())
})

// As of 16.1, token creation is limited to administrators. Without
// creating a token it is difficult to test the creation and revoking
// of a token. If GitLab changes the permissions on creating tokens
// then the commit that introduced this message can be reverted.
t.Run("list", func(t *testing.T) {
cmd2 := exec.Command(labBinaryPath, "token", "list")
cmd2.Dir = repo
Expand All @@ -36,30 +23,6 @@ func Test_token(t *testing.T) {
t.Log(string(cmd2Out))
t.Fatal(err)
}
require.Contains(t, string(cmd2Out), now.String())
})

t.Run("revoke", func(t *testing.T) {
cmd3 := exec.Command(labBinaryPath, "token", "revoke", now.String())
cmd3.Dir = repo

cmd3Out, err := cmd3.CombinedOutput()
if err != nil {
t.Log(string(cmd3Out))
t.Fatal(err)
}
require.Contains(t, string(cmd3Out), now.String())
})

t.Run("list after revoke", func(t *testing.T) {
cmd4 := exec.Command(labBinaryPath, "token", "list")
cmd4.Dir = repo

cmd4Out, err := cmd4.CombinedOutput()
if err != nil {
t.Log(string(cmd4Out))
t.Fatal(err)
}
require.NotContains(t, string(cmd4Out), now.String())
require.NotEmpty(t, string(cmd2Out))
})
}

0 comments on commit 1282241

Please sign in to comment.