-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: clean manifest path in remote deploy to fix regression (#4195)
--------- Signed-off-by: Andrea Falzetti <andrea@okteto.com>
- Loading branch information
1 parent
409c92f
commit 5ed8ee7
Showing
5 changed files
with
93 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -726,5 +726,4 @@ func TestGetOriginalCWD(t *testing.T) { | |
require.NoError(t, err) | ||
require.Equal(t, expected, result) | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2024 The Okteto Authors | ||
// Licensed 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 filesystem | ||
|
||
import ( | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// CleanManifestPath removes the path to the manifest file, in case the command was executed from a parent or child folder | ||
func CleanManifestPath(manifestPath string) string { | ||
lastFolder := filepath.Base(filepath.Dir(manifestPath)) | ||
if lastFolder == ".okteto" { | ||
path := filepath.Clean(manifestPath) | ||
parts := strings.Split(path, string(filepath.Separator)) | ||
|
||
return filepath.Join(parts[len(parts)-2:]...) | ||
} else { | ||
return filepath.Base(manifestPath) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2024 The Okteto Authors | ||
// Licensed 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 filesystem | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_cleanManifestPath(t *testing.T) { | ||
var tests = []struct { | ||
name string | ||
manifest string | ||
expected string | ||
}{ | ||
{ | ||
name: "empty manifest", | ||
manifest: "", | ||
expected: ".", | ||
}, | ||
{ | ||
name: "absolute path to manifest file", | ||
manifest: "/path/to/service/okteto.yml", | ||
expected: "okteto.yml", | ||
}, | ||
{ | ||
name: "relative path to manifest file", | ||
manifest: "./service/okteto.yml", | ||
expected: "okteto.yml", | ||
}, | ||
{ | ||
name: "manifest within .okteto", | ||
manifest: "/path/to/service/.okteto/okteto.yml", | ||
expected: filepath.Clean(".okteto/okteto.yml"), | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := CleanManifestPath(tt.manifest) | ||
assert.Equal(t, tt.expected, result) | ||
}) | ||
} | ||
} |