Esempio n. 1
0
func TestNoSuchProcess(t *testing.T) {
	s := `<config>
                       <hostgroup id="foo">
                               <cluster id="foo.live">
                                       <host id="foo001">
                                               <process id="foo.process"/>
                                       </host>
                               </cluster>
                       </hostgroup>
                       <querygroup id="q" targets="foo">
                               <query id="x" on="X:name=*" attributes="K,L"/>
                       </querygroup>
               </config>`
	cfg, _ := config.Decode(strings.NewReader(s))
	h := &handler{
		config: cfg,
	}
	view, _ := h.View(&Key{
		Host:    "foo002",
		Process: "foo",
	})
	// Make sure we are not matching process names with any other
	// targets (in this case hostgroup foo)
	if len(view.Objects) > 0 {
		t.Errorf("unexpected result\ngot:  %+v\nwant: []", view.Objects[0])
	}
}
Esempio n. 2
0
func TestUpdate(t *testing.T) {
	for i, tt := range testUpdate {
		out, err := config.Decode(strings.NewReader(tt.in))
		if err != nil {
			if tt.err == "" {
				t.Errorf("#%d. unexpected error: %v", i, err)
				continue
			}
			if !strings.Contains(err.Error(), tt.err) {
				t.Errorf("#%d. invalid error, got: %s, want: %s", i, err, tt.err)
				continue
			}
			continue
		}
		if tt.err != "" {
			t.Errorf("#%d. unexpected success, want error: %v", i, tt.err)
			continue
		}
		if err := Update(out); err != nil {
			t.Fatalf("Update failed after Decode")
		}
		// Omit uninteresting data.
		out.Filter = nil
		out.Network = nil
		out.Hosts.NS = nil
		for _, elem := range out.Extra {
			elem.Name = ""
			elem.Raw = nil
		}
		for _, host := range out.Hosts.All {
			for _, elem := range host.Extra {
				elem.Name = ""
				elem.Raw = nil
			}
		}
		if len(out.Hosts.All) == 0 {
			out.Hosts = nil
		}
		// Test what remained.
		if !reflect.DeepEqual(out, tt.out) {
			t.Errorf("#%d. invalid output\ngot:  %+v\nwant: %+v", i, out, tt.out)
		}
	}
}