func TestCommandVersionInitConfigNoDefaultNoFlag(t *testing.T) {
	// INIT
	rootConfig := newConfiguration()
	rootDefaultPointers := newDefaultPointersConfiguration()
	versionConfig := &VersionConfig{"0.1"}

	args := []string{
		"version", // call Command
	}

	// root command
	rootCmd := &Command{
		Name: "flaegtest",
		Description: `flaegtest is a test program made to test flaeg library.
Complete documentation is available at https://github.com/containous/flaeg`,
		Config:                rootConfig,
		DefaultPointersConfig: rootDefaultPointers,
		Run: func() error {
			fmt.Printf("Run with config :\n%+v\n", rootConfig)
			//CHECK
			check := newConfiguration()
			check.LogLevel = "INFO"
			check.Db = newDefaultPointersConfiguration().Db
			check.Owner.Name = newDefaultPointersConfiguration().Owner.Name
			check.Owner.DateOfBirth, _ = time.Parse(time.RFC3339, "2016-04-20T17:39:00Z")

			if !reflect.DeepEqual(rootConfig, check) {
				msg := fmt.Sprintf("\nexpected \t%+v \ngot \t\t%+v\n", check, rootConfig)
				return errors.New(msg)
			}
			return nil
		},
	}

	// version command
	VersionConfig := &Command{
		Name:                  "version",
		Description:           `Print version`,
		Config:                versionConfig,
		DefaultPointersConfig: versionConfig,
		Run: func() error {
			//CHECK
			if versionConfig.Version != "0.1" {
				return fmt.Errorf("expected 0.1 got %s", versionConfig.Version)
			}
			return nil
		},
	}

	// TEST
	// init flaeg
	flaeg := New(rootCmd, args)
	// add custom parser to flaeg
	flaeg.AddParser(reflect.TypeOf([]ServerInfo{}), &sliceServerValue{})
	// add command Version
	flaeg.AddCommand(VersionConfig)

	// run test
	if err := flaeg.Run(); err != nil {
		t.Fatal(err)
	}
}
// Test Commands feature with root and version commands
Test Commands feature with root and version commands
// Test Commands feature with root and version commands
func TestCommandVersionInitConfigNoDefaultNoFlag(t *testing.T) {
	rootConfig := newConfiguration()
	rootDefaultPointers := newDefaultPointersConfiguration()
	versionConfig := &VersionConfig{"0.1"}
	args := []string{
		"version", 
	}
	rootCmd := &Command{
		Name: "flaegtest",
		Description: `flaegtest is a test program made to test flaeg library.
Complete documentation is available at https://github.com/containous/flaeg`,
		Config:                rootConfig,
		DefaultPointersConfig: rootDefaultPointers,
		Run: func() error {
			fmt.Printf("Run with config :\n%+v\n", rootConfig)
			check := newConfiguration()
			check.LogLevel = "INFO"
			check.Db = newDefaultPointersConfiguration().Db
			check.Owner.Name = newDefaultPointersConfiguration().Owner.Name
			check.Owner.DateOfBirth, _ = time.Parse(time.RFC3339, "2016-04-20T17:39:00Z")
			if !reflect.DeepEqual(rootConfig, check) {
				msg := fmt.Sprintf("\nexpected \t%+v \ngot \t\t%+v\n", check, rootConfig)
				return errors.New(msg)
			}
			return nil
		},
	}
	VersionConfig := &Command{
		Name:                  "version",
		Description:           `Print version`,
		Config:                versionConfig,
		DefaultPointersConfig: versionConfig,
		Run: func() error {
			if versionConfig.Version != "0.1" {
				return fmt.Errorf("expected 0.1 got %s", versionConfig.Version)
			}
			return nil
		},
	}
	flaeg := New(rootCmd, args)
	flaeg.AddParser(reflect.TypeOf([]ServerInfo{}), &sliceServerValue{})
	flaeg.AddCommand(VersionConfig)
	if err := flaeg.Run(); err != nil {
		t.Fatal(err)
	}
}
func TestCommandVersionInitConfigNoDefaultNoFlag ( t * testing . T ) { rootConfig := newConfiguration ( ) rootDefaultPointers := newDefaultPointersConfiguration ( ) versionConfig := & VersionConfig { " " } args := [ ] string { " " , } rootCmd := & Command { Name : " " , Description : `flaegtest is a test program made to test flaeg library.
Complete documentation is available at https://github.com/containous/flaeg` , Config : rootConfig , DefaultPointersConfig : rootDefaultPointers , Run : func ( ) error { fmt . Printf ( " \n \n " , rootConfig ) check := newConfiguration ( ) check . LogLevel = " " check . Db = newDefaultPointersConfiguration ( ) . Db check . Owner . Name = newDefaultPointersConfiguration ( ) . Owner . Name check . Owner . DateOfBirth , _ = time . Parse ( time . RFC3339 , " " ) if ! reflect . DeepEqual ( rootConfig , check ) { msg := fmt . Sprintf ( " \n \t \n \t \t \n " , check , rootConfig ) return errors . New ( msg ) } return nil } , } VersionConfig := & Command { Name : " " , Description : `Print version` , Config : versionConfig , DefaultPointersConfig : versionConfig , Run : func ( ) error { if versionConfig . Version != " " { return fmt . Errorf ( " " , versionConfig . Version ) } return nil } , } flaeg := New ( rootCmd , args ) flaeg . AddParser ( reflect . TypeOf ( [ ] ServerInfo { } ) , & sliceServerValue { } ) flaeg . AddCommand ( VersionConfig ) if err := flaeg . Run ( ) ; err != nil { t . Fatal ( err ) } }
Test Commands feature with root and version commands
Test Commands feature with root and version commands
// INIT // call Command // root command //CHECK // version command //CHECK // TEST // init flaeg // add custom parser to flaeg // add command Version // run test