diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c81f8441..6b90cfa0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: - name: Set up environment run: | cp panel-example.conf .env - echo "DB_FILE=database/panel.db" >> .env + echo "DB_FILE=$(pwd)/database/panel.db" >> .env go run . artisan key:generate go run . artisan migrate - name: Run tests diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4088aed8..993ab70a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -44,7 +44,7 @@ unit_test: - apt-get update - apt-get install -y curl jq - cp panel-example.conf .env - - echo "DB_FILE=database/panel.db" >> .env + - echo "DB_FILE=$(pwd)/database/panel.db" >> .env - go run . artisan key:generate - go run . artisan migrate - go test -v -coverprofile=coverage.txt -covermode=atomic ./... diff --git a/app/services/setting_test.go b/app/services/setting_test.go deleted file mode 100644 index e35a0872..00000000 --- a/app/services/setting_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package services - -import ( - "testing" - - "github.com/stretchr/testify/suite" -) - -type SettingTestSuite struct { - suite.Suite - setting Setting -} - -func TestSettingTestSuite(t *testing.T) { - suite.Run(t, &SettingTestSuite{ - setting: NewSettingImpl(), - }) -} - -func (s *SettingTestSuite) SetupTest() { - -} - -func (s *SettingTestSuite) TestGet() { - /*mockOrm, mockDb, _, _ := mock.Orm() - mockOrm.On("Query").Return(mockDb).Twice() - mockDb.On("Where", "key", "test").Return(mockDb).Twice() - mockDb.On("FirstOrFail", &models.Setting{}).Return(nil).Twice() - a := s.setting.Get("test") - b := s.setting.Get("test", "test") - s.Equal("", a) - s.Equal("test", b)*/ -} - -func (s *SettingTestSuite) TestSet() { - /*mockOrm, mockDb, _, _ := mock.Orm() - mockOrm.On("Query").Return(mockDb).Once() - mockDb.On("UpdateOrCreate", &models.Setting{}, models.Setting{Key: "test"}, models.Setting{Value: "test"}).Return(nil).Once() - err := s.setting.Set("test", "test") - s.Nil(err)*/ -} diff --git a/tests/feature/example_test.go b/tests/feature/example_test.go deleted file mode 100644 index 3a93c1ef..00000000 --- a/tests/feature/example_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package feature - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - "panel/tests" -) - -type ExampleTestSuite struct { - suite.Suite - tests.TestCase -} - -func TestExampleTestSuite(t *testing.T) { - suite.Run(t, new(ExampleTestSuite)) -} - -// SetupTest will run before each test in the suite. -func (s *ExampleTestSuite) SetupTest() { -} - -// TearDownTest will run after each test in the suite. -func (s *ExampleTestSuite) TearDownTest() { -} - -func (s *ExampleTestSuite) TestIndex() { - s.True(true) -} diff --git a/tests/setting/setting_test.go b/tests/setting/setting_test.go new file mode 100644 index 00000000..2c21bfa0 --- /dev/null +++ b/tests/setting/setting_test.go @@ -0,0 +1,38 @@ +package setting + +import ( + "testing" + + "github.com/stretchr/testify/suite" + + "panel/app/services" + "panel/tests" +) + +type SettingTestSuite struct { + suite.Suite + tests.TestCase + setting services.Setting +} + +func TestSettingTestSuite(t *testing.T) { + suite.Run(t, &SettingTestSuite{ + setting: services.NewSettingImpl(), + }) +} + +func (s *SettingTestSuite) SetupTest() { + +} + +func (s *SettingTestSuite) TestGet() { + a := s.setting.Get("test") + b := s.setting.Get("test", "test") + s.Equal("", a) + s.Equal("test", b) +} + +func (s *SettingTestSuite) TestSet() { + err := s.setting.Set("test", "test") + s.Nil(err) +} diff --git a/app/services/user_test.go b/tests/user/user_test.go similarity index 54% rename from app/services/user_test.go rename to tests/user/user_test.go index b0876cc9..08501465 100644 --- a/app/services/user_test.go +++ b/tests/user/user_test.go @@ -1,19 +1,23 @@ -package services +package user import ( "testing" "github.com/stretchr/testify/suite" + + "panel/app/services" + "panel/tests" ) type UserTestSuite struct { suite.Suite - user User + tests.TestCase + user services.User } func TestUserTestSuite(t *testing.T) { suite.Run(t, &UserTestSuite{ - user: NewUserImpl(), + user: services.NewUserImpl(), }) } @@ -22,13 +26,7 @@ func (s *UserTestSuite) SetupTest() { } func (s *UserTestSuite) TestCreate() { - /*mockOrm, mockDb, _, _ := mock.Orm() - mockOrm.On("Query").Return(mockDb).Once() - mockDb.On("Create", &models.User{ - Username: "haozi", - Password: "123456", - }).Return(nil).Once() user, err := s.user.Create("haozi", "123456") s.Nil(err) - s.Equal("haozi", user.Username)*/ + s.Equal("haozi", user.Username) }