squakez commented on a change in pull request #2858:
URL: https://github.com/apache/camel-k/pull/2858#discussion_r780989400
##########
File path: pkg/controller/integrationplatform/initialize_test.go
##########
@@ -115,29 +115,3 @@ func TestTimeouts_Truncated(t *testing.T) {
assert.Equal(t, 5*time.Minute,
answer.Status.Build.GetTimeout().Duration)
}
-
-func TestDefaultMavenSettingsApplied(t *testing.T) {
Review comment:
Any reason why this test was removed? I could not find an equivalent one
for the new development.
##########
File path: pkg/util/maven/maven_settings.go
##########
@@ -34,30 +32,46 @@ import (
var DefaultMavenRepositories =
"https://repo.maven.apache.org/maven2@id=central"
func (s Settings) MarshalBytes() ([]byte, error) {
- w := &bytes.Buffer{}
- w.WriteString(xml.Header)
-
- e := xml.NewEncoder(w)
- e.Indent("", " ")
-
- if err := e.Encode(s); err != nil {
- return []byte{}, err
- }
+ return util.EncodeXML(s)
+}
- return w.Bytes(), nil
+type SettingsOption interface {
+ apply(settings *Settings) error
}
-func NewSettings() Settings {
- return Settings{
+func NewSettings(options ...SettingsOption) (Settings, error) {
+ settings := Settings{
XMLName: xml.Name{Local: "settings"},
XMLNs: "http://maven.apache.org/SETTINGS/1.0.0",
XMLNsXsi: "http://www.w3.org/2001/XMLSchema-instance",
XsiSchemaLocation: "http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd",
+ Profiles: []Profile{
+ {
+ ID: "camel-k",
+ Activation: Activation{
+ ActiveByDefault: true,
+ },
+ },
+ },
+ }
+
+ for _, option := range options {
+ err := option.apply(&settings)
+ if err != nil {
+ return Settings{}, err
+ }
}
+
+ return settings, nil
}
func NewDefaultSettings(repositories []v1.Repository, mirrors []Mirror)
Settings {
- settings := NewSettings()
+ settings := Settings{
+ XMLName: xml.Name{Local: "settings"},
+ XMLNs: "http://maven.apache.org/SETTINGS/1.0.0",
Review comment:
All these are used at least twice, we could make them constants
##########
File path: e2e/common/build/maven_http_proxy_test.go
##########
@@ -0,0 +1,337 @@
+//go:build integration
+// +build integration
+
+// To enable compilation of this file in Goland, go to "Settings -> Go ->
Vendoring & Build Tags -> Custom Tags" and add "integration"
+
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package build
+
+import (
+ "crypto/rand"
+ "crypto/rsa"
+ "crypto/x509"
+ "crypto/x509/pkix"
+ "encoding/pem"
+ "fmt"
+ "math/big"
+ rand2 "math/rand"
+ "strings"
+ "testing"
+ "time"
+
+ . "github.com/onsi/gomega"
+ . "github.com/onsi/gomega/gstruct"
+
+ appsv1 "k8s.io/api/apps/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/apimachinery/pkg/util/intstr"
+
+ . "github.com/apache/camel-k/e2e/support"
+ v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+)
+
+func TestMavenProxy(t *testing.T) {
+ WithNewTestNamespace(t, func(ns string) {
+ hostname := fmt.Sprintf("%s.%s.svc", "proxy", ns)
+ tlsMountPath := "/etc/tls/private"
+
+ // Generate the TLS certificate
+ serialNumber := big.NewInt(rand2.Int63())
+ cert := &x509.Certificate{
+ SerialNumber: serialNumber,
+ Subject: pkix.Name{
+ Organization: []string{"Camel K test"},
+ },
+ DNSNames: []string{hostname},
+ NotBefore: time.Now(),
+ NotAfter: time.Now().AddDate(1, 0, 0),
+ ExtKeyUsage:
[]x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
+ KeyUsage: x509.KeyUsageKeyEncipherment |
x509.KeyUsageDigitalSignature,
+ BasicConstraintsValid: true,
+ }
+
+ // generate the certificate private key
+ certPrivateKey, err := rsa.GenerateKey(rand.Reader, 2048)
+ Expect(err).To(BeNil())
+
+ privateKeyBytes := x509.MarshalPKCS1PrivateKey(certPrivateKey)
+ // encode for storing into a Secret
+ privateKeyPem := pem.EncodeToMemory(
+ &pem.Block{
+ Type: "RSA PRIVATE KEY",
+ Bytes: privateKeyBytes,
+ },
+ )
+ certBytes, err := x509.CreateCertificate(rand.Reader, cert,
cert, &certPrivateKey.PublicKey, certPrivateKey)
+ Expect(err).To(BeNil())
+
+ // encode for storing into a Secret
+ certPem := pem.EncodeToMemory(&pem.Block{
+ Type: "CERTIFICATE",
+ Bytes: certBytes,
+ })
+
+ secret := &corev1.Secret{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "Secret",
+ APIVersion: corev1.SchemeGroupVersion.String(),
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Namespace: ns,
+ Name: "tls-secret",
+ },
+ Type: corev1.SecretTypeTLS,
+ Data: map[string][]byte{
+ corev1.TLSCertKey: certPem,
+ corev1.TLSPrivateKeyKey: privateKeyPem,
+ },
+ }
+ Expect(TestClient().Create(TestContext, secret)).To(Succeed())
+
+ // HTTPD configuration
+ config := &corev1.ConfigMap{
Review comment:
Nit: for readability purposes, I'd move all these object (configmap,
secrets, ...) creation in a separate method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]