From 6afaf06215a1da95b92a1594adc87a61f1a0a8d4 Mon Sep 17 00:00:00 2001 From: Harry Date: Thu, 8 Aug 2019 22:57:48 -0700 Subject: [PATCH] feat(upstream) add Algorithm field to Upstream struct Kong 1.3 adds an `algorithm` field to the Upstream entity. From #9 --- kong/upstream.go | 1 + kong/upstream_service_test.go | 22 ++++++++++++++++++++++ kong/zz_generated.deepcopy.go | 5 +++++ 3 files changed, 28 insertions(+) diff --git a/kong/upstream.go b/kong/upstream.go index d368e5eab..d6dc5ea04 100644 --- a/kong/upstream.go +++ b/kong/upstream.go @@ -56,6 +56,7 @@ type Healthcheck struct { type Upstream struct { ID *string `json:"id,omitempty" yaml:"id,omitempty"` Name *string `json:"name,omitempty" yaml:"name,omitempty"` + Algorithm *string `json:"algorithm,omitempty" yaml:"algorithm,omitempty"` Slots *int `json:"slots,omitempty" yaml:"slots,omitempty"` Healthchecks *Healthcheck `json:"healthchecks,omitempty" yaml:"healthchecks,omitempty"` CreatedAt *int64 `json:"created_at,omitempty" yaml:"created_at,omitempty"` diff --git a/kong/upstream_service_test.go b/kong/upstream_service_test.go index dc0815864..7fc132c02 100644 --- a/kong/upstream_service_test.go +++ b/kong/upstream_service_test.go @@ -124,6 +124,28 @@ func TestUpstreamWithPassiveUnHealthyInterval(T *testing.T) { assert.Nil(createdUpstream) } +func TestUpstreamWithAlgorithm(T *testing.T) { + runWhenKong(T, ">=1.3.0") + assert := assert.New(T) + + client, err := NewClient(nil, nil) + assert.Nil(err) + assert.NotNil(client) + + upstream := &Upstream{ + Name: String("upstream1"), + Algorithm: String("least-connections"), + } + + createdUpstream, err := client.Upstreams.Create(defaultCtx, upstream) + assert.Nil(err) + assert.NotNil(createdUpstream) + assert.Equal("least-connections", *createdUpstream.Algorithm) + + err = client.Upstreams.Delete(defaultCtx, createdUpstream.ID) + assert.Nil(err) +} + func TestUpstreamListEndpoint(T *testing.T) { assert := assert.New(T) diff --git a/kong/zz_generated.deepcopy.go b/kong/zz_generated.deepcopy.go index 8f65ddf9c..97712c6b6 100644 --- a/kong/zz_generated.deepcopy.go +++ b/kong/zz_generated.deepcopy.go @@ -820,6 +820,11 @@ func (in *Upstream) DeepCopyInto(out *Upstream) { *out = new(string) **out = **in } + if in.Algorithm != nil { + in, out := &in.Algorithm, &out.Algorithm + *out = new(string) + **out = **in + } if in.Slots != nil { in, out := &in.Slots, &out.Slots *out = new(int)