github.com/tilt-dev/tilt@v0.36.0/internal/docker/env_test.go (about) 1 package docker 2 3 import ( 4 "bytes" 5 "fmt" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 10 "github.com/tilt-dev/clusterid" 11 "github.com/tilt-dev/tilt/internal/k8s" 12 "github.com/tilt-dev/tilt/internal/testutils" 13 ) 14 15 type EnvTest struct { 16 product clusterid.Product 17 kubecontext string 18 dockerHost string 19 warning string 20 match bool 21 } 22 23 type fakeDaemonClient struct { 24 host string 25 } 26 27 func (f *fakeDaemonClient) DaemonHost() string { 28 return f.host 29 } 30 31 func TestEnv(t *testing.T) { 32 33 table := []EnvTest{ 34 { 35 product: clusterid.ProductDockerDesktop, 36 kubecontext: "docker-desktop", 37 dockerHost: "npipe:////./pipe/dockerDesktopLinuxEngine", 38 match: true, 39 }, 40 { 41 product: clusterid.ProductDockerDesktop, 42 kubecontext: "docker-desktop", 43 dockerHost: "npipe:////./pipe/docker_engine", 44 match: true, 45 }, 46 { 47 product: clusterid.ProductDockerDesktop, 48 kubecontext: "docker-desktop", 49 dockerHost: "unix:///var/run/docker.sock", 50 match: true, 51 }, 52 { 53 product: clusterid.ProductDockerDesktop, 54 kubecontext: "docker-desktop", 55 dockerHost: "unix://~/.docker/desktop/docker.sock", 56 match: true, 57 }, 58 { 59 product: clusterid.ProductColima, 60 kubecontext: "colima", 61 dockerHost: "unix://~/.colima/docker.sock", 62 match: true, 63 }, 64 { 65 product: clusterid.ProductColima, 66 kubecontext: "colima", 67 dockerHost: "unix://~/.colima/default/docker.sock", 68 match: true, 69 }, 70 { 71 product: clusterid.ProductColima, 72 kubecontext: "colima-test", 73 dockerHost: "unix://~/.colima-test/docker.sock", 74 match: true, 75 }, 76 { 77 product: clusterid.ProductColima, 78 kubecontext: "colima-test", 79 dockerHost: "unix://~/.colima/test/docker.sock", 80 match: true, 81 }, 82 { 83 product: clusterid.ProductColima, 84 kubecontext: "colima-test", 85 dockerHost: "unix://~/.colima/docker.sock", 86 match: false, 87 warning: "connected to Kubernetes on Colima profile test, but building on Docker on Colima profile default", 88 }, 89 { 90 product: clusterid.ProductColima, 91 kubecontext: "colima", 92 dockerHost: "unix://~/.colima-test/docker.sock", 93 match: false, 94 warning: "connected to Kubernetes on Colima profile default, but building on Docker on Colima profile test", 95 }, 96 { 97 product: clusterid.ProductColima, 98 kubecontext: "colima-test", 99 dockerHost: "unix://~/.docker/desktop/docker.sock", 100 match: false, 101 warning: "connected to Kubernetes running on Colima, but building on a non-Colima Docker socket", 102 }, 103 { 104 product: clusterid.ProductOrbstack, 105 kubecontext: "orbstack", 106 dockerHost: "unix://~/.orbstack/run/docker.sock", 107 match: true, 108 }, 109 { 110 product: clusterid.ProductOrbstack, 111 kubecontext: "orbstack", 112 dockerHost: "unix://~/.docker/desktop/docker.sock", 113 match: false, 114 warning: "connected to Kubernetes running on Orbstack, but building on a non-Orbstack Docker socket", 115 }, 116 // colima on linux 117 { 118 product: clusterid.ProductColima, 119 kubecontext: "colima", 120 dockerHost: "unix://~/.config/colima/default/docker.sock", 121 match: true, 122 }, 123 { 124 product: clusterid.ProductColima, 125 kubecontext: "colima-test", 126 dockerHost: "unix://~/.config/colima/test/docker.sock", 127 match: true, 128 }, 129 } 130 131 for i, c := range table { 132 t.Run(fmt.Sprintf("env-%d", i), func(t *testing.T) { 133 out := &bytes.Buffer{} 134 ctx, _, _ := testutils.ForkedCtxAndAnalyticsForTest(out) 135 env := Env{ 136 Client: &fakeDaemonClient{ 137 host: c.dockerHost, 138 }, 139 } 140 141 result := willBuildToKubeContext(ctx, c.product, k8s.KubeContext(c.kubecontext), env) 142 assert.Equal(t, result, c.match) 143 if c.warning != "" { 144 assert.Contains(t, out.String(), c.warning) 145 } else { 146 assert.Equal(t, out.String(), c.warning) 147 } 148 }) 149 } 150 }