-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from chatwork/fix_test
Add ingress check , cert-manager test
- Loading branch information
Showing
7 changed files
with
237 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package certmanager | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
cmapiv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1" | ||
"github.com/chatwork/kibertas/util" | ||
"github.com/chatwork/kibertas/util/notify" | ||
"github.com/sirupsen/logrus" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/chatwork/kibertas/cmd" | ||
"github.com/chatwork/kibertas/config" | ||
) | ||
|
||
func TestNewCertManager(t *testing.T) { | ||
t.Parallel() | ||
logger := func() *logrus.Entry { | ||
return logrus.NewEntry(logrus.New()) | ||
} | ||
chatwork := ¬ify.Chatwork{} | ||
ingress, err := NewCertManager(true, logger, chatwork) | ||
if err != nil { | ||
t.Fatalf("NewCertManager: %s", err) | ||
} | ||
|
||
if ingress == nil { | ||
t.Error("Expected certManager instance, got nil") | ||
} | ||
} | ||
|
||
func TestCheck(t *testing.T) { | ||
t.Parallel() | ||
logger := func() *logrus.Entry { | ||
return logrus.NewEntry(logrus.New()) | ||
} | ||
|
||
k8sclientset, err := config.NewK8sClientset() | ||
if err != nil { | ||
t.Fatalf("NewK8sClientset: %s", err) | ||
} | ||
|
||
scheme := runtime.NewScheme() | ||
_ = cmapiv1.AddToScheme(scheme) | ||
|
||
k8sclient, err := config.NewK8sClient(client.Options{Scheme: scheme}) | ||
if err != nil { | ||
t.Fatalf("NewK8sClient: %s", err) | ||
} | ||
|
||
chatwork := ¬ify.Chatwork{ApiToken: "token", RoomId: "test", Logger: logger} | ||
|
||
now := time.Now() | ||
namespace := fmt.Sprintf("cert-manager-test-%d%02d%02d-%s", now.Year(), now.Month(), now.Day(), util.GenerateRandomString(5)) | ||
cm := &CertManager{ | ||
Checker: cmd.NewChecker(namespace, k8sclientset, true, logger, chatwork), | ||
CertName: "sample", | ||
Client: k8sclient, | ||
} | ||
|
||
err = cm.Check() | ||
if err != nil { | ||
t.Fatalf("Expected No Error, but got error: %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package fluent | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/chatwork/kibertas/util/notify" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func TestNewFluent(t *testing.T) { | ||
logger := func() *logrus.Entry { | ||
return logrus.NewEntry(logrus.New()) | ||
} | ||
chatwork := ¬ify.Chatwork{} | ||
fluent, err := NewFluent(true, logger, chatwork) | ||
if err != nil { | ||
t.Fatalf("NewFluent: %s", err) | ||
} | ||
|
||
if fluent == nil { | ||
t.Error("Expected fluent instance, got nil") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package ingress | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/chatwork/kibertas/cmd" | ||
"github.com/chatwork/kibertas/config" | ||
"github.com/chatwork/kibertas/util" | ||
"github.com/chatwork/kibertas/util/notify" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func TestNewIngress(t *testing.T) { | ||
t.Parallel() | ||
logger := func() *logrus.Entry { | ||
return logrus.NewEntry(logrus.New()) | ||
} | ||
chatwork := ¬ify.Chatwork{} | ||
ingress, err := NewIngress(true, logger, chatwork, false, "alb") | ||
if err != nil { | ||
t.Fatalf("NewIngress: %s", err) | ||
} | ||
|
||
if ingress == nil { | ||
t.Error("Expected ingress instance, got nil") | ||
} | ||
} | ||
|
||
func TestCheck(t *testing.T) { | ||
t.Parallel() | ||
logger := func() *logrus.Entry { | ||
return logrus.NewEntry(logrus.New()) | ||
} | ||
|
||
k8sclient, err := config.NewK8sClientset() | ||
if err != nil { | ||
t.Fatalf("NewK8sClientset: %s", err) | ||
} | ||
|
||
chatwork := ¬ify.Chatwork{ApiToken: "token", RoomId: "test", Logger: logger} | ||
|
||
now := time.Now() | ||
|
||
namespace := fmt.Sprintf("ingress-test-%d%02d%02d-%s", now.Year(), now.Month(), now.Day(), util.GenerateRandomString(5)) | ||
|
||
// kindとingress-nginxがある前提 | ||
// レコードは作れないのでNoDnsCheckをtrueにする | ||
ingress := &Ingress{ | ||
Checker: cmd.NewChecker(namespace, k8sclient, true, logger, chatwork), | ||
NoDnsCheck: true, | ||
IngressClassName: "nginx", | ||
ResourceName: "sample", | ||
ExternalHostname: "sample.example.com", | ||
} | ||
|
||
err = ingress.Check() | ||
if err != nil { | ||
t.Fatalf("Expected No Error, but got error: %s", err) | ||
} | ||
} | ||
|
||
func TestCheckDNSRecord(t *testing.T) { | ||
logger := func() *logrus.Entry { | ||
return logrus.NewEntry(logrus.New()) | ||
} | ||
|
||
k8sclient, err := config.NewK8sClientset() | ||
if err != nil { | ||
t.Fatalf("NewK8sClientset: %s", err) | ||
} | ||
|
||
chatwork := ¬ify.Chatwork{ApiToken: "token", RoomId: "test", Logger: logger} | ||
|
||
// kindとingress-nginxがある前提 | ||
// レコードは作れないのでNoDnsCheckをtrueにする | ||
ingress := &Ingress{ | ||
Checker: cmd.NewChecker("test", k8sclient, true, logger, chatwork), | ||
NoDnsCheck: true, | ||
IngressClassName: "nginx", | ||
ResourceName: "sample", | ||
ExternalHostname: "go.chatwork.com", | ||
} | ||
|
||
err = ingress.checkDNSRecord() | ||
if err != nil { | ||
t.Fatalf("Expected No Error, but got error: %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters