|
| 1 | +/* |
| 2 | + * Copyright 2026 Han Li and contributors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package sdk |
| 18 | + |
| 19 | +import ( |
| 20 | + "os" |
| 21 | + "path/filepath" |
| 22 | + "testing" |
| 23 | + |
| 24 | + "github.com/version-fox/vfox/internal/config" |
| 25 | + "github.com/version-fox/vfox/internal/env" |
| 26 | + "github.com/version-fox/vfox/internal/plugin" |
| 27 | +) |
| 28 | + |
| 29 | +func TestSdkParseLegacyFile_UsesDeclaredLegacyFilenames(t *testing.T) { |
| 30 | + envContext := &env.RuntimeEnvContext{ |
| 31 | + UserConfig: config.DefaultConfig, |
| 32 | + RuntimeVersion: "test", |
| 33 | + } |
| 34 | + |
| 35 | + plug, err := plugin.CreatePlugin(filepath.Join("..", "plugin", "testdata", "plugins", "java_with_metadata"), envContext) |
| 36 | + if err != nil { |
| 37 | + t.Fatalf("create plugin: %v", err) |
| 38 | + } |
| 39 | + defer plug.Close() |
| 40 | + |
| 41 | + projectDir := t.TempDir() |
| 42 | + if err := os.WriteFile(filepath.Join(projectDir, ".node-version"), []byte("14.17.0\n"), 0644); err != nil { |
| 43 | + t.Fatalf("write legacy file: %v", err) |
| 44 | + } |
| 45 | + |
| 46 | + sdk := &impl{ |
| 47 | + Name: "java_with_metadata", |
| 48 | + envContext: envContext, |
| 49 | + plugin: plug, |
| 50 | + } |
| 51 | + |
| 52 | + version, err := sdk.ParseLegacyFile(projectDir) |
| 53 | + if err != nil { |
| 54 | + t.Fatalf("parse legacy file: %v", err) |
| 55 | + } |
| 56 | + if version != "14.17.0" { |
| 57 | + t.Fatalf("expected legacy file version 14.17.0, got %q", version) |
| 58 | + } |
| 59 | +} |
0 commit comments