github.com/Finschia/finschia-sdk@v0.48.1/types/module/module_int_test.go (about) 1 package module 2 3 import ( 4 "sort" 5 "testing" 6 7 "github.com/stretchr/testify/suite" 8 ) 9 10 func TestModuleIntSuite(t *testing.T) { 11 suite.Run(t, new(TestSuite)) 12 } 13 14 type TestSuite struct { 15 suite.Suite 16 } 17 18 func (s TestSuite) TestAssertNoForgottenModules() { 19 m := Manager{ 20 Modules: map[string]AppModule{"a": nil, "b": nil}, 21 } 22 tcs := []struct { 23 name string 24 positive bool 25 modules []string 26 }{ 27 {"same modules", true, []string{"a", "b"}}, 28 {"more modules", true, []string{"a", "b", "c"}}, 29 } 30 31 for _, tc := range tcs { 32 if tc.positive { 33 m.assertNoForgottenModules("x", tc.modules) 34 } else { 35 s.Panics(func() { m.assertNoForgottenModules("x", tc.modules) }) 36 } 37 } 38 } 39 40 func (s TestSuite) TestModuleNames() { 41 m := Manager{ 42 Modules: map[string]AppModule{"a": nil, "b": nil}, 43 } 44 ms := m.ModuleNames() 45 sort.Strings(ms) 46 s.Require().Equal([]string{"a", "b"}, ms) 47 } 48 49 func (s TestSuite) TestDefaultMigrationsOrder() { 50 require := s.Require() 51 require.Equal( 52 []string{"auth2", "d", "z", "auth"}, 53 DefaultMigrationsOrder([]string{"d", "auth", "auth2", "z"}), "alphabetical, but auth should be last") 54 require.Equal( 55 []string{"auth2", "d", "z"}, 56 DefaultMigrationsOrder([]string{"d", "auth2", "z"}), "alphabetical") 57 }