(t *testing.T)
| 42 | } |
| 43 | |
| 44 | func TestConfigChanged(t *testing.T) { |
| 45 | filePath := "config.yaml" |
| 46 | f, err := os.Create(filePath) |
| 47 | assert.NoError(t, err) |
| 48 | defer func() { |
| 49 | _ = f.Close() |
| 50 | _ = os.Remove(filePath) |
| 51 | }() |
| 52 | c := &Root{ |
| 53 | Forwarders: []Forwarder{ |
| 54 | { |
| 55 | URL: "test.daltoniam.com", |
| 56 | Listener: "127.0.0.1:8080", |
| 57 | }, |
| 58 | }, |
| 59 | } |
| 60 | configRead := func(configPath string, log *zerolog.Logger) (Root, error) { |
| 61 | return *c, nil |
| 62 | } |
| 63 | wait := make(chan struct{}) |
| 64 | w := &mockFileWatcher{path: filePath, ready: wait} |
| 65 | |
| 66 | log := zerolog.Nop() |
| 67 | |
| 68 | service, err := NewFileManager(w, filePath, &log) |
| 69 | service.ReadConfig = configRead |
| 70 | assert.NoError(t, err) |
| 71 | |
| 72 | n := &mockNotifier{} |
| 73 | go service.Start(n) |
| 74 | |
| 75 | <-wait |
| 76 | c.Forwarders = append(c.Forwarders, Forwarder{URL: "add.daltoniam.com", Listener: "127.0.0.1:8081"}) |
| 77 | w.TriggerChange() |
| 78 | |
| 79 | service.Shutdown() |
| 80 | |
| 81 | assert.Len(t, n.configs, 2, "did not get 2 config updates as expected") |
| 82 | assert.Len(t, n.configs[0].Forwarders, 1, "not the amount of forwarders expected") |
| 83 | assert.Len(t, n.configs[1].Forwarders, 2, "not the amount of forwarders expected") |
| 84 | |
| 85 | assert.Equal(t, n.configs[0].Forwarders[0].Hash(), c.Forwarders[0].Hash(), "forwarder hashes don't match") |
| 86 | assert.Equal(t, n.configs[1].Forwarders[0].Hash(), c.Forwarders[0].Hash(), "forwarder hashes don't match") |
| 87 | assert.Equal(t, n.configs[1].Forwarders[1].Hash(), c.Forwarders[1].Hash(), "forwarder hashes don't match") |
| 88 | } |
nothing calls this directly
no test coverage detected