Skip to content
Snippets Groups Projects
Select Git revision
  • 171738e70bd421cf2d611f5be5f0c73e0b9b460e
  • master default protected
  • lintian-fixes
3 results

inputs_test.go

Blame
  • Forked from ai3 / thirdparty / rsyslog-exporter
    Source project has a limited visibility.
    inputs_test.go 1.19 KiB
    package main
    
    import "testing"
    
    var (
    	inputLog = []byte(`{"name":"test_input", "origin":"imuxsock", "submitted":1000}`)
    )
    
    func TestgetInput(t *testing.T) {
    	logType := getStatType(inputLog)
    	if logType != rsyslogInput {
    		t.Errorf("detected pstat type should be %d but is %d", rsyslogInput, logType)
    	}
    
    	pstat, err := newInputFromJSON([]byte(inputLog))
    	if err != nil {
    		t.Fatalf("expected parsing input stat not to fail, got: %v", err)
    	}
    
    	if want, got := "test_input", pstat.Name; want != got {
    		t.Errorf("want '%s', got '%s'", want, got)
    	}
    
    	if want, got := int64(1000), pstat.Submitted; want != got {
    		t.Errorf("want '%d', got '%d'", want, got)
    	}
    }
    
    func TestInputtoPoints(t *testing.T) {
    	pstat, err := newInputFromJSON([]byte(inputLog))
    	if err != nil {
    		t.Fatalf("expected parsing input stat not to fail, got: %v", err)
    	}
    
    	points := pstat.toPoints()
    
    	point := points[0]
    	if want, got := "input_submitted", point.Name; want != got {
    		t.Errorf("want '%s', got '%s'", want, got)
    	}
    
    	if want, got := int64(1000), point.Value; want != got {
    		t.Errorf("want '%d', got '%d'", want, got)
    	}
    
    	if want, got := "test_input", point.LabelValue; want != got {
    		t.Errorf("wanted '%s', got '%s'", want, got)
    	}
    }