Repository: beatlabs/patron
Pull request #203 (2020-05-01 07:55:46)

Append components in service builder
## Which problem is this PR solving?

Resolves https://github.com/beatlabs/patron/issues/202

## Short description of the changes

Append components in service builder instead of replacing


codecov[bot]: # [Codecov](https://codecov.io/gh/beatlabs/patron/pull/203?src=pr&el=h1) Report
> Merging [#203](https://codecov.io/gh/beatlabs/patron/pull/203?src=pr&el=desc) into [master](https://codecov.io/gh/beatlabs/patron/commit/375084b0e6deed91f444975c248bcbefaad2c2e0&el=desc) will **decrease** coverage by `0.04%`.
> The diff coverage is `86.20%`.

[![Impacted file tree graph](https://codecov.io/gh/beatlabs/patron/pull/203/graphs/tree.svg?width=650&height=150&src=pr&token=sxY15rXW1X)](https://codecov.io/gh/beatlabs/patron/pull/203?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #203      +/-   ##
==========================================
- Coverage   84.48%   84.43%   -0.05%     
==========================================
  Files          52       52              
  Lines        3074     3097      +23     
==========================================
+ Hits         2597     2615      +18     
- Misses        398      401       +3     
- Partials       79       81       +2     
```


| [Impacted Files](https://codecov.io/gh/beatlabs/patron/pull/203?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [client/amqp/amqp.go](https://codecov.io/gh/beatlabs/patron/pull/203/diff?src=pr&el=tree#diff-Y2xpZW50L2FtcXAvYW1xcC5nbw==) | `40.98% <ø> (ø)` | |
| [client/amqp/option.go](https://codecov.io/gh/beatlabs/patron/pull/203/diff?src=pr&el=tree#diff-Y2xpZW50L2FtcXAvb3B0aW9uLmdv) | `66.66% <ø> (ø)` | |
| [client/amqp/user.pb.go](https://codecov.io/gh/beatlabs/patron/pull/203/diff?src=pr&el=tree#diff-Y2xpZW50L2FtcXAvdXNlci5wYi5nbw==) | `26.92% <ø> (ø)` | |
| [client/http/option.go](https://codecov.io/gh/beatlabs/patron/pull/203/diff?src=pr&el=tree#diff-Y2xpZW50L2h0dHAvb3B0aW9uLmdv) | `100.00% <ø> (ø)` | |
| [client/redis/redis.go](https://codecov.io/gh/beatlabs/patron/pull/203/diff?src=pr&el=tree#diff-Y2xpZW50L3JlZGlzL3JlZGlzLmdv) | `44.44% <ø> (ø)` | |
| [client/sns/message.go](https://codecov.io/gh/beatlabs/patron/pull/203/diff?src=pr&el=tree#diff-Y2xpZW50L3Nucy9tZXNzYWdlLmdv) | `97.53% <ø> (ø)` | |
| [client/sns/publisher.go](https://codecov.io/gh/beatlabs/patron/pull/203/diff?src=pr&el=tree#diff-Y2xpZW50L3Nucy9wdWJsaXNoZXIuZ28=) | `93.33% <ø> (ø)` | |
| [client/sql/sql.go](https://codecov.io/gh/beatlabs/patron/pull/203/diff?src=pr&el=tree#diff-Y2xpZW50L3NxbC9zcWwuZ28=) | `86.25% <ø> (ø)` | |
| [client/sqs/message.go](https://codecov.io/gh/beatlabs/patron/pull/203/diff?src=pr&el=tree#diff-Y2xpZW50L3Nxcy9tZXNzYWdlLmdv) | `92.50% <ø> (ø)` | |
| [client/sqs/publisher.go](https://codecov.io/gh/beatlabs/patron/pull/203/diff?src=pr&el=tree#diff-Y2xpZW50L3Nxcy9wdWJsaXNoZXIuZ28=) | `93.33% <ø> (ø)` | |
| ... and [62 more](https://codecov.io/gh/beatlabs/patron/pull/203/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/beatlabs/patron/pull/203?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/beatlabs/patron/pull/203?src=pr&el=footer). Last update [41126d8...7d449cd](https://codecov.io/gh/beatlabs/patron/pull/203?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/service.go b/service.go
index a1cf9b11d..61d841614 100644
--- a/service.go
+++ b/service.go
@@ -277,7 +277,7 @@ func (b *Builder) WithComponents(cc ...Component) *Builder {
 		b.errors = append(b.errors, errors.New("provided components slice was empty"))
 	} else {
 		log.Info("setting components")
-		b.cps = cc
+		b.cps = append(b.cps, cc...)
 	}
 
 	return b


Test patch:
diff --git a/service_test.go b/service_test.go
index 8e47a9c23..234fcefeb 100644
--- a/service_test.go
+++ b/service_test.go
@@ -173,6 +173,11 @@ func TestServer_SetupTracing(t *testing.T) {
 	}
 }
 
+func TestBuilder_WithComponentsTwice(t *testing.T) {
+	bld := New("test", "").WithComponents(&testComponent{}).WithComponents(&testComponent{})
+	assert.Len(t, bld.cps, 2)
+}
+
 func TestBuild_FailingConditions(t *testing.T) {
 	tests := []struct {
 		name         string