...

Source file src/github.com/letsencrypt/boulder/observer/probers/crl/crl_conf_test.go

Documentation: github.com/letsencrypt/boulder/observer/probers/crl

     1  package probers
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/letsencrypt/boulder/observer/probers"
     7  	"github.com/letsencrypt/boulder/test"
     8  	"github.com/prometheus/client_golang/prometheus"
     9  	"gopkg.in/yaml.v3"
    10  )
    11  
    12  func TestCRLConf_MakeProber(t *testing.T) {
    13  	conf := CRLConf{}
    14  	colls := conf.Instrument()
    15  	badColl := prometheus.Collector(prometheus.NewGaugeVec(
    16  		prometheus.GaugeOpts{
    17  			Name: "obs_crl_foo",
    18  			Help: "Hmmm, this shouldn't be here...",
    19  		},
    20  		[]string{},
    21  	))
    22  	type fields struct {
    23  		URL string
    24  	}
    25  	tests := []struct {
    26  		name    string
    27  		fields  fields
    28  		colls   map[string]prometheus.Collector
    29  		wantErr bool
    30  	}{
    31  		// valid
    32  		{"valid fqdn", fields{"http://example.com"}, colls, false},
    33  		{"valid fqdn with path", fields{"http://example.com/foo/bar"}, colls, false},
    34  		{"valid hostname", fields{"http://example"}, colls, false},
    35  		// invalid
    36  		{"bad fqdn", fields{":::::"}, colls, true},
    37  		{"missing scheme", fields{"example.com"}, colls, true},
    38  		{
    39  			"unexpected collector",
    40  			fields{"http://example.com"},
    41  			map[string]prometheus.Collector{"obs_crl_foo": badColl},
    42  			true,
    43  		},
    44  		{
    45  			"missing collectors",
    46  			fields{"http://example.com"},
    47  			map[string]prometheus.Collector{},
    48  			true,
    49  		},
    50  	}
    51  	for _, tt := range tests {
    52  		t.Run(tt.name, func(t *testing.T) {
    53  			c := CRLConf{
    54  				URL: tt.fields.URL,
    55  			}
    56  			p, err := c.MakeProber(tt.colls)
    57  			if tt.wantErr {
    58  				test.AssertError(t, err, "CRLConf.MakeProber()")
    59  			} else {
    60  				test.AssertNotError(t, err, "CRLConf.MakeProber()")
    61  
    62  				test.AssertNotNil(t, p, "CRLConf.MakeProber(): nil prober")
    63  				prober := p.(CRLProbe)
    64  				test.AssertNotNil(t, prober.cThisUpdate, "CRLConf.MakeProber(): nil cThisUpdate")
    65  				test.AssertNotNil(t, prober.cNextUpdate, "CRLConf.MakeProber(): nil cNextUpdate")
    66  				test.AssertNotNil(t, prober.cCertCount, "CRLConf.MakeProber(): nil cCertCount")
    67  			}
    68  		})
    69  	}
    70  }
    71  
    72  func TestCRLConf_UnmarshalSettings(t *testing.T) {
    73  	type fields struct {
    74  		url interface{}
    75  	}
    76  	tests := []struct {
    77  		name    string
    78  		fields  fields
    79  		want    probers.Configurer
    80  		wantErr bool
    81  	}{
    82  		{"valid", fields{"google.com"}, CRLConf{"google.com"}, false},
    83  		{"invalid (map)", fields{make(map[string]interface{})}, nil, true},
    84  		{"invalid (list)", fields{make([]string, 0)}, nil, true},
    85  	}
    86  	for _, tt := range tests {
    87  		t.Run(tt.name, func(t *testing.T) {
    88  			settings := probers.Settings{
    89  				"url": tt.fields.url,
    90  			}
    91  			settingsBytes, _ := yaml.Marshal(settings)
    92  			t.Log(string(settingsBytes))
    93  			c := CRLConf{}
    94  			got, err := c.UnmarshalSettings(settingsBytes)
    95  			if tt.wantErr {
    96  				test.AssertError(t, err, "CRLConf.UnmarshalSettings()")
    97  			} else {
    98  				test.AssertNotError(t, err, "CRLConf.UnmarshalSettings()")
    99  			}
   100  			test.AssertDeepEquals(t, got, tt.want)
   101  		})
   102  	}
   103  }
   104  

View as plain text