2023-10-19 09:24:24 +02:00
|
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package actions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 21:41:27 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-10-19 09:24:24 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetLatestRunnerToken(t *testing.T) {
|
2024-07-30 21:41:27 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2023-10-19 09:24:24 +02:00
|
|
|
token := unittest.AssertExistsAndLoadBean(t, &ActionRunnerToken{ID: 3})
|
|
|
|
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
|
2024-07-30 21:41:27 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.EqualValues(t, expectedToken, token)
|
2023-10-19 09:24:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewRunnerToken(t *testing.T) {
|
2024-07-30 21:41:27 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2023-10-19 09:24:24 +02:00
|
|
|
token, err := NewRunnerToken(db.DefaultContext, 1, 0)
|
2024-07-30 21:41:27 +02:00
|
|
|
require.NoError(t, err)
|
2023-10-19 09:24:24 +02:00
|
|
|
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
|
2024-07-30 21:41:27 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.EqualValues(t, expectedToken, token)
|
2023-10-19 09:24:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateRunnerToken(t *testing.T) {
|
2024-07-30 21:41:27 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2023-10-19 09:24:24 +02:00
|
|
|
token := unittest.AssertExistsAndLoadBean(t, &ActionRunnerToken{ID: 3})
|
|
|
|
token.IsActive = true
|
2024-07-30 21:41:27 +02:00
|
|
|
require.NoError(t, UpdateRunnerToken(db.DefaultContext, token))
|
2023-10-19 09:24:24 +02:00
|
|
|
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
|
2024-07-30 21:41:27 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.EqualValues(t, expectedToken, token)
|
2023-10-19 09:24:24 +02:00
|
|
|
}
|