MCPcopy
hub / github.com/helm/helm / setup

Function setup

pkg/registry/registry_test.go:72–169  ·  view source on GitHub ↗
(suite *TestRegistry, tlsEnabled, insecure bool)

Source from the content-addressed store, hash-verified

70}
71
72func setup(suite *TestRegistry, tlsEnabled, insecure bool) {
73 suite.WorkspaceDir = testWorkspaceDir
74 err := os.RemoveAll(suite.WorkspaceDir)
75 require.NoError(suite.T(), err, "no error removing test workspace dir")
76 err = os.Mkdir(suite.WorkspaceDir, 0700)
77 require.NoError(suite.T(), err, "no error creating test workspace dir")
78
79 var out bytes.Buffer
80
81 suite.Out = &out
82 credentialsFile := filepath.Join(suite.WorkspaceDir, CredentialsFileBasename)
83
84 // init test client
85 opts := []ClientOption{
86 ClientOptDebug(true),
87 ClientOptEnableCache(true),
88 ClientOptWriter(suite.Out),
89 ClientOptCredentialsFile(credentialsFile),
90 ClientOptBasicAuth(testUsername, testPassword),
91 }
92
93 if tlsEnabled {
94 var tlsConf *tls.Config
95 if insecure {
96 tlsConf, err = tlsutil.NewTLSConfig(
97 tlsutil.WithInsecureSkipVerify(true),
98 )
99 } else {
100 tlsConf, err = tlsutil.NewTLSConfig(
101 tlsutil.WithCertKeyPairFiles(tlsCert, tlsKey),
102 tlsutil.WithCAFile(tlsCA),
103 )
104 }
105 httpClient := &http.Client{
106 Transport: &http.Transport{
107 TLSClientConfig: tlsConf,
108 },
109 }
110 suite.Nil(err, "no error loading tls config")
111 opts = append(opts, ClientOptHTTPClient(httpClient))
112 } else {
113 opts = append(opts, ClientOptPlainHTTP())
114 }
115
116 suite.RegistryClient, err = NewClient(opts...)
117 suite.Nil(err, "no error creating registry client")
118
119 // create htpasswd file (w BCrypt, which is required)
120 pwBytes, err := bcrypt.GenerateFromPassword([]byte(testPassword), bcrypt.DefaultCost)
121 suite.Nil(err, "no error generating bcrypt password for test htpasswd file")
122 htpasswdPath := filepath.Join(suite.WorkspaceDir, testHtpasswdFileBasename)
123 err = os.WriteFile(htpasswdPath, fmt.Appendf(nil, "%s:%s\n", testUsername, string(pwBytes)), 0644)
124 suite.Nil(err, "no error creating test htpasswd file")
125
126 // Registry config
127 config := &configuration.Configuration{}
128 ln, err := net.Listen("tcp", "127.0.0.1:0")
129 suite.Nil(err, "no error finding free port for test registry")

Callers 12

SetupSuiteMethod · 0.85
SetupSuiteMethod · 0.85
SetupSuiteMethod · 0.85
TestStorageListFunction · 0.85
TestStorageDeployedFunction · 0.85
TestStorageHistoryFunction · 0.85
TestStorageLastFunction · 0.85

Calls 15

NewTLSConfigFunction · 0.92
WithInsecureSkipVerifyFunction · 0.92
WithCertKeyPairFilesFunction · 0.92
WithCAFileFunction · 0.92
ClientOptDebugFunction · 0.85
ClientOptEnableCacheFunction · 0.85
ClientOptWriterFunction · 0.85
ClientOptCredentialsFileFunction · 0.85
ClientOptBasicAuthFunction · 0.85
ClientOptHTTPClientFunction · 0.85
ClientOptPlainHTTPFunction · 0.85
NewClientFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…