aboutsummaryrefslogtreecommitdiff
path: root/pkg/components/auth/controller_test.go
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-29 23:33:02 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-29 23:33:02 +0200
commit7a414da9a802d5eeee911b3536790a061e1d7503 (patch)
treee009cd94e72bf908701ca6067833ed14f6860b43 /pkg/components/auth/controller_test.go
parent1ae70dbd9124675d4a510954619b01edd5f1f6c3 (diff)
downloadlens-7a414da9a802d5eeee911b3536790a061e1d7503.tar.gz
lens-7a414da9a802d5eeee911b3536790a061e1d7503.tar.bz2
lens-7a414da9a802d5eeee911b3536790a061e1d7503.zip
ref: Move all controller under the same folder
Move all controller to the same folder and rename them to service. Moving them to the same folder allow an easier setup for testing.
Diffstat (limited to 'pkg/components/auth/controller_test.go')
-rw-r--r--pkg/components/auth/controller_test.go78
1 files changed, 0 insertions, 78 deletions
diff --git a/pkg/components/auth/controller_test.go b/pkg/components/auth/controller_test.go
deleted file mode 100644
index b1ca065..0000000
--- a/pkg/components/auth/controller_test.go
+++ /dev/null
@@ -1,78 +0,0 @@
-//go:build unit
-
-package auth
-
-import (
- "context"
- "testing"
-
- "git.sr.ht/~gabrielgio/img/pkg/database/repository"
- "git.sr.ht/~gabrielgio/img/pkg/ext"
- "git.sr.ht/~gabrielgio/img/pkg/testkit"
-)
-
-type (
- scene struct {
- ctx context.Context
- authRepository repository.AuthRepository
- userRepository repository.UserRepository
- controller *Controller
- }
-)
-
-var (
- key = []byte("6368616e676520746869732070617373")
-)
-
-func setUp() *scene {
- userRepository := NewUserRepository()
- return &scene{
- ctx: context.Background(),
- authRepository: userRepository,
- userRepository: userRepository,
- controller: NewController(userRepository, userRepository, key),
- }
-}
-
-func TestInitialRegisterAndLogin(t *testing.T) {
- testCases := []struct {
- name string
- username string
- password []byte
- }{
- {
- name: "Normal register",
- username: "username",
- password: []byte("this is an password"),
- },
- }
-
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- scene := setUp()
-
- err := scene.controller.InitialRegister(scene.ctx, []byte(tc.username), tc.password, []byte("/"))
- testkit.TestFatalError(t, "Register", err)
-
- users, err := scene.userRepository.List(scene.ctx)
- userID := users[0].ID
-
- user, err := scene.userRepository.Get(scene.ctx, userID)
- testkit.TestFatalError(t, "Get", err)
- testkit.TestValue(t, "Register", tc.username, user.Username)
-
- auth, err := scene.controller.Login(scene.ctx, []byte(tc.username), tc.password)
- testkit.TestFatalError(t, "Login", err)
-
- token, err := ext.ReadToken(auth, key)
- testkit.TestFatalError(t, "Login", err)
-
- testkit.TestValue(t, "Login", tc.username, token.Username)
- testkit.TestValue(t, "Login", userID, token.UserID)
- })
- }
-}
-
-func remove[T any](slice []T, s int) []T {
- return append(slice[:s], slice[s+1:]...)
-}