-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactor integration tests to work
- Loading branch information
1 parent
43655e1
commit f06c50e
Showing
6 changed files
with
95 additions
and
65 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
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 |
---|---|---|
@@ -1,53 +1,76 @@ | ||
//go:build integration | ||
|
||
package k8s_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/ilyakaznacheev/cleanenv" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/dyrector-io/dyrectorio/golang/pkg/crane/config" | ||
"github.com/dyrector-io/dyrectorio/golang/pkg/crane/k8s" | ||
) | ||
|
||
func TestGetPods(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
cfg := config.Configuration{} | ||
_ = cleanenv.ReadEnv(&cfg) | ||
|
||
deploymentHandler := k8s.NewDeployment(ctx, &cfg) | ||
|
||
deployments, err := deploymentHandler.GetDeployments(ctx, "default", &cfg) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 2, len(deployments.Items)) | ||
|
||
pods, err := deploymentHandler.GetPods("default", "deployment-1") | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1, len(pods)) | ||
} | ||
|
||
func TestGetPod(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
cfg := config.Configuration{} | ||
_ = cleanenv.ReadEnv(&cfg) | ||
|
||
deploymentHandler := k8s.NewDeployment(ctx, &cfg) | ||
|
||
deployments, err := deploymentHandler.GetDeployments(ctx, "default", &cfg) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 2, len(deployments.Items)) | ||
|
||
pods, err := deploymentHandler.GetPods("default", "deployment-1") | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1, len(pods)) | ||
|
||
pod, err := deploymentHandler.GetPod("default", pods[0].Name) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, pod) | ||
} | ||
//go:build integration | ||
|
||
package k8s | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/AlekSi/pointer" | ||
"github.com/ilyakaznacheev/cleanenv" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
v1 "github.com/dyrector-io/dyrectorio/golang/api/v1" | ||
"github.com/dyrector-io/dyrectorio/golang/internal/dogger" | ||
"github.com/dyrector-io/dyrectorio/golang/internal/grpc" | ||
"github.com/dyrector-io/dyrectorio/golang/pkg/crane/config" | ||
) | ||
|
||
func TestFetchPods(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
cfg := config.Configuration{} | ||
err := cleanenv.ReadEnv(&cfg) | ||
|
||
ctx = grpc.WithGRPCConfig(ctx, &cfg) | ||
assert.Nil(t, err, "error for test deployment is unexpected") | ||
deploymentHandler := NewDeployment(ctx, &cfg) | ||
|
||
err = Deploy(ctx, | ||
dogger.NewDeploymentLogger( | ||
ctx, | ||
pointer.ToString("test"), nil, | ||
&cfg.CommonConfiguration), | ||
&v1.DeployImageRequest{ | ||
RequestID: "test", | ||
ImageName: "nginx:latest", | ||
InstanceConfig: v1.InstanceConfig{ | ||
ContainerPreName: "pods", | ||
}, ContainerConfig: v1.ContainerConfig{ | ||
Container: "deployment-1", | ||
}, | ||
}, | ||
&v1.VersionData{}) | ||
|
||
WaitForRunningDeployment(ctx, "pods", "deployment-1", 1, 30*time.Second, &cfg) | ||
|
||
assert.Nil(t, err, "error for test deployment is unexpected") | ||
t.Run("Test get pods", func(t *testing.T) { | ||
deployments, err := deploymentHandler.GetDeployments(ctx, "pods", &cfg) | ||
assert.NoError(t, err) | ||
assert.Len(t, deployments.Items, 1) | ||
|
||
pods, err := deploymentHandler.GetPods("pods", "deployment-1") | ||
assert.NoError(t, err) | ||
assert.Len(t, pods, 1) | ||
}) | ||
|
||
t.Run("Test get single pod", func(t *testing.T) { | ||
deployments, err := deploymentHandler.GetDeployments(ctx, "pods", &cfg) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1, len(deployments.Items)) | ||
|
||
pods, err := deploymentHandler.GetPods("pods", "deployment-1") | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1, len(pods)) | ||
|
||
pod, err := deploymentHandler.GetPod("pods", pods[0].Name) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, pod) | ||
}) | ||
|
||
err = deploymentHandler.deleteDeployment("pods", "deployment-1") | ||
assert.Nil(t, err, "error for deleting test deployment is unexpected") | ||
} |