示例#1
0
func TestConfigCompile(t *testing.T) {
	for _, test := range testConfigCompile {
		nodes, err := test.config.compile()

		if err == nil && test.error == "" {

		} else if err != nil && test.error == "" {
			t.Errorf("unxpected config.compile error: %v\n", err)
			continue
		} else if err == nil && test.error != "" {
			t.Errorf("expected config.compile error: %v\n", test.error)
			continue
		} else if err.Error() != test.error {
			t.Errorf("incorrect config.compile error: %v\n\tshould be: %v\n", err, test.error)
			continue
		}

		prettyConfig := pretty.Config{
			// omit Meta node
			IncludeUnexported: false,
		}

		if diff := prettyConfig.Compare(test.nodes, nodes); diff != "" {
			t.Errorf("incorrect nodes:\n%s", diff)
		}
	}
}
示例#2
0
func main() {
	Pretty := pretty.Config{
		PrintStringers: true,
	}
	conn, err := admin.Connect(nil)
	if err != nil {
		fmt.Println(err)
		return
	}
	results, err := conn.InterfaceController_peerStats()
	if err != nil {
		fmt.Println(err)
		return
	}
	Pretty.Print(results)
}
示例#3
0
func TestReaderUpdate(t *testing.T) {
	var reader Reader

	reader.options.FilterRoutes = "test-"

	if err := reader.init(); err != nil {
		panic(err)
	}

	// setup
	var syncGroup sync.WaitGroup

	for name, testSource := range testReaderSources {
		testSource.syncGroup = &syncGroup

		if err := reader.open(testSource); err != nil {
			t.Fatalf("reader.open %v: %v\n", name, err)
		}
	}

	// ensure the test terminates
	go func() {
		syncGroup.Wait()
		reader.stop()
	}()

	// read
	var readerConfig Config

	for config := range reader.Listen() {
		t.Logf("reader.Listen: tick\n")

		// touch it
		_ = pretty.Sprint(config)

		readerConfig = config
	}

	prettyConfig := pretty.Config{
		// omit Meta node
		IncludeUnexported: false,
	}

	if diff := prettyConfig.Compare(testReaderConfig, readerConfig); diff != "" {
		t.Errorf("reader config:\n%s", diff)
	}
}
示例#4
0
func TestConfigMerge(t *testing.T) {
	for _, test := range testConfigMerge {
		var config Config

		for _, mergeConfig := range test.mergeConfigs {
			config.merge(mergeConfig)
		}

		prettyConfig := pretty.Config{
			// omit Meta node
			IncludeUnexported: false,
		}

		if diff := prettyConfig.Compare(test.config, config); diff != "" {
			t.Errorf("incorrect config:\n%s", diff)
		}
	}
}
示例#5
0
func TestConfigUpdate(t *testing.T) {
	for _, test := range testConfigUpdate {
		var config Config
		var err error

		config.merge(test.initConfig)

		for _, testNode := range test.nodes {
			if err = config.update(testNode); err != nil {
				break
			}
		}

		if err == nil && test.error == "" {

		} else if err != nil && test.error == "" {
			t.Errorf("unxpected config.update error: %v\n", err)
			continue
		} else if err == nil && test.error != "" {
			t.Errorf("expected config.update error: %v\n", test.error)
			continue
		} else if err.Error() != test.error {
			t.Errorf("incorrect config.update error: %v\n\tshould be: %v\n", err, test.error)
			continue
		}

		prettyConfig := pretty.Config{
			// omit Meta node
			IncludeUnexported: false,
		}

		if diff := prettyConfig.Compare(config, test.config); diff != "" {
			t.Errorf("incorrect config:\n%s", diff)
		}
	}
}
示例#6
0
func TestReaderFiles(t *testing.T) {
	var readerOptions = ReaderOptions{
		SourceURLs: []string{
			"file://./test-files",
		},
	}

	reader, err := readerOptions.Reader()
	if err != nil {
		t.Fatalf("Reader: %v", err)
	}

	config := reader.Get()

	// diff
	prettyConfig := pretty.Config{
		// omit Meta node
		IncludeUnexported: false,
	}

	if diff := prettyConfig.Compare(testFilesConfig, config); diff != "" {
		t.Errorf("reader config:\n%s", diff)
	}
}