github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/cli/e2e/context/context_test.go (about)

     1  package context
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"gotest.tools/v3/assert"
     8  	"gotest.tools/v3/golden"
     9  	"gotest.tools/v3/icmd"
    10  )
    11  
    12  func TestContextList(t *testing.T) {
    13  	cmd := icmd.Command("docker", "context", "ls")
    14  	cmd.Env = append(cmd.Env,
    15  		"DOCKER_CONFIG=./testdata/test-dockerconfig",
    16  		"KUBECONFIG=./testdata/test-kubeconfig",
    17  	)
    18  	result := icmd.RunCmd(cmd).Assert(t, icmd.Expected{
    19  		Err:      icmd.None,
    20  		ExitCode: 0,
    21  	})
    22  	golden.Assert(t, result.Stdout(), "context-ls.golden")
    23  }
    24  
    25  func TestContextImportNoTLS(t *testing.T) {
    26  	d := t.TempDir()
    27  	cmd := icmd.Command("docker", "context", "import", "remote", "./testdata/test-dockerconfig.tar")
    28  	cmd.Env = append(cmd.Env,
    29  		"DOCKER_CONFIG="+d,
    30  	)
    31  	icmd.RunCmd(cmd).Assert(t, icmd.Success)
    32  
    33  	cmd = icmd.Command("docker", "context", "ls")
    34  	cmd.Env = append(cmd.Env,
    35  		"DOCKER_CONFIG="+d,
    36  		"KUBECONFIG=./testdata/test-kubeconfig", // Allows reuse of context-ls.golden
    37  	)
    38  	result := icmd.RunCmd(cmd).Assert(t, icmd.Success)
    39  	golden.Assert(t, result.Stdout(), "context-ls.golden")
    40  }
    41  
    42  func TestContextImportTLS(t *testing.T) {
    43  	d := t.TempDir()
    44  	cmd := icmd.Command("docker", "context", "import", "test", "./testdata/test-dockerconfig-tls.tar")
    45  	cmd.Env = append(cmd.Env,
    46  		"DOCKER_CONFIG="+d,
    47  	)
    48  	icmd.RunCmd(cmd).Assert(t, icmd.Success)
    49  
    50  	cmd = icmd.Command("docker", "context", "ls")
    51  	cmd.Env = append(cmd.Env,
    52  		"DOCKER_CONFIG="+d,
    53  	)
    54  	result := icmd.RunCmd(cmd).Assert(t, icmd.Success)
    55  	golden.Assert(t, result.Stdout(), "context-ls-tls.golden")
    56  
    57  	b, err := os.ReadFile(d + "/contexts/tls/9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08/kubernetes/key.pem")
    58  	assert.NilError(t, err)
    59  	assert.Equal(t, string(b), `-----BEGIN RSA PRIVATE KEY-----
    60  MIIEpAIBAAKCAQEArQk77K5sgrQYY6HiQ1y7AC+67HrRB36oEvR+Fq60RsFcc3cZ
    61  xAvMkRSBPjQyskjdYY7kfykGHhfJxGKopb3cDJx3eDBxjgAniwnnOMmHVWbf8Eik
    62  o0sNxkgzQPGq83nL3QvVxm3xgqe4nlTdR/Swoq6Pv0oaVYvPPMnaZIF89SJ/wlNT
    63  myCs6Uq00dICi20II+M2Nw9b+EVEK4ENl+SlrsK7iuoBIh/H0ZghxOthO9J/HeBb
    64  hmM4wcs1OonhPDYKHEaChYA7/Q3/8OBp3bAdlQJ1ziyP3ROAKHL2NwwkGZ8o8HP8
    65  u0ex/NAb8w5J5WNePqYQd/sqfisfNpA5VIKcEQIDAQABAoIBABLo4W2aGi2mdMve
    66  kxV9esoobSsOuO0ywDdiFK1x5i2dT/cmWuB70Z1BOmaL2cZ2BAt3TC1BVHPRcbFO
    67  ftOuDfAq4Tt3P9Ge3rNpH6WrEGka1voxVhyqRRUYKtG8F0yIUOkVNAV9WllG7vwO
    68  ligY63y7yuXCuWID51/jR0SYiglXz6G4gcJKFXtugXXiLUIg08GVWkwOsrACC+hR
    69  mhcHly1926VhN5+ozjNU/GZ1LaTuK6erBZakH5bqlN97s5rrk0ZRwk/JtnkoRRdI
    70  cq0918Za2vqGDHZ3MqLttL52YfDXPIEJPwlFdvC/+sXK2NhUB/xY4yuliU3sY0sf
    71  XsIvIWECgYEAwD8AnZI0hnGv8hc6zJppHFRwhrtLZ+09SJwPv5Y4wxuuk5dzNkpf
    72  xCNo5hjSVYA1MMmWG8p/sEXo2IyCT8sWDNCn9kieTXihxRxbj88Y2qA5O4N46Zy4
    73  kPngjkP5PPDMkwaQQgUr9LvlWS7P6OJkH18ZN8s3QhMaKcHu9FFT44UCgYEA5mte
    74  mMSDf9hUK3IK+yrGX62qc2H+ecXN3Zf3nehyiz+dX4ZXhBwBkwJ/mHvuAZPfoFUN
    75  Xg6cdyWFJg9ynm45JXnDjmYPGmFLn0mP3Mje/+SbbW2fdFWHJW/maqj4uUqqgQd+
    76  pGNzKXq34MzDrpsqIJ7AHu3LYVMOoLAVqC7LXh0CgYEAnLF9ZfFqQH7fgvouIeBl
    77  dgLZKOf2AUJcJheVunnN0DF67K+P55tdTTfzY0CuB6SVNivI3uQBiYKh1AdKm5ET
    78  auSTUmlEJi8B4/BGLQQG5QOdQoXZgsgLo5cX0b1To7k9dUTvRfCDMFoKCNPgAJiu
    79  NOfFXTWU15VMSObaRmcXciUCgYEA5e1cXwsxwUAodZX+eTXs8ArHHQ47Nl55GFeN
    80  wufybRuUuX7AE9cyhvUmSA3aqX5a144noaTo40fwftNJZ+jLY6cGyjDzfzp5kMCC
    81  KynSxPzlUCPkytyR2Hy6K9LjJ1rnm4vUBswqXcjUdiE+Xxz8w8JGKlbV7Q9JeHVd
    82  lw7i5s0CgYAn9T9ySI3xCbrUa/XV/ZY2hopUdH5CDPeTd2eH+L+lctkD9nlzLrpj
    83  qij+jaEUweymNx0uttgv02J3DYcIIvVq3RNAwORy5Mp9KasHmjbW2xq+HAq5yFOO
    84  1ma82F5zeUl+bKqjMRCY8IVZ349VxRZtb2RVVEKyVswb7HmKp6gGbA==
    85  -----END RSA PRIVATE KEY-----
    86  `)
    87  }