You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2021/11/09 15:33:46 UTC
[skywalking-infra-e2e] branch main updated: Expand KinD file path
with system environment (#67)
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-infra-e2e.git
The following commit(s) were added to refs/heads/main by this push:
new 05488cd Expand KinD file path with system environment (#67)
05488cd is described below
commit 05488cd86e0a34d284766679b4293021386f6ba4
Author: John Niang <jo...@fastmail.com>
AuthorDate: Tue Nov 9 23:33:39 2021 +0800
Expand KinD file path with system environment (#67)
Signed-off-by: John Niang <jo...@fastmail.com>
---
internal/config/e2eConfig.go | 6 ++-
internal/config/e2eConfig_test.go | 79 +++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 1 deletion(-)
diff --git a/internal/config/e2eConfig.go b/internal/config/e2eConfig.go
index b853309..8a1f77b 100644
--- a/internal/config/e2eConfig.go
+++ b/internal/config/e2eConfig.go
@@ -20,6 +20,7 @@ package config
import (
"fmt"
+ "os"
"time"
"github.com/apache/skywalking-infra-e2e/internal/constant"
@@ -90,7 +91,10 @@ type Verify struct {
}
func (s *Setup) GetFile() string {
- return util.ResolveAbs(s.File)
+ // expand the file path with system environment
+ file := os.ExpandEnv(s.File)
+ file = util.ResolveAbs(file)
+ return file
}
type Manifest struct {
diff --git a/internal/config/e2eConfig_test.go b/internal/config/e2eConfig_test.go
new file mode 100644
index 0000000..5811431
--- /dev/null
+++ b/internal/config/e2eConfig_test.go
@@ -0,0 +1,79 @@
+// Licensed to 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. Apache Software Foundation (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 config
+
+import (
+ "os"
+ "testing"
+
+ "github.com/apache/skywalking-infra-e2e/internal/util"
+ "k8s.io/apimachinery/pkg/util/rand"
+)
+
+func TestSetup_GetFile(t *testing.T) {
+ randomVersion := rand.String(10)
+ type fields struct {
+ File string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ beforeEach func()
+ want string
+ }{{
+ name: "Should keep file path still",
+ fields: fields{
+ File: "fake/file/path.yaml",
+ },
+ want: util.ResolveAbs("fake/file/path.yaml"),
+ }, {
+ name: "Should expand file path",
+ fields: fields{
+ File: "kind/$VERSION.yaml",
+ },
+ beforeEach: func() {
+ os.Clearenv()
+ os.Setenv("VERSION", randomVersion)
+ },
+ want: util.ResolveAbs("kind/" + randomVersion + ".yaml"),
+ }, {
+ name: "Should never expand file path",
+ fields: fields{
+ File: "kind/$VERSION.yaml",
+ },
+ beforeEach: func() {
+ os.Clearenv()
+ os.Setenv("INVAD_VERSION", randomVersion)
+ },
+ want: util.ResolveAbs("kind/.yaml"),
+ }}
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if tt.beforeEach != nil {
+ tt.beforeEach()
+ }
+ s := &Setup{
+ File: tt.fields.File,
+ }
+ if got := s.GetFile(); got != tt.want {
+ t.Errorf("Setup.GetFile() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}