github.com/cosmos/cosmos-sdk@v0.50.10/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]interface{}{"a": nil, "b": nil}, 21 } 22 tcs := []struct { 23 name string 24 positive bool 25 modules []string 26 pass func(string) bool 27 }{ 28 {"less modules", false, []string{"a"}, nil}, 29 {"same modules", true, []string{"a", "b"}, nil}, 30 {"more modules", true, []string{"a", "b", "c"}, nil}, 31 {"pass module b", true, []string{"a"}, func(moduleName string) bool { return moduleName == "b" }}, 32 } 33 34 for _, tc := range tcs { 35 if tc.positive { 36 m.assertNoForgottenModules("x", tc.modules, tc.pass) 37 } else { 38 s.Panics(func() { m.assertNoForgottenModules("x", tc.modules, tc.pass) }) 39 } 40 } 41 } 42 43 func (s *TestSuite) TestModuleNames() { 44 m := Manager{ 45 Modules: map[string]interface{}{"a": nil, "b": nil}, 46 } 47 ms := m.ModuleNames() 48 sort.Strings(ms) 49 s.Require().Equal([]string{"a", "b"}, ms) 50 } 51 52 func (s *TestSuite) TestDefaultMigrationsOrder() { 53 require := s.Require() 54 require.Equal( 55 []string{"auth2", "d", "z", "auth"}, 56 DefaultMigrationsOrder([]string{"d", "auth", "auth2", "z"}), "alphabetical, but auth should be last") 57 require.Equal( 58 []string{"auth2", "d", "z"}, 59 DefaultMigrationsOrder([]string{"d", "auth2", "z"}), "alphabetical") 60 }