From 7a414da9a802d5eeee911b3536790a061e1d7503 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Thu, 29 Jun 2023 23:33:02 +0200 Subject: 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. --- pkg/components/auth/controller_test.go | 78 ---------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 pkg/components/auth/controller_test.go (limited to 'pkg/components/auth/controller_test.go') 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:]...) -} -- cgit v1.2.3