Skip to content

Commit

Permalink
fix: broken test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tokers committed Jan 7, 2021
1 parent bbacaeb commit b495486
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
4 changes: 0 additions & 4 deletions cmd/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

"github.com/api7/ingress-controller/pkg/config"
"github.com/api7/ingress-controller/pkg/log"
"github.com/api7/ingress-controller/pkg/seven/conf"
"github.com/api7/ingress-controller/pkg/types"
)

Expand Down Expand Up @@ -141,9 +140,6 @@ func TestNewIngressCommandEffectiveLog(t *testing.T) {
assert.Equal(t, cfg.Kubernetes.ResyncInterval, types.TimeDuration{24 * time.Hour})
assert.Equal(t, cfg.APISIX.AdminKey, "0x123")
assert.Equal(t, cfg.APISIX.BaseURL, "http://apisixgw.default.cluster.local/apisix")

// Test the conf.BaseUrl is really set.
assert.Equal(t, cfg.APISIX.BaseURL, conf.BaseUrl)
}

func parseLog(t *testing.T, r *bufio.Reader) *fields {
Expand Down
15 changes: 14 additions & 1 deletion pkg/ingress/apisix/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"

apisixhttp "github.com/api7/ingress-controller/pkg/apisix"
"github.com/api7/ingress-controller/pkg/seven/conf"
"github.com/api7/ingress-controller/pkg/seven/utils"
apisix "github.com/api7/ingress-controller/pkg/types/apisix/v1"
)
Expand Down Expand Up @@ -99,6 +101,7 @@ spec:
Status: &status,
Group: &group,
}
setDummyApisixClient(t)
atlsCRD := &ApisixTlsCRD{}
err := yaml.Unmarshal([]byte(atlsStr), atlsCRD)
assert.Nil(t, err, "yaml decode failed")
Expand All @@ -119,6 +122,7 @@ spec:
name: test-atls
namespace: helm
`
setDummyApisixClient(t)
atlsCRD := &ApisixTlsCRD{}
err := yaml.Unmarshal([]byte(atlsStr), atlsCRD)
assert.Nil(t, err, "yaml decode failed")
Expand Down Expand Up @@ -157,3 +161,12 @@ type SecretClientErrorMock struct{}
func (sc *SecretClientErrorMock) FindByName(namespace, name string) (*v1.Secret, error) {
return nil, utils.ErrNotFound
}

func setDummyApisixClient(t *testing.T) {
cli, err := apisixhttp.NewForOptions(&apisixhttp.ClusterOptions{
Name: "",
BaseURL: "http://127.0.0.2:9080/apisix/admin",
})
assert.Nil(t, err)
conf.SetAPISIXClient(cli)
}
13 changes: 12 additions & 1 deletion pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"os"
"sync"

"github.com/api7/ingress-controller/pkg/apisix"

clientSet "github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned"
crdclientset "github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned"
"github.com/gxthrj/apisix-ingress-types/pkg/client/informers/externalversions"
Expand Down Expand Up @@ -58,7 +60,16 @@ func NewController(cfg *config.Config) (*Controller, error) {
podNamespace = "default"
}

conf.SetBaseUrl(cfg.APISIX.BaseURL)
client, err := apisix.NewForOptions(&apisix.ClusterOptions{
Name: "",
AdminKey: cfg.APISIX.AdminKey,
BaseURL: cfg.APISIX.BaseURL,
})
if err != nil {
return nil, err
}
conf.SetAPISIXClient(client)

if err := kube.InitInformer(cfg); err != nil {
return nil, err
}
Expand Down

0 comments on commit b495486

Please sign in to comment.