Skip to content

Commit

Permalink
feat: add support for mocking kube controller
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak160 <rocksarthak45@gmail.com>
  • Loading branch information
Sarthak160 authored and shivamsouravjha committed Jan 11, 2024
1 parent a6f4dda commit 1908dad
Show file tree
Hide file tree
Showing 16 changed files with 890 additions and 202 deletions.
25 changes: 24 additions & 1 deletion cmd/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ func (r *Record) GetCmd() *cobra.Command {
r.logger.Error("failed to read the disable telemetry flag")
return err
}
//add flag for mtls cert path
mtlsCertPath, err := cmd.Flags().GetString("mtls-cert-path")
if err != nil {
r.logger.Error("failed to read the mtls cert path")
return err
}
//add flag for mtls key path
mtlsKeyPath, err := cmd.Flags().GetString("mtls-key-path")
if err != nil {
r.logger.Error("failed to read the mtls key path")
return err
}
mtlsHostName, err := cmd.Flags().GetString("mtls-host-name")
if err != nil {
r.logger.Error("failed to read the mtls host name")
return err
}

err = r.GetRecordConfig(&path, &proxyPort, &appCmd, &appContainer, &networkName, &delay, &buildDelay, &ports, configPath)
if err != nil {
Expand Down Expand Up @@ -210,7 +227,7 @@ func (r *Record) GetCmd() *cobra.Command {
}

r.logger.Debug("the ports are", zap.Any("ports", ports))
r.recorder.CaptureTraffic(path, proxyPort, appCmd, appContainer, networkName, delay, buildDelay, ports, &filters, enableTele)
r.recorder.CaptureTraffic(path, proxyPort, appCmd, appContainer, networkName, delay, buildDelay, ports, &filters, enableTele, mtlsCertPath, mtlsKeyPath, mtlsHostName)
return nil
},
}
Expand All @@ -233,6 +250,12 @@ func (r *Record) GetCmd() *cobra.Command {

recordCmd.Flags().String("config-path", ".", "Path to the local directory where keploy configuration file is stored")

recordCmd.Flags().String("mtls-cert-path", "", "Path to the local directory where mtls cert file is stored")

recordCmd.Flags().String("mtls-key-path", "", "Path to the local directory where mtls key file is stored")

recordCmd.Flags().String("mtls-host-name", "", "Host name for mtls")

recordCmd.Flags().Bool("enableTele", true, "Switch for telemetry")
recordCmd.Flags().MarkHidden("enableTele")

Expand Down
20 changes: 19 additions & 1 deletion cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ func (t *Test) GetCmd() *cobra.Command {
return err
}

mockAssert, err := cmd.Flags().GetBool("mockAssert")
if err != nil {
t.logger.Error("failed to read the mock asserion flag")
return err
}

baseUrl, err := cmd.Flags().GetString("baseUrl")
if err != nil {
t.logger.Error("failed to read the base url flag for mock asserion")
return err
}

tests := map[string][]string{}

testsets, err := cmd.Flags().GetStringSlice("testsets")
Expand Down Expand Up @@ -275,6 +287,7 @@ func (t *Test) GetCmd() *cobra.Command {
AppContainer: appContainer,
AppNetwork: networkName,
MongoPassword: mongoPassword,
BaseUrl: baseUrl, // for mock assertion
Delay: delay,
BuildDelay: buildDelay,
PassThroughPorts: ports,
Expand All @@ -284,7 +297,7 @@ func (t *Test) GetCmd() *cobra.Command {
TestsetNoise: testsetNoise,
WithCoverage: withCoverage,
CoverageReportPath: coverageReportPath,
}, enableTele)
}, enableTele, mockAssert)

return nil
},
Expand All @@ -309,6 +322,11 @@ func (t *Test) GetCmd() *cobra.Command {

testCmd.Flags().UintSlice("passThroughPorts", []uint{}, "Ports of Outgoing dependency calls to be ignored as mocks")

testCmd.Flags().Bool("mockAssert", false, "Mock Assert")
testCmd.Flags().MarkHidden("mockAssert")

testCmd.Flags().String("baseUrl", "", "Base Url for mock assertion")

testCmd.Flags().String("config-path", ".", "Path to the local directory where keploy configuration file is stored")

testCmd.Flags().String("mongoPassword", "default123", "Authentication password for mocking MongoDB connection")
Expand Down
32 changes: 32 additions & 0 deletions config
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v1
clusters:
- cluster:
certificate-authority: /home/newsarthak.linux/.minikube/ca.crt
extensions:
- extension:
last-update: Thu, 28 Dec 2023 19:25:41 UTC
provider: minikube.sigs.k8s.io
version: v1.32.0
name: cluster_info
server: https://192.168.49.2:8443
name: minikube
contexts:
- context:
cluster: minikube
extensions:
- extension:
last-update: Thu, 28 Dec 2023 19:25:41 UTC
provider: minikube.sigs.k8s.io
version: v1.32.0
name: context_info
namespace: default
user: minikube
name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
user:
client-certificate: /home/newsarthak.linux/.minikube/profiles/minikube/client.crt
client-key: /home/newsarthak.linux/.minikube/profiles/minikube/client.key
1 change: 0 additions & 1 deletion pkg/hooks/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ func (h *Hook) IsUsrAppTerminateInitiated() bool {
return h.userAppShutdownInitiated
}


func (h *Hook) GetConfigMocks() ([]*models.Mock, error) {
it, err := h.localDb.getAll(configMockTable, configMockTableIndex)
if err != nil {
Expand Down
Loading

0 comments on commit 1908dad

Please sign in to comment.