@@ -18,8 +18,8 @@ package e2e
1818
1919import (
2020 "fmt"
21- "net/http"
2221 "os"
22+ "path/filepath"
2323 "strings"
2424 "testing"
2525 "time"
@@ -48,31 +48,50 @@ func TestComposeUp(t *testing.T) {
4848 c := NewParallelE2eCLI (t , binDir )
4949
5050 const projectName = "compose-kube-demo"
51+ kubeconfig := filepath .Join (c .ConfigDir , "kubeconfig" )
52+ kindClusterName := "e2e"
53+ kubeContextName := "kind-" + kindClusterName
54+ dockerContextName := "kube-e2e-ctx"
55+
56+ t .Run ("create kube cluster" , func (t * testing.T ) {
57+ c .RunCmd ("kind" , "create" , "cluster" , "--name" , kindClusterName , "--kubeconfig" , kubeconfig , "--wait" , "180s" )
58+ })
59+ defer func () {
60+ c .RunDockerCmd ("context" , "use" , "default" )
61+ c .RunCmd ("kind" , "delete" , "cluster" , "--name" , kindClusterName , "--kubeconfig" , kubeconfig )
62+ }()
5163
5264 t .Run ("create kube context" , func (t * testing.T ) {
53- res := c .RunDockerCmd ("context" , "create" , "kubernetes" , "--kubeconfig" , "/Users/gtardif/.kube/config" , "--kubecontext" , "docker-desktop" , "kube-e2e" )
54- res .Assert (t , icmd.Expected {Out : ` Successfully created kube context "kube-e2e"` })
55- c .RunDockerCmd ("context" , "use" , "kube-e2e" )
65+ res := c .RunDockerCmd ("context" , "create" , "kubernetes" , "--kubeconfig" , kubeconfig , "--kubecontext" , kubeContextName , dockerContextName )
66+ res .Assert (t , icmd.Expected {Out : fmt . Sprintf ( " Successfully created kube context %q" , dockerContextName ) })
67+ c .RunDockerCmd ("context" , "use" , dockerContextName )
5668 })
5769
5870 t .Run ("up" , func (t * testing.T ) {
5971 c .RunDockerCmd ("compose" , "-f" , "./kube-simple-demo/demo_sentences.yaml" , "--project-name" , projectName , "up" , "-d" )
6072 })
6173
74+ t .Run ("compose ls" , func (t * testing.T ) {
75+ res := c .RunDockerCmd ("compose" , "ls" , "--format" , "json" )
76+ res .Assert (t , icmd.Expected {Out : `[{"Name":"compose-kube-demo","Status":"deployed"}]` })
77+ })
78+
6279 t .Run ("check running project" , func (t * testing.T ) {
63- res := c .RunDockerCmd ("compose" , "-p" , projectName , "ps" )
64- res .Assert (t , icmd.Expected {Out : `web` })
80+ // Docker Desktop kube cluster automatically exposes ports on the host, this is not the case with kind on Desktop,
81+ //we need to connect to the clusterIP, from the kind container
82+ res := c .RunCmd ("sh" , "-c" , "kubectl --kubeconfig " + kubeconfig + " get service/web -o json | jq -r '.spec.clusterIP'" )
83+ clusterIP := strings .ReplaceAll (strings .TrimSpace (res .Stdout ()), `"` , "" )
6584
66- endpoint := "http://localhost:95"
67- output := HTTPGetWithRetry (t , endpoint + "/words/noun" , http .StatusOK , 2 * time .Second , 20 * time .Second )
68- assert .Assert (t , strings .Contains (output , `"word":` ))
85+ endpoint := fmt .Sprintf ("http://%s:80/words/noun" , clusterIP )
86+ c .WaitForCmdResult (icmd .Command ("docker" , "--context" , "default" , "exec" , "e2e-control-plane" , "curl" , endpoint ), StdoutContains (`"word":` ), 3 * time .Minute , 3 * time .Second )
6987 })
88+
7089 t .Run ("down" , func (t * testing.T ) {
7190 _ = c .RunDockerCmd ("compose" , "--project-name" , projectName , "down" )
7291 })
7392
74- t .Run ("check containers after down" , func (t * testing.T ) {
75- res := c .RunDockerCmd ("ps " , "--all " )
93+ t .Run ("check stack after down" , func (t * testing.T ) {
94+ res := c .RunDockerCmd ("compose " , "ls " )
7695 assert .Assert (t , ! strings .Contains (res .Combined (), projectName ), res .Combined ())
7796 })
7897}
0 commit comments