From 18f33b337d7af97ba30ab03eeeab801574208e55 Mon Sep 17 00:00:00 2001 From: Chris Crone Date: Tue, 5 Jan 2021 14:12:52 +0100 Subject: [PATCH] context: Add tarball e2e tests Signed-off-by: Chris Crone --- e2e/context/context_test.go | 73 ++++++++++++++++++ e2e/context/testdata/context-ls-notls.golden | 3 + e2e/context/testdata/context-ls-tls.golden | 3 + .../testdata/test-dockerconfig-tls.tar | Bin 0 -> 8335 bytes e2e/context/testdata/test-dockerconfig.tar | Bin 0 -> 1536 bytes 5 files changed, 79 insertions(+) create mode 100644 e2e/context/testdata/context-ls-notls.golden create mode 100644 e2e/context/testdata/context-ls-tls.golden create mode 100644 e2e/context/testdata/test-dockerconfig-tls.tar create mode 100644 e2e/context/testdata/test-dockerconfig.tar diff --git a/e2e/context/context_test.go b/e2e/context/context_test.go index ce22f7b7c3..6212b98dea 100644 --- a/e2e/context/context_test.go +++ b/e2e/context/context_test.go @@ -1,8 +1,11 @@ package context import ( + "io/ioutil" + "os" "testing" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" "gotest.tools/v3/icmd" ) @@ -19,3 +22,73 @@ func TestContextList(t *testing.T) { }) golden.Assert(t, result.Stdout(), "context-ls.golden") } + +func TestContextImportNoTLS(t *testing.T) { + d, _ := ioutil.TempDir("", "") + defer func() { + os.RemoveAll(d) + }() + cmd := icmd.Command("docker", "context", "import", "remote", "./testdata/test-dockerconfig.tar") + cmd.Env = append(cmd.Env, + "DOCKER_CONFIG="+d, + ) + icmd.RunCmd(cmd).Assert(t, icmd.Success) + + cmd = icmd.Command("docker", "context", "ls") + cmd.Env = append(cmd.Env, + "DOCKER_CONFIG="+d, + "KUBECONFIG=./testdata/test-kubeconfig", // Allows reuse of context-ls.golden + ) + result := icmd.RunCmd(cmd).Assert(t, icmd.Success) + golden.Assert(t, result.Stdout(), "context-ls.golden") +} + +func TestContextImportTLS(t *testing.T) { + d, _ := ioutil.TempDir("", "") + defer func() { + os.RemoveAll(d) + }() + cmd := icmd.Command("docker", "context", "import", "test", "./testdata/test-dockerconfig-tls.tar") + cmd.Env = append(cmd.Env, + "DOCKER_CONFIG="+d, + ) + icmd.RunCmd(cmd).Assert(t, icmd.Success) + + cmd = icmd.Command("docker", "context", "ls") + cmd.Env = append(cmd.Env, + "DOCKER_CONFIG="+d, + ) + result := icmd.RunCmd(cmd).Assert(t, icmd.Success) + golden.Assert(t, result.Stdout(), "context-ls-tls.golden") + + b, err := ioutil.ReadFile(d + "/contexts/tls/9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08/kubernetes/key.pem") + assert.NilError(t, err) + assert.Equal(t, string(b), `-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEArQk77K5sgrQYY6HiQ1y7AC+67HrRB36oEvR+Fq60RsFcc3cZ +xAvMkRSBPjQyskjdYY7kfykGHhfJxGKopb3cDJx3eDBxjgAniwnnOMmHVWbf8Eik +o0sNxkgzQPGq83nL3QvVxm3xgqe4nlTdR/Swoq6Pv0oaVYvPPMnaZIF89SJ/wlNT +myCs6Uq00dICi20II+M2Nw9b+EVEK4ENl+SlrsK7iuoBIh/H0ZghxOthO9J/HeBb +hmM4wcs1OonhPDYKHEaChYA7/Q3/8OBp3bAdlQJ1ziyP3ROAKHL2NwwkGZ8o8HP8 +u0ex/NAb8w5J5WNePqYQd/sqfisfNpA5VIKcEQIDAQABAoIBABLo4W2aGi2mdMve +kxV9esoobSsOuO0ywDdiFK1x5i2dT/cmWuB70Z1BOmaL2cZ2BAt3TC1BVHPRcbFO +ftOuDfAq4Tt3P9Ge3rNpH6WrEGka1voxVhyqRRUYKtG8F0yIUOkVNAV9WllG7vwO +ligY63y7yuXCuWID51/jR0SYiglXz6G4gcJKFXtugXXiLUIg08GVWkwOsrACC+hR +mhcHly1926VhN5+ozjNU/GZ1LaTuK6erBZakH5bqlN97s5rrk0ZRwk/JtnkoRRdI +cq0918Za2vqGDHZ3MqLttL52YfDXPIEJPwlFdvC/+sXK2NhUB/xY4yuliU3sY0sf +XsIvIWECgYEAwD8AnZI0hnGv8hc6zJppHFRwhrtLZ+09SJwPv5Y4wxuuk5dzNkpf +xCNo5hjSVYA1MMmWG8p/sEXo2IyCT8sWDNCn9kieTXihxRxbj88Y2qA5O4N46Zy4 +kPngjkP5PPDMkwaQQgUr9LvlWS7P6OJkH18ZN8s3QhMaKcHu9FFT44UCgYEA5mte +mMSDf9hUK3IK+yrGX62qc2H+ecXN3Zf3nehyiz+dX4ZXhBwBkwJ/mHvuAZPfoFUN +Xg6cdyWFJg9ynm45JXnDjmYPGmFLn0mP3Mje/+SbbW2fdFWHJW/maqj4uUqqgQd+ +pGNzKXq34MzDrpsqIJ7AHu3LYVMOoLAVqC7LXh0CgYEAnLF9ZfFqQH7fgvouIeBl +dgLZKOf2AUJcJheVunnN0DF67K+P55tdTTfzY0CuB6SVNivI3uQBiYKh1AdKm5ET +auSTUmlEJi8B4/BGLQQG5QOdQoXZgsgLo5cX0b1To7k9dUTvRfCDMFoKCNPgAJiu +NOfFXTWU15VMSObaRmcXciUCgYEA5e1cXwsxwUAodZX+eTXs8ArHHQ47Nl55GFeN +wufybRuUuX7AE9cyhvUmSA3aqX5a144noaTo40fwftNJZ+jLY6cGyjDzfzp5kMCC +KynSxPzlUCPkytyR2Hy6K9LjJ1rnm4vUBswqXcjUdiE+Xxz8w8JGKlbV7Q9JeHVd +lw7i5s0CgYAn9T9ySI3xCbrUa/XV/ZY2hopUdH5CDPeTd2eH+L+lctkD9nlzLrpj +qij+jaEUweymNx0uttgv02J3DYcIIvVq3RNAwORy5Mp9KasHmjbW2xq+HAq5yFOO +1ma82F5zeUl+bKqjMRCY8IVZ349VxRZtb2RVVEKyVswb7HmKp6gGbA== +-----END RSA PRIVATE KEY----- +`) +} diff --git a/e2e/context/testdata/context-ls-notls.golden b/e2e/context/testdata/context-ls-notls.golden new file mode 100644 index 0000000000..1747503305 --- /dev/null +++ b/e2e/context/testdata/context-ls-notls.golden @@ -0,0 +1,3 @@ +NAME DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR +default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock swarm +remote my remote cluster ssh://someserver https://someserver (default) kubernetes diff --git a/e2e/context/testdata/context-ls-tls.golden b/e2e/context/testdata/context-ls-tls.golden new file mode 100644 index 0000000000..f0f0d464e7 --- /dev/null +++ b/e2e/context/testdata/context-ls-tls.golden @@ -0,0 +1,3 @@ +NAME DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR +default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock swarm +test unix:///var/run/docker.sock https://kubernetes.docker.internal:6443 (default) swarm diff --git a/e2e/context/testdata/test-dockerconfig-tls.tar b/e2e/context/testdata/test-dockerconfig-tls.tar new file mode 100644 index 0000000000000000000000000000000000000000..6dc21a601421ecbbb22119a38f2b0d175e46a152 GIT binary patch literal 8335 zcmeHMS+lD~lJ+yd!f{^JV|ED~(GTqVju7aL9mFPfki-AIImf=^>pPzAp60y(;egBrESvc3z+n?UFBPEh>3g5o};mw)C zxH5*gNXKair*1eT$2A<9w;%uX#p^T*3hy z<`(=(;JfjVJB&D0`E*ssONTPs-@ebndQ11>-d9l_}w#Y zel7A(e|wMr`Ij31RO_Ff2n4~O-rq&PfnXFtj`;u6nEdy6{%>CY|MA{vPLT9(8P0Yk zUScSh`{)HUNn&=EVW^17sa2w>{P?hxPUlr$RHZ2P=SY43fT@k`&zyPT^X4pH!x1E@_?Lewko zzC7Q3yN+LnH;%NjRv;_gT`HDXr!0=9EsD)^&ZOSGwL0c_rzr*FfhG>_UFpS7JijH2 zPNtGzf?OP6xZ2NP8{iN1)KCrBrSi)yc3eC84>Iv{ak;D+;UK_s_N_o-#hrH5Ei}o~ z$<)rC&yFHTxL%uiMe0v6+o}p#wkL$J`}$rc0!^%FpPeHDz`7{)uaRKEgX;T_+>5U8V4YvzW?{di2e( zc*@Jn$(|t>STCNOXGv0bW90Px)qq=|M9u08jsfie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kMT6RHqi zy3H&0-nOrSG6@6^?b6k#Je~5$TU`s6Wi^1h%!4z!U-sE&=9|RgF!-<`Cn)pUf1L#^ zk7b4Tr#biiQoTw!L94|QNtJd5E;t7tN-yzb@xWss4b*3e&GIjm3 z*z7HO5JZ6V6mDQTcE0ZzP?>H1s7%~6S*=<_%gV0e7;mN&Xf%h-$l|J?l5*My!9OE?jEJW+_I320p>101J>z>zykz;( z%~DF&K$5F>#mErqD#vn>dUMDRJHG6+p~PpB+yx7YUs$x(t*8rV^#W zITr|L$GtW+Czk|`fwZ7nmVjGEVs-vKA9J3`y>&M8 zRbLsi+Na${#Qm(0>O+QyBPh$29@pNFAJ?ShPX6{HRzen(I`S?SDW{^B0QGt)@$r3? zspDdc+#Lzsm}t0$pzneA04ciXH4$-!HB&c1Qt_mo>UgSHvaMh0@O%J$`8Yj7?z*OX zqi@hWP5A;LGRg+ABrRT#+B&rw_HiNlB$aR!o5zt6TYnO%9^ZMx0N^Gh5FUS}*ZLGG q{X?^vfRMa9ijm%C-=_$%y<>aby>X2$Vxv6Ixe!sGlgZzNo4)|bYn{me literal 0 HcmV?d00001 diff --git a/e2e/context/testdata/test-dockerconfig.tar b/e2e/context/testdata/test-dockerconfig.tar new file mode 100644 index 0000000000000000000000000000000000000000..92eab23bda94661456a55c023f3c8dc4b227ff37 GIT binary patch literal 1536 zcmd^8O;5ux4DC;;a$dU@_JMk45(hpGLtGGtkh(OqO{&-(Ow;~54i#G22~FxQ_>efx z^Rr(RH$XCeM{9!dEMZ&BW`WLT#^*oPFw>jr(4q2Fr?XrJt|Z+KN~nkuSu%v!Ko6E zoFwZQS9P!83=p8$PsGaPt<{Fm6XsS`oX6gcMPe*snN6o?8$fWIp0d*I$a4s*t4DS7f_9(SM#H>9E`@%sQBaW`A?S1bP<{9 literal 0 HcmV?d00001